mirror of
https://github.com/nodejs/node.git
synced 2024-11-28 22:46:31 +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:
parent
066e77ae8d
commit
a65a9d18e4
@ -176,16 +176,19 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
|
||||
get: () => {
|
||||
const lib = dummyModule.require(name);
|
||||
|
||||
// Disable the current getter/setter and set up a new
|
||||
try {
|
||||
// Override 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
|
||||
enumerable: false,
|
||||
});
|
||||
} catch {
|
||||
// If the property is no longer configurable, ignore the error.
|
||||
}
|
||||
|
||||
return lib;
|
||||
},
|
||||
|
@ -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/);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user