mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
fc2862b7f5
This bootstraps ESM loaders in the ShadowRealm with `ShadowRealm.prototype.importValue` as its entry point and enables loading ESM and CJS modules in the ShadowRealm. The module is imported without a parent URL and resolved with the current process's working directory. PR-URL: https://github.com/nodejs/node/pull/48655 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
22 lines
807 B
JavaScript
22 lines
807 B
JavaScript
// Flags: --experimental-shadow-realm
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
async function main() {
|
|
// Verifies that builtin modules can not be imported in the ShadowRealm.
|
|
const realm = new ShadowRealm();
|
|
// The error object created inside the ShadowRealm with the error code
|
|
// property is not copied on the realm boundary. Only the error message
|
|
// is copied. Simply check the error message here.
|
|
await assert.rejects(realm.importValue('fs', 'readFileSync'), {
|
|
message: /Cannot find package 'fs'/,
|
|
});
|
|
// As above, we can only validate the error message, not the error code.
|
|
await assert.rejects(realm.importValue('node:fs', 'readFileSync'), {
|
|
message: /No such built-in module: node:fs/,
|
|
});
|
|
}
|
|
|
|
main().then(common.mustCall());
|