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:
parent
066e77ae8d
commit
a65a9d18e4
@ -176,16 +176,19 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
|
|||||||
get: () => {
|
get: () => {
|
||||||
const lib = dummyModule.require(name);
|
const lib = dummyModule.require(name);
|
||||||
|
|
||||||
// Disable the current getter/setter and set up a new
|
try {
|
||||||
// non-enumerable property.
|
// Override the current getter/setter and set up a new
|
||||||
delete object[name];
|
// non-enumerable property.
|
||||||
ObjectDefineProperty(object, name, {
|
ObjectDefineProperty(object, name, {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
get: () => lib,
|
get: () => lib,
|
||||||
set: setReal,
|
set: setReal,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: false
|
enumerable: false,
|
||||||
});
|
});
|
||||||
|
} catch {
|
||||||
|
// If the property is no longer configurable, ignore the error.
|
||||||
|
}
|
||||||
|
|
||||||
return lib;
|
return lib;
|
||||||
},
|
},
|
||||||
|
@ -354,3 +354,12 @@ child.exec(
|
|||||||
common.mustSucceed((stdout) => {
|
common.mustSucceed((stdout) => {
|
||||||
assert.match(stdout, /^number/);
|
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/);
|
||||||
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user