From 83bece56b01f6997cb71e9289a4d83a398cde0c8 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 25 Apr 2021 22:00:05 +0200 Subject: refactor(core): move op cache sync responsibility to rust space (#10340) Even if bootstrapping the JS runtime is low level, it's an abstraction leak of core to require users to call `Deno.core.ops()` in JS space. So instead we're introducing a `JsRuntime::sync_ops_cache()` method, once we have runtime extensions a new runtime will ensure the ops cache is setup (for the provided extensions) and then loading/unloading plugins should be the only operations that require op cache syncs --- core/ops_json.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'core/ops_json.rs') diff --git a/core/ops_json.rs b/core/ops_json.rs index 309fac12d..a04bdac60 100644 --- a/core/ops_json.rs +++ b/core/ops_json.rs @@ -25,15 +25,15 @@ use std::rc::Rc; /// ```ignore /// let mut runtime = JsRuntime::new(...); /// runtime.register_op("hello", deno_core::op_sync(Self::hello_op)); +/// runtime.sync_ops_cache(); /// ``` /// /// ...it can be invoked from JS using the provided name, for example: /// ```js -/// Deno.core.ops(); /// let result = Deno.core.opSync("function_name", args); /// ``` /// -/// The `Deno.core.ops()` statement is needed once before any op calls, for initialization. +/// `runtime.sync_ops_cache()` must be called after registering new ops /// A more complete example is available in the examples directory. pub fn op_sync(op_fn: F) -> Box where @@ -63,15 +63,15 @@ where /// ```ignore /// let mut runtime = JsRuntime::new(...); /// runtime.register_op("hello", deno_core::op_async(Self::hello_op)); +/// runtime.sync_ops_cache(); /// ``` /// /// ...it can be invoked from JS using the provided name, for example: /// ```js -/// Deno.core.ops(); /// let future = Deno.core.opAsync("function_name", args); /// ``` /// -/// The `Deno.core.ops()` statement is needed once before any op calls, for initialization. +/// `runtime.sync_ops_cache()` must be called after registering new ops /// A more complete example is available in the examples directory. pub fn op_async(op_fn: F) -> Box where @@ -116,13 +116,11 @@ mod tests { } runtime.register_op("op_throw", op_async(op_throw)); + runtime.sync_ops_cache(); runtime .execute( "", r#" - // First we initialize the ops cache. This maps op names to their id's. - Deno.core.ops(); - async function f1() { await Deno.core.opAsync('op_throw', 'hello'); } -- cgit v1.2.3