asarfuckery/electronasar/canary/common/api/exports/electron.js

32 lines
889 B
JavaScript
Raw Normal View History

2019-06-20 21:19:08 +00:00
'use strict'
const moduleList = require('@electron/internal/common/api/module-list')
2019-06-16 20:19:06 +00:00
exports.memoizedGetter = (getter) => {
2019-06-20 21:19:08 +00:00
/*
* It's ok to leak this value as it would be leaked by the global
* node module cache anyway at `Module._cache`. This memoization
* is dramatically faster than relying on nodes module cache however
*/
let memoizedValue = null
return () => {
if (memoizedValue === null) {
memoizedValue = getter()
}
return memoizedValue
}
}
2019-06-16 20:19:06 +00:00
// Attaches properties to |targetExports|.
exports.defineProperties = function (targetExports) {
2019-06-20 21:19:08 +00:00
const descriptors = {}
for (const module of moduleList) {
descriptors[module.name] = {
enumerable: !module.private,
get: exports.memoizedGetter(() => require(`@electron/internal/common/api/${module.file}`))
2019-06-16 20:19:06 +00:00
}
2019-06-20 21:19:08 +00:00
}
return Object.defineProperties(targetExports, descriptors)
}