0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

refactor(core): initialize extensions in runtime constructor (#10421)

This ensures that provided extensions are all correctly setup and ready to use once the JsRuntime constructor returns

Note: this will also initialize ops for to-be-snapshotted runtimes
This commit is contained in:
Aaron O'Mullan 2021-04-30 16:38:35 +02:00 committed by GitHub
parent f31ee8d1bf
commit 5ec478b5fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 13 deletions

View file

@ -313,9 +313,16 @@ impl JsRuntime {
extensions: options.extensions,
};
// TODO(@AaronO): diff extensions inited in snapshot and those provided
// for now we assume that snapshot and extensions always match
if !has_startup_snapshot {
js_runtime.js_init();
js_runtime.init_extension_js().unwrap();
}
// Init extension ops
js_runtime.init_extension_ops().unwrap();
js_runtime.sync_ops_cache();
// Init async ops callback
js_runtime.init_recv_cb();
js_runtime
@ -366,8 +373,7 @@ impl JsRuntime {
}
/// Initializes JS of provided Extensions
// NOTE: this will probably change when streamlining snapshot flow
pub fn init_extension_js(&mut self) -> Result<(), AnyError> {
fn init_extension_js(&mut self) -> Result<(), AnyError> {
// Take extensions to avoid double-borrow
let mut extensions: Vec<Extension> = std::mem::take(&mut self.extensions);
for m in extensions.iter_mut() {
@ -384,8 +390,7 @@ impl JsRuntime {
}
/// Initializes ops of provided Extensions
// NOTE: this will probably change when streamlining snapshot flow
pub fn init_extension_ops(&mut self) -> Result<(), AnyError> {
fn init_extension_ops(&mut self) -> Result<(), AnyError> {
let op_state = self.op_state();
// Take extensions to avoid double-borrow
let mut extensions: Vec<Extension> = std::mem::take(&mut self.extensions);

View file

@ -10,9 +10,6 @@ fn create_js_runtime() -> JsRuntime {
..Default::default()
});
runtime.init_extension_js().unwrap();
runtime.init_extension_ops().unwrap();
runtime
.execute("setup", "const { URL } = globalThis.__bootstrap.url;")
.unwrap();

View file

@ -14,8 +14,6 @@ fn create_snapshot(
snapshot_path: &Path,
files: Vec<PathBuf>,
) {
js_runtime.init_extension_js().unwrap();
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
// workspace root.
let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();

View file

@ -253,8 +253,6 @@ impl WebWorker {
});
}
js_runtime.init_extension_ops().unwrap();
ops::web_worker::init(js_runtime, sender.clone(), handle);
ops::runtime::init(js_runtime, main_module);
ops::worker_host::init(

View file

@ -140,8 +140,6 @@ impl MainWorker {
});
}
js_runtime.init_extension_ops().unwrap();
ops::runtime::init(js_runtime, main_module);
ops::worker_host::init(
js_runtime,