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 --- cli/build.rs | 2 ++ cli/lsp/tsc.rs | 1 + cli/main.rs | 2 ++ cli/tsc.rs | 1 + cli/tsc/99_main_compiler.js | 5 ----- 5 files changed, 6 insertions(+), 5 deletions(-) (limited to 'cli') 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 { 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 { 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[] }} */ -- cgit v1.2.3