Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: globals should be wrapped to stay in sync with ESM #29426

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { Object, SafeWeakMap } = primordials;
const { NativeModule } = require('internal/bootstrap/loaders');

const { getOptionValue } = require('internal/options');
const { Buffer } = require('buffer');
Expand Down Expand Up @@ -369,6 +370,11 @@ function initializeCJSLoader() {
}

function initializeESMLoader() {
// proxify the global process to keep in sync with ESM
const mod = NativeModule.map.get('process');
mod.compileForPublicLoader(true);
globalThis.process = mod.exports;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is done when ESM is not even used doesn't this just slow down access to globalThis.process unconditionally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, but that's how to keep ESM names synced


// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
internalBinding('module_wrap').callbackMap = new SafeWeakMap();

Expand Down