Skip to content

Conversation

@bartlomieju
Copy link
Member

This should also solve problems in #30905 (comment).

Copilot AI review requested due to automatic review settings November 17, 2025 11:38
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; (() => {`,
Copy link
Member Author

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?

Copy link
Member Author

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;
Copy link
Member Author

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

Copy link
Member Author

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

Copilot finished reviewing on behalf of bartlomieju November 17, 2025 11:41
Copy link
Contributor

Copilot AI left a 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 globalThis property 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.

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

nice

@bartlomieju bartlomieju merged commit 9498b36 into denoland:main Nov 20, 2025
19 checks passed
@bartlomieju bartlomieju deleted the remove_managed_globals branch November 20, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants