Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c595da

Browse filesBrowse files
aduh95danielleadams
authored andcommitted
lib: do not throw if global property is no longer configurable
Fixes: #45336 PR-URL: #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>
1 parent 8b44c61 commit 2c595da
Copy full SHA for 2c595da

File tree

Expand file treeCollapse file tree

2 files changed

+22
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-10
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/helpers.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/helpers.js
+13-10Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,19 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
176176
get: () => {
177177
const lib = dummyModule.require(name);
178178

179-
// Disable the current getter/setter and set up a new
180-
// non-enumerable property.
181-
delete object[name];
182-
ObjectDefineProperty(object, name, {
183-
__proto__: null,
184-
get: () => lib,
185-
set: setReal,
186-
configurable: true,
187-
enumerable: false
188-
});
179+
try {
180+
// Override the current getter/setter and set up a new
181+
// non-enumerable property.
182+
ObjectDefineProperty(object, name, {
183+
__proto__: null,
184+
get: () => lib,
185+
set: setReal,
186+
configurable: true,
187+
enumerable: false,
188+
});
189+
} catch {
190+
// If the property is no longer configurable, ignore the error.
191+
}
189192

190193
return lib;
191194
},
Collapse file

‎test/parallel/test-cli-eval.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,12 @@ child.exec(
288288
common.mustSucceed((stdout) => {
289289
assert.strictEqual(stdout, '.mjs file\n');
290290
}));
291+
292+
// Regression test for https://github.com/nodejs/node/issues/45336
293+
child.execFile(process.execPath,
294+
['-p',
295+
'Object.defineProperty(global, "fs", { configurable: false });' +
296+
'fs === require("node:fs")'],
297+
common.mustSucceed((stdout) => {
298+
assert.match(stdout, /^true/);
299+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.