Pass all globals through "require"
(cherry picked from commit 7d015419cb7a0ecfe6728431a4ed2056cd411d62)
This commit is contained in:
Родитель
3749292669
Коммит
bbab795813
|
@ -70,6 +70,10 @@
|
|||
writable: false
|
||||
});
|
||||
|
||||
// Store the global context into a local variable, so we can refrence them in
|
||||
// this scope even after we deleted them from global context.
|
||||
const localGlobal = global;
|
||||
|
||||
// Set up process.binding() and process._linkedBinding()
|
||||
{
|
||||
const bindingObj = ObjectCreate(null);
|
||||
|
@ -223,9 +227,10 @@
|
|||
};
|
||||
|
||||
NativeModule.wrapper = [
|
||||
'(function (exports, require, module, process) {',
|
||||
'\n});'
|
||||
];
|
||||
'(function (exports, require, module, process, global, Buffer) { ' +
|
||||
'return function (exports, require, module, process) { ',
|
||||
'\n}.call(this, exports, require, module, process); });'
|
||||
]
|
||||
|
||||
const getOwn = (target, property, receiver) => {
|
||||
return ReflectApply(ObjectHasOwnProperty, target, [property]) ?
|
||||
|
@ -294,7 +299,7 @@
|
|||
const requireFn = this.id.startsWith('internal/deps/') ?
|
||||
NativeModule.requireForDeps :
|
||||
NativeModule.require;
|
||||
fn(this.exports, requireFn, this, process);
|
||||
fn(this.exports, requireFn, this, process, localGlobal, localGlobal.Buffer);
|
||||
|
||||
if (config.experimentalModules && !NativeModule.isInternal(this.id)) {
|
||||
this.exportKeys = ObjectKeys(this.exports);
|
||||
|
|
|
@ -126,8 +126,9 @@ Module.wrap = function(script) {
|
|||
};
|
||||
|
||||
Module.wrapper = [
|
||||
'(function (exports, require, module, __filename, __dirname) { ',
|
||||
'\n});'
|
||||
'(function (exports, require, module, __filename, __dirname, process, global, Buffer) { ' +
|
||||
'return function (exports, require, module, __filename, __dirname) { ',
|
||||
'\n}.call(this, exports, require, module, __filename, __dirname); });'
|
||||
];
|
||||
|
||||
const debug = util.debuglog('module');
|
||||
|
@ -684,10 +685,11 @@ Module.prototype._compile = function(content, filename) {
|
|||
var result;
|
||||
if (inspectorWrapper) {
|
||||
result = inspectorWrapper(compiledWrapper, this.exports, this.exports,
|
||||
require, this, filename, dirname);
|
||||
require, this, filename, dirname, process,
|
||||
global, Buffer);
|
||||
} else {
|
||||
result = compiledWrapper.call(this.exports, this.exports, require, this,
|
||||
filename, dirname);
|
||||
filename, dirname, process, global, Buffer);
|
||||
}
|
||||
if (depth === 0) stat.cache = null;
|
||||
return result;
|
||||
|
|
Загрузка…
Ссылка в новой задаче