Skip to content

Commit f126622

Browse files
committed
v8: some cleanup
1 parent 400d475 commit f126622

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

crates/core/src/host/v8/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
use super::module_common::{build_common_module_from_raw, ModuleCommon};
44
use super::module_host::{CallReducerParams, DynModule, Module, ModuleInfo, ModuleInstance, ModuleRuntime};
55
use super::UpdateDatabaseResult;
6-
use crate::host::v8::error::{exception_already_thrown, ExceptionThrown, Throwable};
7-
use crate::host::v8::ser::serialize_to_js;
86
use crate::host::wasm_common::module_host_actor::InstanceCommon;
97
use crate::host::ArgsTuple;
108
use crate::{host::Scheduler, module_host_context::ModuleCreationContext, replica_context::ReplicaContext};
119
use anyhow::anyhow;
1210
use de::deserialize_js;
13-
use error::catch_exception;
11+
use error::{catch_exception, exception_already_thrown, ExcResult, Throwable};
1412
use from_value::cast;
1513
use key_cache::get_or_create_key_cache;
14+
use ser::serialize_to_js;
1615
use spacetimedb_datastore::locking_tx_datastore::MutTxId;
1716
use spacetimedb_datastore::traits::Program;
1817
use spacetimedb_lib::{ConnectionId, Identity, RawModuleDef};
@@ -147,14 +146,23 @@ impl ModuleInstance for JsInstance {
147146
fn 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.
159167
fn 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)?;

crates/core/src/host/v8/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ macro_rules! serialize_primitive {
9292
/// However, the values of existing properties may be modified,
9393
/// which can be useful if the module wants to modify a property
9494
/// and then send the object back.
95-
fn seal_object(scope: &mut HandleScope<'_>, object: &Object) -> Result<(), ExceptionThrown> {
95+
fn seal_object(scope: &mut HandleScope<'_>, object: &Object) -> ExcResult<()> {
9696
let _ = object
9797
.set_integrity_level(scope, IntegrityLevel::Sealed)
9898
.ok_or_else(exception_already_thrown)?;

0 commit comments

Comments
 (0)