summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench_util/src/js_runtime.rs8
-rw-r--r--cli/build.rs2
-rw-r--r--cli/lsp/tsc.rs1
-rw-r--r--cli/main.rs2
-rw-r--r--cli/tsc.rs1
-rw-r--r--cli/tsc/99_main_compiler.js5
-rw-r--r--core/benches/op_baseline.rs11
-rw-r--r--core/core.js9
-rw-r--r--core/examples/hello_world.rs7
-rw-r--r--core/examples/http_bench_json_ops.js2
-rw-r--r--core/examples/http_bench_json_ops.rs1
-rw-r--r--core/ops_json.rs12
-rw-r--r--core/runtime.rs8
-rw-r--r--op_crates/url/benches/url_ops.rs9
-rw-r--r--runtime/js/99_main.js2
-rw-r--r--runtime/web_worker.rs1
-rw-r--r--runtime/worker.rs1
17 files changed, 31 insertions, 51 deletions
diff --git a/bench_util/src/js_runtime.rs b/bench_util/src/js_runtime.rs
index 415f4a135..d5509d624 100644
--- a/bench_util/src/js_runtime.rs
+++ b/bench_util/src/js_runtime.rs
@@ -16,13 +16,7 @@ pub fn create_js_runtime(setup: impl FnOnce(&mut JsRuntime)) -> JsRuntime {
setup(&mut rt);
// Init ops
- rt.execute(
- "init",
- r#"
- Deno.core.ops();
- "#,
- )
- .unwrap();
+ rt.sync_ops_cache();
rt
}
diff --git a/cli/build.rs b/cli/build.rs
index 930ba376f..d4e6a92ab 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -210,6 +210,8 @@ fn create_compiler_snapshot(
}
}),
);
+ js_runtime.sync_ops_cache();
+
create_snapshot(js_runtime, snapshot_path, files);
}
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index fef605397..bb9311b2f 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -2122,6 +2122,7 @@ pub fn start(debug: bool) -> Result<JsRuntime, AnyError> {
runtime.register_op("op_respond", op(respond));
runtime.register_op("op_script_names", op(script_names));
runtime.register_op("op_script_version", op(script_version));
+ runtime.sync_ops_cache();
let init_config = json!({ "debug": debug });
let init_src = format!("globalThis.serverInit({});", init_config);
diff --git a/cli/main.rs b/cli/main.rs
index 0005bb891..c42604146 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -148,6 +148,7 @@ fn create_web_worker_callback(
if args.use_deno_namespace {
ops::runtime_compiler::init(js_runtime);
}
+ js_runtime.sync_ops_cache();
}
worker.bootstrap(&options);
@@ -218,6 +219,7 @@ pub fn create_main_worker(
// above
ops::errors::init(js_runtime);
ops::runtime_compiler::init(js_runtime);
+ js_runtime.sync_ops_cache();
}
worker.bootstrap(&options);
diff --git a/cli/tsc.rs b/cli/tsc.rs
index 0fac29ce3..167b5b110 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -496,6 +496,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
runtime.register_op("op_load", op(load));
runtime.register_op("op_resolve", op(resolve));
runtime.register_op("op_respond", op(respond));
+ runtime.sync_ops_cache();
let startup_source = "globalThis.startup({ legacyFlag: false })";
let request_value = json!({
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index ebb4d679d..f944b21b8 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -778,7 +778,6 @@ delete Object.prototype.__proto__;
}
hasStarted = true;
languageService = ts.createLanguageService(host);
- core.ops();
setLogDebug(debugFlag, "TSLS");
debug("serverInit()");
}
@@ -793,13 +792,9 @@ delete Object.prototype.__proto__;
throw new Error("The compiler runtime already started.");
}
hasStarted = true;
- core.ops();
setLogDebug(!!debugFlag, "TS");
}
- // Setup the compiler runtime during the build process.
- core.ops();
-
// A build time only op that provides some setup information that is used to
// ensure the snapshot is setup properly.
/** @type {{ buildSpecifier: string; libs: string[] }} */
diff --git a/core/benches/op_baseline.rs b/core/benches/op_baseline.rs
index a7f3bda1d..c0c988eb6 100644
--- a/core/benches/op_baseline.rs
+++ b/core/benches/op_baseline.rs
@@ -20,16 +20,7 @@ fn create_js_runtime() -> JsRuntime {
runtime.register_op("nop", |state, _, _| {
Op::Sync(serialize_op_result(Ok(9), state))
});
-
- // Init ops
- runtime
- .execute(
- "init",
- r#"
- Deno.core.ops();
- "#,
- )
- .unwrap();
+ runtime.sync_ops_cache();
runtime
}
diff --git a/core/core.js b/core/core.js
index a11f281f1..fd9b2c3ea 100644
--- a/core/core.js
+++ b/core/core.js
@@ -60,12 +60,14 @@
}
function ops() {
- // op id 0 is a special value to retrieve the map of registered ops.
- const newOpsCache = Object.fromEntries(opcall(0));
- opsCache = Object.freeze(newOpsCache);
return opsCache;
}
+ function syncOpsCache() {
+ // op id 0 is a special value to retrieve the map of registered ops.
+ opsCache = Object.freeze(Object.fromEntries(opcall(0)));
+ }
+
function handleAsyncMsgFromRust() {
for (let i = 0; i < arguments.length; i += 2) {
const promiseId = arguments[i];
@@ -130,5 +132,6 @@
resources,
registerErrorClass,
handleAsyncMsgFromRust,
+ syncOpsCache,
});
})(this);
diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs
index 62d268340..a9d2934f6 100644
--- a/core/examples/hello_world.rs
+++ b/core/examples/hello_world.rs
@@ -56,6 +56,7 @@ fn main() {
Ok(sum)
}),
);
+ runtime.sync_ops_cache();
// Now we see how to invoke the ops we just defined. The runtime automatically
// contains a Deno.core object with several functions for interacting with it.
@@ -64,11 +65,7 @@ fn main() {
.execute(
"<init>",
r#"
-// First we initialize the ops cache.
-// This maps op names to their id's.
-Deno.core.ops();
-
-// Then we define a print function that uses
+// Define a print function that uses
// our op_print op to display the stringified argument.
const _newline = new Uint8Array([10]);
function print(value) {
diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js
index 672747196..ad36dd674 100644
--- a/core/examples/http_bench_json_ops.js
+++ b/core/examples/http_bench_json_ops.js
@@ -54,8 +54,6 @@ async function serve(rid) {
}
async function main() {
- Deno.core.ops();
-
const listenerRid = listen();
Deno.core.print(`http_bench_ops listening on http://127.0.0.1:4544/\n`);
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs
index e1b435e4c..f891caa9e 100644
--- a/core/examples/http_bench_json_ops.rs
+++ b/core/examples/http_bench_json_ops.rs
@@ -116,6 +116,7 @@ fn create_js_runtime() -> JsRuntime {
runtime.register_op("accept", deno_core::op_async(op_accept));
runtime.register_op("read", deno_core::op_async(op_read));
runtime.register_op("write", deno_core::op_async(op_write));
+ runtime.sync_ops_cache();
runtime
}
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');
}
diff --git a/core/runtime.rs b/core/runtime.rs
index 34a83e3f3..7475c7020 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -367,6 +367,11 @@ impl JsRuntime {
state.js_recv_cb.replace(v8::Global::new(scope, cb));
}
+ /// Ensures core.js has the latest op-name to op-id mappings
+ pub fn sync_ops_cache(&mut self) {
+ self.execute("<anon>", "Deno.core.syncOpsCache()").unwrap()
+ }
+
/// Returns the runtime's op state, which can be used to maintain ops
/// and access resources between op calls.
pub fn op_state(&mut self) -> Rc<RefCell<OpState>> {
@@ -2140,6 +2145,7 @@ pub mod tests {
module_loader: Some(loader),
..Default::default()
});
+ runtime.sync_ops_cache();
runtime
.execute(
"file:///dyn_import3.js",
@@ -2149,8 +2155,6 @@ pub mod tests {
if (mod.b() !== 'b') {
throw Error("bad");
}
- // Now do any op
- Deno.core.ops();
})();
"#,
)
diff --git a/op_crates/url/benches/url_ops.rs b/op_crates/url/benches/url_ops.rs
index 37efb0a33..7d5d32879 100644
--- a/op_crates/url/benches/url_ops.rs
+++ b/op_crates/url/benches/url_ops.rs
@@ -15,6 +15,7 @@ fn create_js_runtime() -> JsRuntime {
"op_url_stringify_search_params",
op_sync(deno_url::op_url_stringify_search_params),
);
+ runtime.sync_ops_cache();
runtime
.execute(
@@ -24,14 +25,6 @@ fn create_js_runtime() -> JsRuntime {
.unwrap();
deno_url::init(&mut runtime);
runtime
- .execute(
- "init",
- r#"
- Deno.core.ops();
- "#,
- )
- .unwrap();
- runtime
.execute("setup", "const { URL } = globalThis.__bootstrap.url;")
.unwrap();
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 851d798c3..d2626a07d 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -142,8 +142,6 @@ delete Object.prototype.__proto__;
}
function runtimeStart(runtimeOptions, source) {
- core.ops();
-
core.setMacrotaskCallback(timers.handleTimerMacrotask);
version.setVersions(
runtimeOptions.denoVersion,
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index cdc3d7e3d..f6f88f59b 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -284,6 +284,7 @@ impl WebWorker {
t.add(stream);
}
}
+ js_runtime.sync_ops_cache();
worker
}
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 6de87f52e..6dbf8e7ec 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -171,6 +171,7 @@ impl MainWorker {
t.add(stream);
}
}
+ js_runtime.sync_ops_cache();
worker
}