diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/ops_builtin.rs | 23 | ||||
-rw-r--r-- | core/runtime.rs | 34 |
2 files changed, 30 insertions, 27 deletions
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 5c74c7330..96aca5c53 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -1,18 +1,29 @@ use crate::error::bad_resource_id; use crate::error::type_error; use crate::error::AnyError; +use crate::include_js_files; +use crate::op_sync; use crate::resources::ResourceId; +use crate::Extension; use crate::OpState; use crate::ZeroCopyBuf; -// TODO(@AaronO): provide these ops grouped as a runtime extension -// e.g: -// pub fn init_builtins() -> Extension { ... } +pub(crate) fn init_builtins() -> Extension { + Extension::builder() + .js(include_js_files!( + prefix "deno:core", + "core.js", + "error.js", + )) + .ops(vec![ + ("op_close", op_sync(op_close)), + ("op_resources", op_sync(op_resources)), + ]) + .build() +} /// Return map of resources with id as key /// and string representation as value. -/// -/// This op must be wrapped in `op_sync`. pub fn op_resources( state: &mut OpState, _args: (), @@ -27,8 +38,6 @@ pub fn op_resources( } /// Remove a resource from the resource table. -/// -/// This op must be wrapped in `op_sync`. pub fn op_close( state: &mut OpState, rid: Option<ResourceId>, diff --git a/core/runtime.rs b/core/runtime.rs index 171abbb5e..547f6aa23 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -305,6 +305,11 @@ impl JsRuntime { waker: AtomicWaker::new(), }))); + // Add builtins extension + options + .extensions + .insert(0, crate::ops_builtin::init_builtins()); + let mut js_runtime = Self { v8_isolate: Some(isolate), snapshot_creator: maybe_snapshot_creator, @@ -316,7 +321,6 @@ impl JsRuntime { // 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 @@ -360,18 +364,6 @@ impl JsRuntime { s.clone() } - /// Executes a JavaScript code to provide Deno.core and error reporting. - /// - /// This function can be called during snapshotting. - fn js_init(&mut self) { - self - .execute("deno:core/core.js", include_str!("core.js")) - .unwrap(); - self - .execute("deno:core/error.js", include_str!("error.js")) - .unwrap(); - } - /// Initializes JS of provided Extensions fn init_extension_js(&mut self) -> Result<(), AnyError> { // Take extensions to avoid double-borrow @@ -1592,7 +1584,8 @@ pub mod tests { dispatch_count: dispatch_count.clone(), }); - runtime.register_op("test", dispatch); + runtime.register_op("op_test", dispatch); + runtime.sync_ops_cache(); runtime .execute( @@ -1618,9 +1611,9 @@ pub mod tests { "filename.js", r#" let control = 42; - Deno.core.opcall(1, null, control); + Deno.core.opAsync("op_test", control); async function main() { - Deno.core.opcall(1, null, control); + Deno.core.opAsync("op_test", control); } main(); "#, @@ -1636,7 +1629,7 @@ pub mod tests { .execute( "filename.js", r#" - Deno.core.opcall(1); + Deno.core.opAsync("op_test"); "#, ) .unwrap(); @@ -1651,7 +1644,7 @@ pub mod tests { "filename.js", r#" let zero_copy_a = new Uint8Array([0]); - Deno.core.opcall(1, null, null, zero_copy_a); + Deno.core.opAsync("op_test", null, zero_copy_a); "#, ) .unwrap(); @@ -1954,7 +1947,8 @@ pub mod tests { module_loader: Some(loader), ..Default::default() }); - runtime.register_op("test", dispatcher); + runtime.register_op("op_test", dispatcher); + runtime.sync_ops_cache(); runtime .execute( @@ -1980,7 +1974,7 @@ pub mod tests { import { b } from './b.js' if (b() != 'b') throw Error(); let control = 42; - Deno.core.opcall(1, null, control); + Deno.core.opAsync("op_test", control); "#, ) .unwrap(); |