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: 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>
  • Loading branch information
aduh95 authored and marco-ippolito committed Jan 22, 2024
1 parent 7880ca6 commit f7c0be2
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 f7c0be2

Please sign in to comment.