Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions webapi_gen/base.mbt/global.mbt
Original file line number Diff line number Diff line change
@@ -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.

///|
extern "js" fn global_document_ffi() -> Document = "() => document"

///|
pub let document : Document = global_document_ffi()

///|
extern "js" fn global_window_ffi() -> Window = "() => window"

///|
pub let window : Window = global_window_ffi()

///|
extern "js" fn global_navigator_ffi() -> Navigator = "() => navigator"

///|
pub let navigator : Navigator = global_navigator_ffi()
142 changes: 0 additions & 142 deletions webapi_gen/emit/emit_globals.mbt

This file was deleted.

2 changes: 0 additions & 2 deletions webapi_gen/emit/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import(
// Values
pub fn[E : Emitter] emit_all(E, Iter[String]) -> Map[Filename, Code]

pub fn emit_globals(@flattened_idl.FlattenedIdl) -> String

pub fn emit_js_runtime(@flattened_idl.FlattenedIdl) -> String

pub fn mbt_code_gen(Array[Emit]) -> String
Expand Down
9 changes: 0 additions & 9 deletions webapi_gen/main.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@ fn main {
flattened.callbacks.keys(),
)

// Generate and write globals
println("=== Generating Globals ===")
let globals_code = @emit.emit_globals(flattened)
let globals_filepath = "\{output_dir}/globals.mbt"
println(" Writing \{globals_filepath}...")
@fs.write_string_to_file(globals_filepath, globals_code) catch {
e => fail("failed to write file: \{e}")
}

// XXX: Disabled for now since we only need JS bindings
// Generate and write JS runtime
// println("=== Generating JS Runtime ===")
Expand Down