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 <legendecas@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
  • Loading branch information
aduh95 authored and targos committed Feb 15, 2024
1 parent d3b7805 commit 391aeb1
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 391aeb1

Please sign in to comment.