Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bootstrap: make Buffer and process non-enumerable
This makes sure these two properties are non-enumerable. This aligns
them with all other globals that are not enumerable by spec.

Refs: #20565
  • Loading branch information
BridgeAR committed Dec 6, 2018
commit e76fc8cec58d2fe5e41b85c373f857e8e5b78438
14 changes: 12 additions & 2 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ function setupGlobalVariables() {
enumerable: false,
configurable: true
});
global.process = process;
Object.defineProperty(global, 'process', {
value: process,
enumerable: false,
writable: true,
configurable: true
});
const util = NativeModule.require('util');

function makeGetter(name) {
Expand Down Expand Up @@ -469,7 +474,12 @@ function setupGlobalVariables() {
// and exposes it on `internal/buffer`.
NativeModule.require('internal/buffer');

global.Buffer = NativeModule.require('buffer').Buffer;
Object.defineProperty(global, 'Buffer', {
value: NativeModule.require('buffer').Buffer,
enumerable: false,
writable: true,
configurable: true
});
process.domain = null;
process._exiting = false;
}
Expand Down
2 changes: 0 additions & 2 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ function platformTimeout(ms) {
}

let knownGlobals = [
Buffer,
clearImmediate,
clearInterval,
clearTimeout,
global,
process,
setImmediate,
setInterval,
setTimeout
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ const common = require('../common');
const fixtures = require('../common/fixtures');

const assert = require('assert');
const { builtinModules } = require('module');

// Load all modules to actually cover most code parts.
builtinModules.forEach((moduleName) => {
if (!moduleName.includes('/')) {
try {
// This could throw for e.g., crypto if the binary is not compiled
// accordingly.
require(moduleName);
} catch {}
}
});

assert.deepStrictEqual(
Object.keys(global),
[
'global',
'clearImmediate',
'clearInterval',
'clearTimeout',
'setImmediate',
'setInterval',
'setTimeout'
]
);

common.allowGlobals('bar', 'foo');

Expand Down