module: fix crash when built-in module export a default key

PR-URL: https://github.com/nodejs/node/pull/51481
Fixes: https://github.com/nodejs/node/issues/51480
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This commit is contained in:
Antoine du Hamel 2024-01-19 09:42:07 +01:00 committed by GitHub
parent eb4432c12c
commit a7729737cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -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() {

View File

@ -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);
}));