Skip to content

Commit b09a7dd

Browse files
aduh95Medhansh404
authored andcommitted
module: fix crash when built-in module export a default key
PR-URL: nodejs#51481 Fixes: nodejs#51480 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
1 parent 11a8afc commit b09a7dd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/internal/bootstrap/realm.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ class BuiltinModule {
350350
const url = `node:${this.id}`;
351351
const builtin = this;
352352
const exportsKeys = ArrayPrototypeSlice(this.exportKeys);
353-
ArrayPrototypePush(exportsKeys, 'default');
353+
if (!ArrayPrototypeIncludes(exportsKeys, 'default')) {
354+
ArrayPrototypePush(exportsKeys, 'default');
355+
}
354356
this.module = new ModuleWrap(
355357
url, undefined, exportsKeys,
356358
function() {

test/parallel/test-process-default.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('node:assert');
4+
5+
process.default = 1;
6+
import('node:process').then(common.mustCall((processModule) => {
7+
assert.strictEqual(processModule.default.default, 1);
8+
}));

0 commit comments

Comments
 (0)