GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: do not throw if global property is no longer configurable · nodejs/node@2c595da

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/modules/cjs
    • helpers.js
  • test/parallel
    • test-cli-eval.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.