-
Notifications
You must be signed in to change notification settings - Fork 5.8k
refactor: remove 'managed globals' infra #31318
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
refactor: remove 'managed globals' infra #31318
Conversation
| Module.wrapper = [ | ||
| `(function (exports, require, module, __filename, __dirname) { var { Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout } = Deno[Deno.internal].nodeGlobals; (() => {`, | ||
| // TODO(bartlomieju): these should actually be stored somewhere | ||
| `(function (exports, require, module, __filename, __dirname) { var { Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout } = globalThis; (() => {`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can now skip destructuring all these variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that in a follow up
| nodeGlobals.setImmediate = nativeModuleExports["timers"].setImmediate; | ||
| nodeGlobals.setInterval = nativeModuleExports["timers"].setInterval; | ||
| nodeGlobals.setTimeout = nativeModuleExports["timers"].setTimeout; | ||
| globalThis.Buffer = nativeModuleExports["buffer"].Buffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this can be moved to 98_global_scope_shared.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that in a follow up too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes the complex "managed globals" infrastructure that used V8 named property handlers and proxies to dynamically serve different global values based on whether code was running in node_modules. The refactor simplifies the implementation by directly assigning Node.js-specific globals to globalThis.
Key Changes
- Removed the proxy-based global interception system that provided context-dependent globals
- Simplified to direct
globalThisproperty assignments for Node.js globals (Buffer, process, timers, etc.) - Eliminated approximately 500 lines of complex Rust code and associated JavaScript glue
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ext/node/global.rs | Entire file deleted - removed V8 property handler callbacks and GlobalsStorage infrastructure |
| ext/node/lib.rs | Removed global module import, middleware references, and external references for property handlers |
| ext/node/polyfills/00_globals.js | File deleted - no longer needed to export nodeGlobals/denoGlobals objects |
| ext/node/polyfills/02_init.js | Changed from assigning to nodeGlobals object to directly assigning to globalThis |
| ext/node/polyfills/01_require.js | Updated Module.wrapper to destructure Node globals from globalThis instead of Deno.internal.nodeGlobals |
| runtime/js/99_main.js | Removed nodeGlobals import and removed it from internals object assignment |
| tools/core_import_map.json | Removed import map entry for deleted 00_globals.js file |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
littledivy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
This should also solve problems in #30905 (comment).