summaryrefslogtreecommitdiff
path: root/core/ops_json.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-25 22:00:05 +0200
committerGitHub <noreply@github.com>2021-04-25 22:00:05 +0200
commit83bece56b01f6997cb71e9289a4d83a398cde0c8 (patch)
tree6f688f86bffd3ada71f7afa67d27a812d0bae386 /core/ops_json.rs
parent1c7164257d146c279b61708ddf8514d85b5fc11c (diff)
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
Diffstat (limited to 'core/ops_json.rs')
-rw-r--r--core/ops_json.rs12
1 files changed, 5 insertions, 7 deletions
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<F, V, R>(op_fn: F) -> Box<OpFn>
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<F, V, R, RV>(op_fn: F) -> Box<OpFn>
where
@@ -116,13 +116,11 @@ mod tests {
}
runtime.register_op("op_throw", op_async(op_throw));
+ runtime.sync_ops_cache();
runtime
.execute(
"<init>",
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');
}