Skip to content

Commit

Permalink
module: fix crash when built-in module export a default key
Browse files Browse the repository at this point in the history
PR-URL: #51481
Fixes: #51480
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
  • Loading branch information
aduh95 authored and richardlau committed Mar 25, 2024
1 parent 76968ab commit c621491
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/bootstrap/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ class BuiltinModule {
const url = `node:${this.id}`;
const builtin = this;
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);
ArrayPrototypePush(exportsKeys, 'default');
if (!ArrayPrototypeIncludes(exportsKeys, 'default')) {
ArrayPrototypePush(exportsKeys, 'default');
}
this.module = new ModuleWrap(
url, undefined, exportsKeys,
function() {
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-process-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
const common = require('../common');
const assert = require('node:assert');

process.default = 1;
import('node:process').then(common.mustCall((processModule) => {
assert.strictEqual(processModule.default.default, 1);
}));

0 comments on commit c621491

Please sign in to comment.