33use super :: module_common:: { build_common_module_from_raw, ModuleCommon } ;
44use super :: module_host:: { CallReducerParams , DynModule , Module , ModuleInfo , ModuleInstance , ModuleRuntime } ;
55use super :: UpdateDatabaseResult ;
6- use crate :: host:: v8:: error:: { exception_already_thrown, ExceptionThrown , Throwable } ;
7- use crate :: host:: v8:: ser:: serialize_to_js;
86use crate :: host:: wasm_common:: module_host_actor:: InstanceCommon ;
97use crate :: host:: ArgsTuple ;
108use crate :: { host:: Scheduler , module_host_context:: ModuleCreationContext , replica_context:: ReplicaContext } ;
119use anyhow:: anyhow;
1210use de:: deserialize_js;
13- use error:: catch_exception;
11+ use error:: { catch_exception, exception_already_thrown , ExcResult , Throwable } ;
1412use from_value:: cast;
1513use key_cache:: get_or_create_key_cache;
14+ use ser:: serialize_to_js;
1615use spacetimedb_datastore:: locking_tx_datastore:: MutTxId ;
1716use spacetimedb_datastore:: traits:: Program ;
1817use spacetimedb_lib:: { ConnectionId , Identity , RawModuleDef } ;
@@ -147,14 +146,23 @@ impl ModuleInstance for JsInstance {
147146fn get_global_property < ' scope > (
148147 scope : & mut HandleScope < ' scope > ,
149148 key : Local < ' scope , v8:: String > ,
150- ) -> Result < Local < ' scope , Value > , ExceptionThrown > {
149+ ) -> ExcResult < Local < ' scope , Value > > {
151150 scope
152151 . get_current_context ( )
153152 . global ( scope)
154153 . get ( scope, key. into ( ) )
155154 . ok_or_else ( exception_already_thrown)
156155}
157156
157+ fn call_free_fun < ' scope > (
158+ scope : & mut HandleScope < ' scope > ,
159+ fun : Local < ' scope , Function > ,
160+ args : & [ Local < ' scope , Value > ] ,
161+ ) -> ExcResult < Local < ' scope , Value > > {
162+ let receiver = v8:: undefined ( scope) . into ( ) ;
163+ fun. call ( scope, receiver, args) . ok_or_else ( exception_already_thrown)
164+ }
165+
158166// Calls the `__call_reducer__` function on the global proxy object.
159167fn call_call_reducer (
160168 scope : & mut HandleScope < ' _ > ,
@@ -183,8 +191,7 @@ fn call_call_reducer(
183191 cast ! ( scope, object, Function , "function export for `__call_reducer__`" ) . map_err ( |e| e. throw ( scope) ) ?;
184192
185193 // Call the function.
186- let receiver = v8:: undefined ( scope) . into ( ) ;
187- let ret = fun. call ( scope, receiver, args) . ok_or_else ( exception_already_thrown) ?;
194+ let ret = call_free_fun ( scope, fun, args) ?;
188195
189196 // Deserialize the user result.
190197 let user_res = deserialize_js ( scope, ret) ?;
@@ -207,8 +214,7 @@ fn call_describe_module(scope: &mut HandleScope<'_>) -> anyhow::Result<RawModule
207214 cast ! ( scope, object, Function , "function export for `__describe_module__`" ) . map_err ( |e| e. throw ( scope) ) ?;
208215
209216 // Call the function.
210- let receiver = v8:: undefined ( scope) . into ( ) ;
211- let raw_mod_js = fun. call ( scope, receiver, & [ ] ) . ok_or_else ( exception_already_thrown) ?;
217+ let raw_mod_js = call_free_fun ( scope, fun, & [ ] ) ?;
212218
213219 // Deserialize the raw module.
214220 let raw_mod: RawModuleDef = deserialize_js ( scope, raw_mod_js) ?;
0 commit comments