@@ -16,7 +16,6 @@ import arc/vm/value.{type FuncTemplate, type JsValue, type Ref, JsObject}
1616import gleam/dict
1717import gleam/option . { type Option , None , Some }
1818import gleam/result
19- import gleam/set
2019
2120// ============================================================================
2221// Public types
@@ -33,8 +32,7 @@ pub type ModuleResult {
3332pub type ReplEnv {
3433 ReplEnv (
3534 global_object : Ref ,
36- lexical_globals : dict . Dict ( String , JsValue ) ,
37- const_lexical_globals : set . Set ( String ) ,
35+ lexical_globals : dict . Dict ( String , value . LexicalGlobal ) ,
3836 symbol_descriptions : dict . Dict ( value . SymbolId , String ) ,
3937 symbol_registry : dict . Dict ( String , value . SymbolId ) ,
4038 /// Realm builtins registry, keyed by RealmSlot ref.
@@ -99,7 +97,6 @@ pub fn run_module(
9997 builtins ,
10098 global_object ,
10199 dict . new ( ) ,
102- set . new ( ) ,
103100 dict . new ( ) ,
104101 dict . new ( ) ,
105102 )
@@ -131,7 +128,6 @@ pub fn run_and_drain_repl(
131128 builtins ,
132129 env . global_object ,
133130 env . lexical_globals ,
134- env . const_lexical_globals ,
135131 env . symbol_descriptions ,
136132 env . symbol_registry ,
137133 ) ,
@@ -145,7 +141,6 @@ pub fn run_and_drain_repl(
145141 ReplEnv (
146142 global_object : drained . global_object ,
147143 lexical_globals : drained . lexical_globals ,
148- const_lexical_globals : drained . const_lexical_globals ,
149144 symbol_descriptions : drained . symbol_descriptions ,
150145 symbol_registry : drained . symbol_registry ,
151146 realms : drained . realms ,
@@ -154,13 +149,15 @@ pub fn run_and_drain_repl(
154149}
155150
156151/// Call a function value with `this` and `args`, then run the `finish` driver
157- /// to drain. The counterpart to `run`/`run_with` for a value you already hold
158- /// — e.g. a `receive` export read off a module namespace — so an embedder can
159- /// invoke it the way the engine would, without re-evaluating a script. This is
160- /// the host-call-then-drain pattern (cf. Node's MakeCallback, QuickJS
161- /// `JS_Call` + the `JS_ExecutePendingJob` loop): draining happens at this
162- /// outermost call only, so don't call it from inside a host function — use the
163- /// re-entrant `state.call` there.
152+ /// to drain. The counterpart to `run`/`run_with` for a value you already hold —
153+ /// e.g. a `receive` export read off a module namespace — letting an embedder
154+ /// invoke it without re-evaluating a script. The host-call-then-drain pattern
155+ /// (cf. Node's MakeCallback, QuickJS `JS_Call` + `JS_ExecutePendingJob`).
156+ ///
157+ /// Built on the lossless `interpreter.call_root`, so it shares its shape with
158+ /// `run`/`run_with`: a thrown value is a `ThrowCompletion`, an engine `VmError`
159+ /// surfaces as `Error` (not a panic — the embedder is outside the VM and can
160+ /// handle it). Draining happens once, at this outermost call.
164161pub fn run_export (
165162 callee : JsValue ,
166163 this_val : JsValue ,
@@ -170,16 +167,10 @@ pub fn run_export(
170167 global_object : Ref ,
171168 finish : fn ( State ) -> State ,
172169) -> Result ( Completion , VmError ) {
173- let executed =
174- interpreter . call_to_completion (
175- callee ,
176- this_val ,
177- args ,
178- heap ,
179- builtins ,
180- global_object ,
181- )
182- use # ( settled , drained ) <- result . map ( settle ( executed , finish ) )
170+ use # ( settled , drained ) <- result . map ( settle (
171+ interpreter . call_root ( callee , this_val , args , heap , builtins , global_object ) ,
172+ finish ,
173+ ) )
183174 completion_of ( settled , drained . heap )
184175}
185176
0 commit comments