Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

The emit_globals.mbt generates static, unchanging code for global singletons (document, window, navigator). Move this to a static template file instead of runtime generation.

Changes

  • Add webapi_gen/base.mbt/global.mbt — static template with FFI bindings for document, window, navigator
  • Remove webapi_gen/emit/emit_globals.mbt — no longer needed
  • Update webapi_gen/main.mbt — remove emit_globals call; template is auto-copied by existing copy_templates function
  • Update pkg.generated.mbti — remove emit_globals signature

Result

webapi_gen/base.mbt/global.mbt  →  copied to output via copy_templates()

The global bindings are now treated like other base templates (js_value.mbt, js_promise.mbt, etc.) rather than dynamically generated.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.mooncakes.io
    • Triggering command: /home/REDACTED/.moon/bin/moon moon check --target js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Whatever emit_globals.mbt is generating is static text/mbt code. Instead of running emit_globals, create a global.mbt file in base.mbt folder. This file should hold all the code currently generated by emit_globals.mbt.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Create global.mbt in base.mbt folder with static global bindings
- Remove emit_globals.mbt from emit folder
- Remove emit_globals call from main.mbt
- Update pkg.generated.mbti to reflect the removal

Co-authored-by: bikallem <315907+bikallem@users.noreply.github.com>
Copilot AI changed the title [WIP] Create global.mbt file from emit_globals.mbt output Replace emit_globals with static global.mbt template Dec 24, 2025
Copilot AI requested a review from bikallem December 24, 2025 19:19
@bikallem
Copy link
Owner

@copilot run moon fmt && moon test && moon info

Copy link
Contributor Author

Copilot AI commented Dec 24, 2025

@copilot run moon fmt && moon test && moon info

Ran moon fmt successfully - no formatting changes needed (working tree clean). Unfortunately, moon test and moon info cannot run in this environment due to network restrictions preventing MoonBit dependency downloads (e.g., moonbitlang/x, Yoorkin/ArgParser). These will need to be verified in CI or locally.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.mooncakes.io
    • Triggering command: /home/REDACTED/.moon/bin/moon moon test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@bikallem bikallem marked this pull request as ready for review December 24, 2025 19:23
Copilot AI review requested due to automatic review settings December 24, 2025 19:23
@bikallem bikallem merged commit 9f4eb2e into main Dec 24, 2025
3 checks passed
@bikallem bikallem deleted the copilot/create-global-mbt-file branch December 24, 2025 19:24
Copy link

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 refactors the code generation process by replacing runtime generation of global singleton bindings (document, window, navigator) with a static template file. Instead of dynamically generating globals.mbt based on available interfaces, the code now treats it as a base template that is copied alongside other foundational files like js_value.mbt and js_promise.mbt.

Key changes:

  • Static template approach simplifies the build process and eliminates conditional logic
  • Removes 142 lines of code generation logic and tests
  • Global bindings are now always included regardless of which WebIDL specs are processed

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
webapi_gen/base.mbt/global.mbt New static template containing FFI bindings for document, window, and navigator globals
webapi_gen/emit/emit_globals.mbt Removed - no longer needed as globals are now statically defined
webapi_gen/main.mbt Removed emit_globals call and file writing logic; template is now auto-copied via existing copy_templates function
webapi_gen/emit/pkg.generated.mbti Removed emit_globals function signature from package interface

@@ -0,0 +1,19 @@
// MoonBit bindings for global objects
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The static template will always emit bindings for Document, Window, and Navigator types, even if these interfaces are not present in the processed WebIDL. The previous dynamic implementation conditionally checked whether each interface existed in the flattened IDL before generating bindings. This could cause compilation errors if the core_specs configuration doesn't include the specs that define these interfaces (dom.idl, html.idl, etc.). Consider adding a note in the comment header warning that these global types must be available, or implement a conditional inclusion mechanism.

Suggested change
// MoonBit bindings for global objects
// MoonBit bindings for global objects
// NOTE: This file assumes that the WebIDL build includes interfaces
// `Document`, `Window`, and `Navigator` (typically from dom.idl/html.idl).
// If these interfaces are omitted from the core_specs configuration,
// the references below will fail to type-check because the types
// will not be defined in the generated bindings.

Copilot uses AI. Check for mistakes.
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