diff --git a/crates/core/src/host/v8/mod.rs b/crates/core/src/host/v8/mod.rs index 0abf9203163..0d3ad7acb24 100644 --- a/crates/core/src/host/v8/mod.rs +++ b/crates/core/src/host/v8/mod.rs @@ -25,7 +25,7 @@ use crate::host::wasm_common::module_host_actor::{ InstanceOp, ProcedureExecuteResult, ProcedureOp, ReducerExecuteResult, ReducerOp, ViewExecuteResult, ViewOp, WasmInstance, }; -use crate::host::wasm_common::{RowIters, TimingSpanSet, DESCRIBE_MODULE_DUNDER}; +use crate::host::wasm_common::{RowIters, TimingSpanSet}; use crate::host::{ModuleHost, ReducerCallError, ReducerCallResult, Scheduler}; use crate::module_host_context::{ModuleCreationContext, ModuleCreationContextLimited}; use crate::replica_context::ReplicaContext; @@ -871,8 +871,7 @@ fn extract_description<'scope>( replica_ctx: &ReplicaContext, ) -> Result { run_describer( - //TODO(shub): make it work with `DESCRIBE_MODULE_DUNDER_V10` - DESCRIBE_MODULE_DUNDER, + hooks.describe_func_name(), |a, b, c| log_traceback(replica_ctx, a, b, c), || { catch_exception(scope, |scope| { diff --git a/crates/core/src/host/v8/syscall/hooks.rs b/crates/core/src/host/v8/syscall/hooks.rs index 7a9207ee091..9a8003fa1c3 100644 --- a/crates/core/src/host/v8/syscall/hooks.rs +++ b/crates/core/src/host/v8/syscall/hooks.rs @@ -11,6 +11,8 @@ use crate::host::v8::error::Throwable; use crate::host::v8::error::TypeError; use crate::host::v8::from_value::cast; use crate::host::v8::string::StringConst; +use crate::host::wasm_common::DESCRIBE_MODULE_DUNDER; +use crate::host::wasm_common::DESCRIBE_MODULE_DUNDER_V10; /// Returns the hook function `name` on `hooks_obj`. pub(super) fn get_hook_function<'scope>( @@ -49,6 +51,7 @@ pub(in super::super) enum ModuleHookKey { CallView, CallAnonymousView, CallProcedure, + DescribeModuleV10, } impl ModuleHookKey { @@ -93,18 +96,39 @@ impl HooksInfo { } } +#[derive(Copy, Clone)] +/// The describe_module hook function for different `RawModuleDef`s. +pub enum DescribeModuleHook<'scope> { + Legacy(Local<'scope, Function>), + V10(Local<'scope, Function>), +} + #[derive(Copy, Clone)] /// The actual callable module hook functions and their abi version. pub(in super::super) struct HookFunctions<'scope> { pub abi: AbiVersion, /// describe_module and call_reducer existed in v1.0, but everything else is `Option`al - pub describe_module: Local<'scope, Function>, + pub describe_module: DescribeModuleHook<'scope>, pub call_reducer: Local<'scope, Function>, pub call_view: Option>, pub call_view_anon: Option>, pub call_procedure: Option>, } +impl HookFunctions<'_> { + pub(in super::super) fn describe_hook(&self) -> Local<'_, Function> { + match self.describe_module { + DescribeModuleHook::Legacy(f) | DescribeModuleHook::V10(f) => f, + } + } + + pub(in super::super) fn describe_func_name(&self) -> &'static str { + match self.describe_module { + DescribeModuleHook::Legacy(_) => DESCRIBE_MODULE_DUNDER, + DescribeModuleHook::V10(_) => DESCRIBE_MODULE_DUNDER_V10, + } + } +} /// Returns the hook function previously registered in [`register_hooks`]. pub(in super::super) fn get_hooks<'scope>(scope: &mut PinScope<'scope, '_>) -> Option> { let ctx = scope.get_current_context(); @@ -118,9 +142,17 @@ pub(in super::super) fn get_hooks<'scope>(scope: &mut PinScope<'scope, '_>) -> O }) }; + let describe_module = if let Some(f) = get(ModuleHookKey::DescribeModule) { + DescribeModuleHook::Legacy(f) + } else if let Some(f) = get(ModuleHookKey::DescribeModuleV10) { + DescribeModuleHook::V10(f) + } else { + return None; + }; + Some(HookFunctions { abi: hooks.abi, - describe_module: get(ModuleHookKey::DescribeModule)?, + describe_module, call_reducer: get(ModuleHookKey::CallReducer)?, call_view: get(ModuleHookKey::CallView), call_view_anon: get(ModuleHookKey::CallAnonymousView), diff --git a/crates/core/src/host/v8/syscall/v1.rs b/crates/core/src/host/v8/syscall/v1.rs index a7a90272352..4c4a2dffe23 100644 --- a/crates/core/src/host/v8/syscall/v1.rs +++ b/crates/core/src/host/v8/syscall/v1.rs @@ -682,7 +682,7 @@ pub(super) fn call_describe_module( hooks: &HookFunctions<'_>, ) -> Result> { // Call the function. - let raw_mod_js = call_free_fun(scope, hooks.describe_module, &[])?; + let raw_mod_js = call_free_fun(scope, hooks.describe_hook(), &[])?; // Deserialize the raw module. let raw_mod = cast!(