2018-09-22 12:28:50 +00:00
|
|
|
'use strict'
|
|
|
|
|
2018-09-20 03:43:26 +00:00
|
|
|
const moduleList = require('@electron/internal/common/api/module-list')
|
2017-03-06 14:58:10 +00:00
|
|
|
|
2018-09-20 03:43:26 +00:00
|
|
|
exports.memoizedGetter = (getter) => {
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attaches properties to |targetExports|.
|
|
|
|
exports.defineProperties = function (targetExports) {
|
2017-03-06 14:58:10 +00:00
|
|
|
const descriptors = {}
|
|
|
|
for (const module of moduleList) {
|
|
|
|
descriptors[module.name] = {
|
|
|
|
enumerable: !module.private,
|
2018-09-20 03:43:26 +00:00
|
|
|
get: exports.memoizedGetter(() => require(`@electron/internal/common/api/${module.file}`))
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2017-03-06 14:58:10 +00:00
|
|
|
}
|
2018-09-20 03:43:26 +00:00
|
|
|
return Object.defineProperties(targetExports, descriptors)
|
2016-03-25 19:50:33 +00:00
|
|
|
}
|