0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00

lib: do not throw if global property is no longer configurable

Fixes: https://github.com/nodejs/node/issues/45336
PR-URL: https://github.com/nodejs/node/pull/45344
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel 2022-11-17 13:17:48 -05:00 committed by GitHub
parent 066e77ae8d
commit a65a9d18e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -176,16 +176,19 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
get: () => {
const lib = dummyModule.require(name);
// Disable the current getter/setter and set up a new
// non-enumerable property.
delete object[name];
ObjectDefineProperty(object, name, {
__proto__: null,
get: () => lib,
set: setReal,
configurable: true,
enumerable: false
});
try {
// Override the current getter/setter and set up a new
// non-enumerable property.
ObjectDefineProperty(object, name, {
__proto__: null,
get: () => lib,
set: setReal,
configurable: true,
enumerable: false,
});
} catch {
// If the property is no longer configurable, ignore the error.
}
return lib;
},

View File

@ -354,3 +354,12 @@ child.exec(
common.mustSucceed((stdout) => {
assert.match(stdout, /^number/);
}));
// Regression test for https://github.com/nodejs/node/issues/45336
child.execFile(process.execPath,
['-p',
'Object.defineProperty(global, "fs", { configurable: false });' +
'fs === require("node:fs")'],
common.mustSucceed((stdout) => {
assert.match(stdout, /^true/);
}));