diff --git a/cli/bench/http.rs b/cli/bench/http.rs index 690e26cf49..7fdab9844f 100644 --- a/cli/bench/http.rs +++ b/cli/bench/http.rs @@ -21,9 +21,6 @@ pub(crate) fn benchmark( let hyper_hello_exe = target_path.join("test_server"); let hyper_hello_exe = hyper_hello_exe.to_str().unwrap(); - let core_http_bin_ops_exe = target_path.join("examples/http_bench_bin_ops"); - let core_http_bin_ops_exe = core_http_bin_ops_exe.to_str().unwrap(); - let core_http_json_ops_exe = target_path.join("examples/http_bench_json_ops"); let core_http_json_ops_exe = core_http_json_ops_exe.to_str().unwrap(); @@ -40,12 +37,8 @@ pub(crate) fn benchmark( "deno_proxy_tcp".to_string(), deno_tcp_proxy(deno_exe, hyper_hello_exe)?, ); - // "core_http_bin_ops" was once called "deno_core_single" - // "core_http_bin_ops" was once called "deno_core_http_bench" - res.insert( - "core_http_bin_ops".to_string(), - core_http_bin_ops(core_http_bin_ops_exe)?, - ); + // "core_http_json_ops" previously had a "bin op" counterpart called "core_http_bin_ops", + // which was previously also called "deno_core_http_bench", "deno_core_single" res.insert( "core_http_json_ops".to_string(), core_http_json_ops(core_http_json_ops_exe)?, @@ -246,11 +239,6 @@ fn deno_http_proxy( ) } -fn core_http_bin_ops(exe: &str) -> Result { - println!("http_benchmark testing CORE http_bench_bin_ops"); - run(&[exe], 4544, None, None) -} - fn core_http_json_ops(exe: &str) -> Result { println!("http_benchmark testing CORE http_bench_json_ops"); run(&[exe], 4544, None, None) diff --git a/cli/build.rs b/cli/build.rs index 1b1e913d28..930ba376f1 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::custom_error; -use deno_core::json_op_sync; +use deno_core::op_sync; use deno_core::serde::Deserialize; use deno_core::serde_json; use deno_core::serde_json::json; @@ -156,7 +156,7 @@ fn create_compiler_snapshot( }); js_runtime.register_op( "op_build_info", - json_op_sync(move |_state, _args: Value, _bufs| { + op_sync(move |_state, _args: Value, _bufs| { Ok(json!({ "buildSpecifier": build_specifier, "libs": build_libs, @@ -167,7 +167,7 @@ fn create_compiler_snapshot( // files, but a slightly different implementation at build time. js_runtime.register_op( "op_load", - json_op_sync(move |_state, args, _bufs| { + op_sync(move |_state, args, _bufs| { let v: LoadArgs = serde_json::from_value(args)?; // we need a basic file to send to tsc to warm it up. if v.specifier == build_specifier { diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 38b736349c..aaea82421e 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -18,7 +18,7 @@ use crate::tsc_config::TsConfig; use deno_core::error::anyhow; use deno_core::error::custom_error; use deno_core::error::AnyError; -use deno_core::json_op_sync; +use deno_core::op_sync; use deno_core::resolve_url; use deno_core::serde::de; use deno_core::serde::Deserialize; @@ -1480,7 +1480,7 @@ where V: de::DeserializeOwned, R: Serialize + 'static, { - json_op_sync(move |s, args, _bufs| { + op_sync(move |s, args, _bufs| { let state = s.borrow_mut::(); op_fn(state, args) }) diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index 5dc4026f7d..b3591b6f95 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -15,8 +15,8 @@ use std::collections::HashMap; use std::sync::Arc; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_apply_source_map", op_apply_source_map); - super::reg_json_sync(rt, "op_format_diagnostic", op_format_diagnostic); + super::reg_sync(rt, "op_apply_source_map", op_apply_source_map); + super::reg_sync(rt, "op_format_diagnostic", op_format_diagnostic); } #[derive(Deserialize)] diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 782b0a2019..8caede260c 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -4,8 +4,8 @@ pub mod errors; pub mod runtime_compiler; use deno_core::error::AnyError; -use deno_core::json_op_async; -use deno_core::json_op_sync; +use deno_core::op_async; +use deno_core::op_sync; use deno_core::serde_json::Value; use deno_core::JsRuntime; use deno_core::OpState; @@ -15,18 +15,18 @@ use std::cell::RefCell; use std::future::Future; use std::rc::Rc; -pub fn reg_json_async(rt: &mut JsRuntime, name: &'static str, op_fn: F) +pub fn reg_async(rt: &mut JsRuntime, name: &'static str, op_fn: F) where F: Fn(Rc>, Value, Option) -> R + 'static, R: Future> + 'static, { - rt.register_op(name, metrics_op(name, json_op_async(op_fn))); + rt.register_op(name, metrics_op(name, op_async(op_fn))); } -pub fn reg_json_sync(rt: &mut JsRuntime, name: &'static str, op_fn: F) +pub fn reg_sync(rt: &mut JsRuntime, name: &'static str, op_fn: F) where F: Fn(&mut OpState, Value, Option) -> Result + 'static, { - rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); + rt.register_op(name, metrics_op(name, op_sync(op_fn))); } diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index acd307f2f9..dc9cd21632 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -28,7 +28,7 @@ use std::sync::Arc; use std::sync::Mutex; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_async(rt, "op_emit", op_emit); + super::reg_async(rt, "op_emit", op_emit); } #[derive(Debug, Deserialize)] diff --git a/cli/tests/unit/dispatch_bin_test.ts b/cli/tests/unit/dispatch_test.ts similarity index 75% rename from cli/tests/unit/dispatch_bin_test.ts rename to cli/tests/unit/dispatch_test.ts index 01f29d0bcf..6805d1af78 100644 --- a/cli/tests/unit/dispatch_bin_test.ts +++ b/cli/tests/unit/dispatch_test.ts @@ -9,7 +9,7 @@ unitTest(async function sendAsyncStackTrace() { } catch (error) { const s = error.stack.toString(); console.log(s); - assertStringIncludes(s, "dispatch_bin_test.ts"); + assertStringIncludes(s, "dispatch_test.ts"); assertStringIncludes(s, "read"); } }); @@ -21,10 +21,10 @@ declare global { } } -unitTest(async function binOpsAsyncBadResource(): Promise { +unitTest(async function opsAsyncBadResource(): Promise { try { const nonExistingRid = 9999; - await Deno.core.binOpAsync( + await Deno.core.opAsync( "op_read_async", nonExistingRid, new Uint8Array(0), @@ -36,10 +36,10 @@ unitTest(async function binOpsAsyncBadResource(): Promise { } }); -unitTest(function binOpsSyncBadResource(): void { +unitTest(function opsSyncBadResource(): void { try { const nonExistingRid = 9999; - Deno.core.binOpSync("op_read_sync", nonExistingRid, new Uint8Array(0)); + Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0)); } catch (e) { if (!(e instanceof Deno.errors.BadResource)) { throw e; diff --git a/cli/tests/unit/unit_tests.ts b/cli/tests/unit/unit_tests.ts index 0dcbfe80bb..ebf87651d4 100644 --- a/cli/tests/unit/unit_tests.ts +++ b/cli/tests/unit/unit_tests.ts @@ -15,7 +15,7 @@ import "./console_test.ts"; import "./copy_file_test.ts"; import "./custom_event_test.ts"; import "./dir_test.ts"; -import "./dispatch_bin_test.ts"; +import "./dispatch_test.ts"; import "./error_stack_test.ts"; import "./event_test.ts"; import "./event_target_test.ts"; diff --git a/cli/tsc.rs b/cli/tsc.rs index 834b0cc587..0fac29ce3d 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -10,7 +10,7 @@ use deno_core::error::anyhow; use deno_core::error::bail; use deno_core::error::AnyError; use deno_core::error::Context; -use deno_core::json_op_sync; +use deno_core::op_sync; use deno_core::resolve_url_or_path; use deno_core::serde::Deserialize; use deno_core::serde_json; @@ -227,7 +227,7 @@ fn op(op_fn: F) -> Box where F: Fn(&mut State, Value) -> Result + 'static, { - json_op_sync(move |s, args, _bufs| { + op_sync(move |s, args, _bufs| { let state = s.borrow_mut::(); op_fn(state, args) }) diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 9396ba4adf..dc2b59533f 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -200,7 +200,7 @@ delete Object.prototype.__proto__; debug( `snapshot.getText(${start}, ${end}) specifier: ${specifier} version: ${version}`, ); - return core.jsonOpSync("op_get_text", { specifier, version, start, end }); + return core.opSync("op_get_text", { specifier, version, start, end }); } /** * @returns {number} @@ -208,7 +208,7 @@ delete Object.prototype.__proto__; getLength() { const { specifier, version } = this; debug(`snapshot.getLength() specifier: ${specifier} version: ${version}`); - return core.jsonOpSync("op_get_length", { specifier, version }); + return core.opSync("op_get_length", { specifier, version }); } /** * @param {ScriptSnapshot} oldSnapshot @@ -221,7 +221,7 @@ delete Object.prototype.__proto__; debug( `snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`, ); - return core.jsonOpSync( + return core.opSync( "op_get_change_range", { specifier, oldLength, oldVersion, version }, ); @@ -229,7 +229,7 @@ delete Object.prototype.__proto__; dispose() { const { specifier, version } = this; debug(`snapshot.dispose() specifier: ${specifier} version: ${version}`); - core.jsonOpSync("op_dispose", { specifier, version }); + core.opSync("op_dispose", { specifier, version }); } } @@ -250,7 +250,7 @@ delete Object.prototype.__proto__; }, readFile(specifier) { debug(`host.readFile("${specifier}")`); - return core.jsonOpSync("op_load", { specifier }).data; + return core.opSync("op_load", { specifier }).data; }, getSourceFile( specifier, @@ -272,7 +272,7 @@ delete Object.prototype.__proto__; specifier = normalizedToOriginalMap.get(specifier) ?? specifier; /** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */ - const { data, hash, scriptKind } = core.jsonOpSync( + const { data, hash, scriptKind } = core.opSync( "op_load", { specifier }, ); @@ -304,7 +304,7 @@ delete Object.prototype.__proto__; if (sourceFiles) { maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName); } - return core.jsonOpSync( + return core.opSync( "op_emit", { maybeSpecifiers, fileName, data }, ); @@ -326,7 +326,7 @@ delete Object.prototype.__proto__; debug(` base: ${base}`); debug(` specifiers: ${specifiers.join(", ")}`); /** @type {Array<[string, ts.Extension] | undefined>} */ - const resolved = core.jsonOpSync("op_resolve", { + const resolved = core.opSync("op_resolve", { specifiers, base, }); @@ -349,7 +349,7 @@ delete Object.prototype.__proto__; } }, createHash(data) { - return core.jsonOpSync("op_create_hash", { data }).hash; + return core.opSync("op_create_hash", { data }).hash; }, // LanguageServiceHost @@ -359,7 +359,7 @@ delete Object.prototype.__proto__; }, getScriptFileNames() { debug("host.getScriptFileNames()"); - return core.jsonOpSync("op_script_names", undefined); + return core.opSync("op_script_names", undefined); }, getScriptVersion(specifier) { debug(`host.getScriptVersion("${specifier}")`); @@ -367,7 +367,7 @@ delete Object.prototype.__proto__; if (sourceFile) { return sourceFile.version ?? "1"; } - return core.jsonOpSync("op_script_version", { specifier }); + return core.opSync("op_script_version", { specifier }); }, getScriptSnapshot(specifier) { debug(`host.getScriptSnapshot("${specifier}")`); @@ -386,7 +386,7 @@ delete Object.prototype.__proto__; }; } /** @type {string | undefined} */ - const version = core.jsonOpSync("op_script_version", { specifier }); + const version = core.opSync("op_script_version", { specifier }); if (version != null) { return new ScriptSnapshot(specifier, version); } @@ -505,7 +505,7 @@ delete Object.prototype.__proto__; ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code)); performanceProgram({ program }); - core.jsonOpSync("op_respond", { + core.opSync("op_respond", { diagnostics: fromTypeScriptDiagnostic(diagnostics), stats: performanceEnd(), }); @@ -517,7 +517,7 @@ delete Object.prototype.__proto__; * @param {any} data */ function respond(id, data = null) { - core.jsonOpSync("op_respond", { id, data }); + core.opSync("op_respond", { id, data }); } /** @@ -767,7 +767,7 @@ delete Object.prototype.__proto__; // 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[] }} */ - const { buildSpecifier, libs } = core.jsonOpSync("op_build_info", {}); + const { buildSpecifier, libs } = core.opSync("op_build_info", {}); for (const lib of libs) { const specifier = `lib.${lib}.d.ts`; // we are using internal APIs here to "inject" our custom libraries into diff --git a/cli/tsc/compiler.d.ts b/cli/tsc/compiler.d.ts index ec82af1e2a..0b1f5e4de9 100644 --- a/cli/tsc/compiler.d.ts +++ b/cli/tsc/compiler.d.ts @@ -34,7 +34,7 @@ declare global { interface DenoCore { // deno-lint-ignore no-explicit-any - jsonOpSync(name: string, params: T): any; + opSync(name: string, params: T): any; ops(): void; print(msg: string, code?: number): void; registerErrorClass( diff --git a/core/Cargo.toml b/core/Cargo.toml index bf4c7dc14f..572d487130 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -26,10 +26,6 @@ serde_json = { version = "1.0.64", features = ["preserve_order"] } serde_v8 = { version = "0.1.0", path = "../serde_v8" } url = { version = "2.2.1", features = ["serde"] } -[[example]] -name = "http_bench_bin_ops" -path = "examples/http_bench_bin_ops.rs" - [[example]] name = "http_bench_json_ops" path = "examples/http_bench_json_ops.rs" diff --git a/core/README.md b/core/README.md index 55ec05a2d0..fc1fc3d319 100644 --- a/core/README.md +++ b/core/README.md @@ -21,9 +21,7 @@ function to trigger the "dispatch" callback in Rust. The user is responsible for encoding both the request and response into a Uint8Array. Documentation for this crate is thin at the moment. Please see -[http_bench_bin_ops.rs](https://github.com/denoland/deno/blob/main/core/examples/http_bench_bin_ops.rs) -and -[http_bench_json_ops.rs](https://github.com/denoland/deno/blob/main/core/examples/http_bench_json_ops.rs) +[http_bench_ops.rs](https://github.com/denoland/deno/blob/main/core/examples/http_bench_ops.rs) as a simple example of usage. TypeScript support and a lot of other functionality is not available at this diff --git a/core/benches/op_baseline.rs b/core/benches/op_baseline.rs index 81c5d89b88..5287a7a8b1 100644 --- a/core/benches/op_baseline.rs +++ b/core/benches/op_baseline.rs @@ -1,9 +1,8 @@ use bencher::{benchmark_group, benchmark_main, Bencher}; -use deno_core::bin_op_sync; use deno_core::error::AnyError; -use deno_core::json_op_async; -use deno_core::json_op_sync; +use deno_core::op_async; +use deno_core::op_sync; use deno_core::v8; use deno_core::JsRuntime; use deno_core::Op; @@ -16,9 +15,8 @@ use std::rc::Rc; fn create_js_runtime() -> JsRuntime { let mut runtime = JsRuntime::new(Default::default()); - runtime.register_op("pi_bin", bin_op_sync(|_, _, _| Ok(314159))); - runtime.register_op("pi_json", json_op_sync(|_, _: (), _| Ok(314159))); - runtime.register_op("pi_async", json_op_async(op_pi_async)); + runtime.register_op("pi_json", op_sync(|_, _: (), _| Ok(314159))); + runtime.register_op("pi_async", op_async(op_pi_async)); runtime .register_op("nop", |_, _, _| Op::Sync(OpResponse::Value(Box::new(9)))); @@ -70,20 +68,11 @@ pub fn bench_runtime_js_async(b: &mut Bencher, src: &str) { }); } -fn bench_op_pi_bin(b: &mut Bencher) { - bench_runtime_js( - b, - r#"for(let i=0; i < 1e3; i++) { - Deno.core.binOpSync("pi_bin", 0, null); - }"#, - ); -} - fn bench_op_pi_json(b: &mut Bencher) { bench_runtime_js( b, r#"for(let i=0; i < 1e3; i++) { - Deno.core.jsonOpSync("pi_json", null); + Deno.core.opSync("pi_json", null); }"#, ); } @@ -101,16 +90,10 @@ fn bench_op_async(b: &mut Bencher) { bench_runtime_js_async( b, r#"for(let i=0; i < 1e3; i++) { - Deno.core.jsonOpAsync("pi_async", null); + Deno.core.opAsync("pi_async", null); }"#, ); } -benchmark_group!( - benches, - bench_op_pi_bin, - bench_op_pi_json, - bench_op_nop, - bench_op_async -); +benchmark_group!(benches, bench_op_pi_json, bench_op_nop, bench_op_async); benchmark_main!(benches); diff --git a/core/core.js b/core/core.js index 3142aa93ae..0697458de3 100644 --- a/core/core.js +++ b/core/core.js @@ -102,7 +102,7 @@ return res; } - function jsonOpAsync(opName, args = null, zeroCopy = null) { + function opAsync(opName, args = null, zeroCopy = null) { const promiseId = nextPromiseId++; const maybeError = dispatch(opName, promiseId, args, zeroCopy); // Handle sync error (e.g: error parsing args) @@ -110,31 +110,21 @@ return setPromise(promiseId).then(unwrapOpResult); } - function jsonOpSync(opName, args = null, zeroCopy = null) { + function opSync(opName, args = null, zeroCopy = null) { return unwrapOpResult(dispatch(opName, null, args, zeroCopy)); } - function binOpSync(opName, args = null, zeroCopy = null) { - return jsonOpSync(opName, args, zeroCopy); - } - - function binOpAsync(opName, args = null, zeroCopy = null) { - return jsonOpAsync(opName, args, zeroCopy); - } - function resources() { - return Object.fromEntries(jsonOpSync("op_resources")); + return Object.fromEntries(opSync("op_resources")); } function close(rid) { - jsonOpSync("op_close", rid); + opSync("op_close", rid); } Object.assign(window.Deno.core, { - binOpAsync, - binOpSync, - jsonOpAsync, - jsonOpSync, + opAsync, + opSync, dispatch: send, dispatchByName: dispatch, ops, diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs index 11fc5ff0ef..154c05d97e 100644 --- a/core/examples/hello_world.rs +++ b/core/examples/hello_world.rs @@ -2,7 +2,7 @@ //! This example shows you how to define ops in Rust and then call them from //! JavaScript. -use deno_core::json_op_sync; +use deno_core::op_sync; use deno_core::JsRuntime; use std::io::Write; @@ -26,7 +26,7 @@ fn main() { // The op_fn callback takes a state object OpState, // a structured arg of type `T` and an optional ZeroCopyBuf, // a mutable reference to a JavaScript ArrayBuffer - json_op_sync(|_state, msg: Option, zero_copy| { + op_sync(|_state, msg: Option, zero_copy| { let mut out = std::io::stdout(); // Write msg to stdout @@ -46,10 +46,10 @@ fn main() { // Register the JSON op for summing a number array. runtime.register_op( "op_sum", - // The json_op_sync function automatically deserializes + // The op_sync function automatically deserializes // the first ZeroCopyBuf and serializes the return value // to reduce boilerplate - json_op_sync(|_state, nums: Vec, _| { + op_sync(|_state, nums: Vec, _| { // Sum inputs let sum = nums.iter().fold(0.0, |a, v| a + v); // return as a Result @@ -91,11 +91,11 @@ const arr = [1, 2, 3]; print("The sum of"); print(arr); print("is"); -print(Deno.core.jsonOpSync('op_sum', arr)); +print(Deno.core.opSync('op_sum', arr)); // And incorrect usage try { - print(Deno.core.jsonOpSync('op_sum', 0)); + print(Deno.core.opSync('op_sum', 0)); } catch(e) { print('Exception:'); print(e); diff --git a/core/examples/http_bench_bin_ops.js b/core/examples/http_bench_bin_ops.js deleted file mode 100644 index c3128dbb20..0000000000 --- a/core/examples/http_bench_bin_ops.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -// This is not a real HTTP server. We read blindly one time into 'requestBuf', -// then write this fixed 'responseBuf'. The point of this benchmark is to -// exercise the event loop in a simple yet semi-realistic way. -const requestBuf = new Uint8Array(64 * 1024); -const responseBuf = new Uint8Array( - "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" - .split("") - .map((c) => c.charCodeAt(0)), -); - -/** Listens on 0.0.0.0:4500, returns rid. */ -function listen() { - return Deno.core.binOpSync("listen", 0); -} - -/** Accepts a connection, returns rid. */ -function accept(rid) { - return Deno.core.binOpAsync("accept", rid); -} - -/** - * Reads a packet from the rid, presumably an http request. data is ignored. - * Returns bytes read. - */ -function read(rid, data) { - return Deno.core.binOpAsync("read", rid, data); -} - -/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */ -function write(rid, data) { - return Deno.core.binOpAsync("write", rid, data); -} - -function close(rid) { - Deno.core.binOpSync("close", rid); -} - -async function serve(rid) { - try { - while (true) { - await read(rid, requestBuf); - await write(rid, responseBuf); - } - } catch (e) { - if ( - !e.message.includes("Broken pipe") && - !e.message.includes("Connection reset by peer") - ) { - throw e; - } - } - close(rid); -} - -async function main() { - Deno.core.ops(); - Deno.core.registerErrorClass("Error", Error); - - const listenerRid = listen(); - Deno.core.print( - `http_bench_bin_ops listening on http://127.0.0.1:4544/\n`, - ); - - while (true) { - const rid = await accept(listenerRid); - serve(rid); - } -} - -main(); diff --git a/core/examples/http_bench_bin_ops.rs b/core/examples/http_bench_bin_ops.rs deleted file mode 100644 index 0ba7b6706b..0000000000 --- a/core/examples/http_bench_bin_ops.rs +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use deno_core::error::bad_resource_id; -use deno_core::error::null_opbuf; -use deno_core::error::AnyError; -use deno_core::AsyncRefCell; -use deno_core::CancelHandle; -use deno_core::CancelTryFuture; -use deno_core::JsRuntime; -use deno_core::OpState; -use deno_core::RcRef; -use deno_core::Resource; -use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::env; -use std::io::Error; -use std::net::SocketAddr; -use std::rc::Rc; -use tokio::io::AsyncReadExt; -use tokio::io::AsyncWriteExt; - -struct Logger; - -impl log::Log for Logger { - fn enabled(&self, metadata: &log::Metadata) -> bool { - metadata.level() <= log::max_level() - } - - fn log(&self, record: &log::Record) { - if self.enabled(record.metadata()) { - println!("{} - {}", record.level(), record.args()); - } - } - - fn flush(&self) {} -} - -// Note: a `tokio::net::TcpListener` doesn't need to be wrapped in a cell, -// because it only supports one op (`accept`) which does not require a mutable -// reference to the listener. -struct TcpListener { - inner: tokio::net::TcpListener, - cancel: CancelHandle, -} - -impl TcpListener { - async fn accept(self: Rc) -> Result { - let cancel = RcRef::map(&self, |r| &r.cancel); - let stream = self.inner.accept().try_or_cancel(cancel).await?.0.into(); - Ok(stream) - } -} - -impl Resource for TcpListener { - fn close(self: Rc) { - self.cancel.cancel(); - } -} - -impl TryFrom for TcpListener { - type Error = Error; - fn try_from( - std_listener: std::net::TcpListener, - ) -> Result { - tokio::net::TcpListener::try_from(std_listener).map(|tokio_listener| Self { - inner: tokio_listener, - cancel: Default::default(), - }) - } -} - -struct TcpStream { - rd: AsyncRefCell, - wr: AsyncRefCell, - // When a `TcpStream` resource is closed, all pending 'read' ops are - // canceled, while 'write' ops are allowed to complete. Therefore only - // 'read' futures are attached to this cancel handle. - cancel: CancelHandle, -} - -impl TcpStream { - async fn read(self: Rc, buf: &mut [u8]) -> Result { - let mut rd = RcRef::map(&self, |r| &r.rd).borrow_mut().await; - let cancel = RcRef::map(self, |r| &r.cancel); - rd.read(buf).try_or_cancel(cancel).await - } - - async fn write(self: Rc, buf: &[u8]) -> Result { - let mut wr = RcRef::map(self, |r| &r.wr).borrow_mut().await; - wr.write(buf).await - } -} - -impl Resource for TcpStream { - fn close(self: Rc) { - self.cancel.cancel() - } -} - -impl From for TcpStream { - fn from(s: tokio::net::TcpStream) -> Self { - let (rd, wr) = s.into_split(); - Self { - rd: rd.into(), - wr: wr.into(), - cancel: Default::default(), - } - } -} - -fn create_js_runtime() -> JsRuntime { - let mut runtime = JsRuntime::new(Default::default()); - runtime.register_op("listen", deno_core::bin_op_sync(op_listen)); - runtime.register_op("close", deno_core::bin_op_sync(op_close)); - runtime.register_op("accept", deno_core::bin_op_async(op_accept)); - runtime.register_op("read", deno_core::bin_op_async(op_read)); - runtime.register_op("write", deno_core::bin_op_async(op_write)); - runtime -} - -fn op_listen( - state: &mut OpState, - _rid: ResourceId, - _bufs: Option, -) -> Result { - log::debug!("listen"); - let addr = "127.0.0.1:4544".parse::().unwrap(); - let std_listener = std::net::TcpListener::bind(&addr)?; - std_listener.set_nonblocking(true)?; - let listener = TcpListener::try_from(std_listener)?; - let rid = state.resource_table.add(listener); - Ok(rid) -} - -fn op_close( - state: &mut OpState, - rid: ResourceId, - _bufs: Option, -) -> Result { - log::debug!("close rid={}", rid); - state - .resource_table - .close(rid) - .map(|_| 0) - .ok_or_else(bad_resource_id) -} - -async fn op_accept( - state: Rc>, - rid: ResourceId, - _bufs: Option, -) -> Result { - log::debug!("accept rid={}", rid); - - let listener = state - .borrow() - .resource_table - .get::(rid) - .ok_or_else(bad_resource_id)?; - let stream = listener.accept().await?; - let rid = state.borrow_mut().resource_table.add(stream); - Ok(rid) -} - -async fn op_read( - state: Rc>, - rid: ResourceId, - buf: Option, -) -> Result { - let mut buf = buf.ok_or_else(null_opbuf)?; - log::debug!("read rid={}", rid); - - let stream = state - .borrow() - .resource_table - .get::(rid) - .ok_or_else(bad_resource_id)?; - let nread = stream.read(&mut buf).await?; - Ok(nread as u32) -} - -async fn op_write( - state: Rc>, - rid: ResourceId, - buf: Option, -) -> Result { - let buf = buf.ok_or_else(null_opbuf)?; - log::debug!("write rid={}", rid); - - let stream = state - .borrow() - .resource_table - .get::(rid) - .ok_or_else(bad_resource_id)?; - let nwritten = stream.write(&buf).await?; - Ok(nwritten as u32) -} - -fn main() { - log::set_logger(&Logger).unwrap(); - log::set_max_level( - env::args() - .find(|a| a == "-D") - .map(|_| log::LevelFilter::Debug) - .unwrap_or(log::LevelFilter::Warn), - ); - - // NOTE: `--help` arg will display V8 help and exit - deno_core::v8_set_flags(env::args().collect()); - - let mut js_runtime = create_js_runtime(); - let runtime = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); - - let future = async move { - js_runtime - .execute( - "http_bench_bin_ops.js", - include_str!("http_bench_bin_ops.js"), - ) - .unwrap(); - js_runtime.run_event_loop().await - }; - runtime.block_on(future).unwrap(); -} diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js index f8ac05353d..687be7ec15 100644 --- a/core/examples/http_bench_json_ops.js +++ b/core/examples/http_bench_json_ops.js @@ -11,12 +11,12 @@ const responseBuf = new Uint8Array( /** Listens on 0.0.0.0:4500, returns rid. */ function listen() { - return Deno.core.jsonOpSync("listen"); + return Deno.core.opSync("listen"); } /** Accepts a connection, returns rid. */ function accept(serverRid) { - return Deno.core.jsonOpAsync("accept", serverRid); + return Deno.core.opAsync("accept", serverRid); } /** @@ -24,16 +24,16 @@ function accept(serverRid) { * Returns bytes read. */ function read(rid, data) { - return Deno.core.jsonOpAsync("read", rid, data); + return Deno.core.opAsync("read", rid, data); } /** Writes a fixed HTTP response to the socket rid. Returns bytes written. */ function write(rid, data) { - return Deno.core.jsonOpAsync("write", rid, data); + return Deno.core.opAsync("write", rid, data); } function close(rid) { - Deno.core.jsonOpSync("close", rid); + Deno.core.opSync("close", rid); } async function serve(rid) { @@ -58,7 +58,7 @@ async function main() { Deno.core.registerErrorClass("Error", Error); const listenerRid = listen(); - Deno.core.print(`http_bench_json_ops listening on http://127.0.0.1:4544/\n`); + Deno.core.print(`http_bench_ops listening on http://127.0.0.1:4544/\n`); while (true) { const rid = await accept(listenerRid); diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index cb3c64945d..e1b435e4ce 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -111,11 +111,11 @@ impl From for TcpStream { fn create_js_runtime() -> JsRuntime { let mut runtime = JsRuntime::new(Default::default()); - runtime.register_op("listen", deno_core::json_op_sync(op_listen)); - runtime.register_op("close", deno_core::json_op_sync(op_close)); - runtime.register_op("accept", deno_core::json_op_async(op_accept)); - runtime.register_op("read", deno_core::json_op_async(op_read)); - runtime.register_op("write", deno_core::json_op_async(op_write)); + runtime.register_op("listen", deno_core::op_sync(op_listen)); + runtime.register_op("close", deno_core::op_sync(op_close)); + 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 } diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts index b12879a9bd..2da28b4134 100644 --- a/core/lib.deno_core.d.ts +++ b/core/lib.deno_core.d.ts @@ -7,15 +7,15 @@ declare namespace Deno { declare namespace core { - /** Send a JSON op to Rust, and synchronously receive the result. */ - function jsonOpSync( + /** Call an op in Rust, and synchronously receive the result. */ + function opSync( opName: string, args?: any, zeroCopy?: Uint8Array, ): any; - /** Send a JSON op to Rust, and asynchronously receive the result. */ - function jsonOpAsync( + /** Call an op in Rust, and asynchronously receive the result. */ + function opAsync( opName: string, args?: any, zeroCopy?: Uint8Array, diff --git a/core/lib.rs b/core/lib.rs index f514110834..b49de3b7b1 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -9,7 +9,6 @@ mod module_specifier; mod modules; mod normalize_path; mod ops; -mod ops_bin; mod ops_json; pub mod plugin_api; mod resources; @@ -65,11 +64,8 @@ pub use crate::ops::OpResponse; pub use crate::ops::OpState; pub use crate::ops::OpTable; pub use crate::ops::PromiseId; -pub use crate::ops_bin::bin_op_async; -pub use crate::ops_bin::bin_op_sync; -pub use crate::ops_bin::ValueOrVector; -pub use crate::ops_json::json_op_async; -pub use crate::ops_json::json_op_sync; +pub use crate::ops_json::op_async; +pub use crate::ops_json::op_sync; pub use crate::resources::Resource; pub use crate::resources::ResourceId; pub use crate::resources::ResourceTable; diff --git a/core/ops.rs b/core/ops.rs index 53aec4ae4d..3cc24c8ccb 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -188,7 +188,7 @@ impl Default for OpTable { /// Return map of resources with id as key /// and string representation as value. /// -/// This op must be wrapped in `json_op_sync`. +/// This op must be wrapped in `op_sync`. pub fn op_resources( state: &mut OpState, _args: (), @@ -204,7 +204,7 @@ pub fn op_resources( /// Remove a resource from the resource table. /// -/// This op must be wrapped in `json_op_sync`. +/// This op must be wrapped in `op_sync`. pub fn op_close( state: &mut OpState, rid: Option, diff --git a/core/ops_bin.rs b/core/ops_bin.rs deleted file mode 100644 index c4c57f4b9a..0000000000 --- a/core/ops_bin.rs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -use crate::error::AnyError; -use crate::futures::future::FutureExt; -use crate::serialize_op_result; -use crate::Op; -use crate::OpFn; -use crate::OpPayload; -use crate::OpResponse; -use crate::OpState; -use crate::ZeroCopyBuf; -use std::boxed::Box; -use std::cell::RefCell; -use std::future::Future; -use std::rc::Rc; - -// TODO: rewrite this, to have consistent buffer returns -// possibly via direct serde_v8 support -pub trait ValueOrVector { - fn value(&self) -> u32; - fn vector(self) -> Option>; -} - -impl ValueOrVector for Vec { - fn value(&self) -> u32 { - self.len() as u32 - } - fn vector(self) -> Option> { - Some(self) - } -} - -impl ValueOrVector for u32 { - fn value(&self) -> u32 { - *self - } - fn vector(self) -> Option> { - None - } -} - -/// Creates an op that passes data synchronously using raw ui8 buffer. -/// -/// The provided function `op_fn` has the following parameters: -/// * `&mut OpState`: the op state, can be used to read/write resources in the runtime from an op. -/// * `argument`: the i32 value that is passed to the Rust function. -/// * `&mut [ZeroCopyBuf]`: raw bytes passed along. -/// -/// `op_fn` returns an array buffer value, which is directly returned to JavaScript. -/// -/// When registering an op like this... -/// ```ignore -/// let mut runtime = JsRuntime::new(...); -/// runtime.register_op("hello", deno_core::bin_op_sync(Self::hello_op)); -/// ``` -/// -/// ...it can be invoked from JS using the provided name, for example: -/// ```js -/// Deno.core.ops(); -/// let result = Deno.core.binOpSync("function_name", args); -/// ``` -/// -/// The `Deno.core.ops()` statement is needed once before any op calls, for initialization. -/// A more complete example is available in the examples directory. -pub fn bin_op_sync(op_fn: F) -> Box -where - F: - Fn(&mut OpState, u32, Option) -> Result + 'static, - R: ValueOrVector, -{ - Box::new(move |state, payload, buf| -> Op { - let min_arg: u32 = payload.deserialize().unwrap(); - let result = op_fn(&mut state.borrow_mut(), min_arg, buf); - Op::Sync(serialize_bin_result(result, state)) - }) -} - -// wraps serialize_op_result but handles ValueOrVector -fn serialize_bin_result( - result: Result, - state: Rc>, -) -> OpResponse -where - R: ValueOrVector, -{ - match result { - Ok(v) => { - let min_val = v.value(); - match v.vector() { - // Warning! this is incorrect, but buffers aren't use ATM, will fix in future PR - Some(vec) => OpResponse::Buffer(vec.into()), - // u32 - None => serialize_op_result(Ok(min_val), state), - } - } - Err(e) => serialize_op_result::<()>(Err(e), state), - } -} - -/// Creates an op that passes data asynchronously using raw ui8 buffer. -/// -/// The provided function `op_fn` has the following parameters: -/// * `Rc>`: the op state, can be used to read/write resources in the runtime from an op. -/// * `argument`: the i32 value that is passed to the Rust function. -/// * `BufVec`: raw bytes passed along, usually not needed if the JSON value is used. -/// -/// `op_fn` returns a future, whose output is a JSON value. This value will be asynchronously -/// returned to JavaScript. -/// -/// When registering an op like this... -/// ```ignore -/// let mut runtime = JsRuntime::new(...); -/// runtime.register_op("hello", deno_core::json_op_async(Self::hello_op)); -/// ``` -/// -/// ...it can be invoked from JS using the provided name, for example: -/// ```js -/// Deno.core.ops(); -/// let future = Deno.core.jsonOpAsync("function_name", args); -/// ``` -/// -/// The `Deno.core.ops()` statement is needed once before any op calls, for initialization. -/// A more complete example is available in the examples directory. -pub fn bin_op_async(op_fn: F) -> Box -where - F: Fn(Rc>, u32, Option) -> R + 'static, - R: Future> + 'static, - RV: ValueOrVector, -{ - Box::new( - move |state: Rc>, - p: OpPayload, - b: Option| - -> Op { - let pid = p.promise_id; - let min_arg: u32 = p.deserialize().unwrap(); - let fut = op_fn(state.clone(), min_arg, b) - .map(move |result| (pid, serialize_bin_result(result, state))); - Op::Async(Box::pin(fut)) - }, - ) -} diff --git a/core/ops_json.rs b/core/ops_json.rs index 3e2b532d00..cf2e6230b3 100644 --- a/core/ops_json.rs +++ b/core/ops_json.rs @@ -25,18 +25,18 @@ use std::rc::Rc; /// When registering an op like this... /// ```ignore /// let mut runtime = JsRuntime::new(...); -/// runtime.register_op("hello", deno_core::json_op_sync(Self::hello_op)); +/// runtime.register_op("hello", deno_core::op_sync(Self::hello_op)); /// ``` /// /// ...it can be invoked from JS using the provided name, for example: /// ```js /// Deno.core.ops(); -/// let result = Deno.core.jsonOpSync("function_name", args); +/// let result = Deno.core.opSync("function_name", args); /// ``` /// /// The `Deno.core.ops()` statement is needed once before any op calls, for initialization. /// A more complete example is available in the examples directory. -pub fn json_op_sync(op_fn: F) -> Box +pub fn op_sync(op_fn: F) -> Box where F: Fn(&mut OpState, V, Option) -> Result + 'static, V: DeserializeOwned, @@ -63,18 +63,18 @@ where /// When registering an op like this... /// ```ignore /// let mut runtime = JsRuntime::new(...); -/// runtime.register_op("hello", deno_core::json_op_async(Self::hello_op)); +/// runtime.register_op("hello", deno_core::op_async(Self::hello_op)); /// ``` /// /// ...it can be invoked from JS using the provided name, for example: /// ```js /// Deno.core.ops(); -/// let future = Deno.core.jsonOpAsync("function_name", args); +/// let future = Deno.core.opAsync("function_name", args); /// ``` /// /// The `Deno.core.ops()` statement is needed once before any op calls, for initialization. /// A more complete example is available in the examples directory. -pub fn json_op_async(op_fn: F) -> Box +pub fn op_async(op_fn: F) -> Box where F: Fn(Rc>, V, Option) -> R + 'static, V: DeserializeOwned, @@ -115,7 +115,7 @@ mod tests { use super::*; #[tokio::test] - async fn json_op_async_stack_trace() { + async fn op_async_stack_trace() { let mut runtime = crate::JsRuntime::new(Default::default()); async fn op_throw( @@ -128,7 +128,7 @@ mod tests { Err(crate::error::generic_error("foo")) } - runtime.register_op("op_throw", json_op_async(op_throw)); + runtime.register_op("op_throw", op_async(op_throw)); runtime .execute( "", @@ -139,7 +139,7 @@ mod tests { Deno.core.registerErrorClass('Error', Error); async function f1() { - await Deno.core.jsonOpAsync('op_throw', 'hello'); + await Deno.core.opAsync('op_throw', 'hello'); } async function f2() { diff --git a/core/runtime.rs b/core/runtime.rs index 28f015fda8..3583ad89ef 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -438,8 +438,8 @@ impl JsRuntime { /// /// This function provides byte-level bindings. To pass data via JSON, the /// following functions can be passed as an argument for `op_fn`: - /// * [json_op_sync()](fn.json_op_sync.html) - /// * [json_op_async()](fn.json_op_async.html) + /// * [op_sync()](fn.op_sync.html) + /// * [op_async()](fn.op_async.html) pub fn register_op(&mut self, name: &str, op_fn: F) -> OpId where F: Fn(Rc>, OpPayload, Option) -> Op + 'static, diff --git a/op_crates/crypto/01_crypto.js b/op_crates/crypto/01_crypto.js index f0cb1d823c..12f4f45ccf 100644 --- a/op_crates/crypto/01_crypto.js +++ b/op_crates/crypto/01_crypto.js @@ -37,7 +37,7 @@ arrayBufferView.byteOffset, arrayBufferView.byteLength, ); - core.jsonOpSync("op_crypto_get_random_values", null, ui8); + core.opSync("op_crypto_get_random_values", null, ui8); return arrayBufferView; } diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js index 0fd825e162..8dc7c2056c 100644 --- a/op_crates/fetch/26_fetch.js +++ b/op_crates/fetch/26_fetch.js @@ -859,7 +859,7 @@ * @returns {HttpClient} */ function createHttpClient(options) { - return new HttpClient(core.jsonOpSync("op_create_http_client", options)); + return new HttpClient(core.opSync("op_create_http_client", options)); } class HttpClient { @@ -884,7 +884,7 @@ if (body != null) { zeroCopy = new Uint8Array(body.buffer, body.byteOffset, body.byteLength); } - return core.jsonOpSync("op_fetch", args, zeroCopy); + return core.opSync("op_fetch", args, zeroCopy); } /** @@ -892,7 +892,7 @@ * @returns {Promise<{status: number, statusText: string, headers: Record, url: string, responseRid: number}>} */ function opFetchSend(rid) { - return core.jsonOpAsync("op_fetch_send", rid); + return core.opAsync("op_fetch_send", rid); } /** @@ -906,7 +906,7 @@ body.byteOffset, body.byteLength, ); - return core.jsonOpAsync("op_fetch_request_write", rid, zeroCopy); + return core.opAsync("op_fetch_request_write", rid, zeroCopy); } const NULL_BODY_STATUS = [101, 204, 205, 304]; @@ -1400,7 +1400,7 @@ async pull(controller) { try { const chunk = new Uint8Array(16 * 1024 + 256); - const read = await core.jsonOpAsync( + const read = await core.opAsync( "op_fetch_response_read", rid, chunk, diff --git a/op_crates/file/03_blob_url.js b/op_crates/file/03_blob_url.js index a3ec904331..570aa43425 100644 --- a/op_crates/file/03_blob_url.js +++ b/op_crates/file/03_blob_url.js @@ -31,7 +31,7 @@ prefix, }); - const url = core.jsonOpSync( + const url = core.opSync( "op_file_create_object_url", blob.type, blob[_byteSequence], @@ -52,7 +52,7 @@ prefix, }); - core.jsonOpSync( + core.opSync( "op_file_revoke_object_url", url, ); diff --git a/op_crates/url/00_url.js b/op_crates/url/00_url.js index bf1ed60592..7c24a871ae 100644 --- a/op_crates/url/00_url.js +++ b/op_crates/url/00_url.js @@ -28,7 +28,7 @@ init = init.slice(1); } - this.#params = core.jsonOpSync("op_url_parse_search_params", init); + this.#params = core.opSync("op_url_parse_search_params", init); } else if ( Array.isArray(init) || typeof init?.[Symbol.iterator] == "function" @@ -64,7 +64,7 @@ return; } const parseArgs = { href: url.href, setSearch: this.toString() }; - parts.set(url, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(url, core.opSync("op_url_parse", parseArgs)); }; append(name, value) { @@ -189,7 +189,7 @@ } toString() { - return core.jsonOpSync("op_url_stringify_search_params", this.#params); + return core.opSync("op_url_stringify_search_params", this.#params); } } @@ -206,7 +206,7 @@ } else { base = base !== undefined ? String(base) : base; const parseArgs = { href: String(url), baseHref: base }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } } @@ -230,7 +230,7 @@ #updateSearchParams = () => { if (this.#searchParams != null) { const params = paramLists.get(this.#searchParams); - const newParams = core.jsonOpSync( + const newParams = core.opSync( "op_url_parse_search_params", this.search.slice(1), ); @@ -245,7 +245,7 @@ set hash(value) { try { const parseArgs = { href: this.href, setHash: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -258,7 +258,7 @@ set host(value) { try { const parseArgs = { href: this.href, setHost: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -271,7 +271,7 @@ set hostname(value) { try { const parseArgs = { href: this.href, setHostname: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -284,7 +284,7 @@ set href(value) { try { const parseArgs = { href: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { throw new TypeError("Invalid URL"); } @@ -302,7 +302,7 @@ set password(value) { try { const parseArgs = { href: this.href, setPassword: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -315,7 +315,7 @@ set pathname(value) { try { const parseArgs = { href: this.href, setPathname: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -328,7 +328,7 @@ set port(value) { try { const parseArgs = { href: this.href, setPort: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -341,7 +341,7 @@ set protocol(value) { try { const parseArgs = { href: this.href, setProtocol: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } @@ -354,7 +354,7 @@ set search(value) { try { const parseArgs = { href: this.href, setSearch: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); this.#updateSearchParams(); } catch { /* pass */ @@ -368,7 +368,7 @@ set username(value) { try { const parseArgs = { href: this.href, setUsername: String(value) }; - parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); + parts.set(this, core.opSync("op_url_parse", parseArgs)); } catch { /* pass */ } diff --git a/op_crates/webgpu/01_webgpu.js b/op_crates/webgpu/01_webgpu.js index 1b790914e7..a02262ccd4 100644 --- a/op_crates/webgpu/01_webgpu.js +++ b/op_crates/webgpu/01_webgpu.js @@ -155,7 +155,7 @@ context: "Argument 1", }); - const { err, ...data } = await core.jsonOpAsync( + const { err, ...data } = await core.opAsync( "op_webgpu_request_adapter", { ...options }, ); @@ -248,7 +248,7 @@ const nonGuaranteedLimits = descriptor.nonGuaranteedLimits ?? []; // TODO(lucacasonato): validate nonGuaranteedLimits - const { rid, features, limits } = await core.jsonOpAsync( + const { rid, features, limits } = await core.opAsync( "op_webgpu_request_device", { adapterRid: this[_adapter].rid, @@ -701,7 +701,7 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_buffer", { + const { rid, err } = core.opSync("op_webgpu_create_buffer", { deviceRid: device.rid, ...descriptor, }); @@ -748,7 +748,7 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_texture", { + const { rid, err } = core.opSync("op_webgpu_create_texture", { deviceRid: device.rid, ...descriptor, size: normalizeGPUExtent3D(descriptor.size), @@ -776,7 +776,7 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_sampler", { + const { rid, err } = core.opSync("op_webgpu_create_sampler", { deviceRid: device.rid, ...descriptor, }); @@ -816,7 +816,7 @@ } } - const { rid, err } = core.jsonOpSync( + const { rid, err } = core.opSync( "op_webgpu_create_bind_group_layout", { deviceRid: device.rid, @@ -859,7 +859,7 @@ return rid; }, ); - const { rid, err } = core.jsonOpSync("op_webgpu_create_pipeline_layout", { + const { rid, err } = core.opSync("op_webgpu_create_pipeline_layout", { deviceRid: device.rid, label: descriptor.label, bindGroupLayouts, @@ -951,7 +951,7 @@ } }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_bind_group", { + const { rid, err } = core.opSync("op_webgpu_create_bind_group", { deviceRid: device.rid, label: descriptor.label, layout, @@ -980,7 +980,7 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync( + const { rid, err } = core.opSync( "op_webgpu_create_shader_module", { deviceRid: device.rid, @@ -1038,7 +1038,7 @@ selfContext: "this", }); - const { rid, err } = core.jsonOpSync( + const { rid, err } = core.opSync( "op_webgpu_create_compute_pipeline", { deviceRid: device.rid, @@ -1111,7 +1111,7 @@ }; } - const { rid, err } = core.jsonOpSync("op_webgpu_create_render_pipeline", { + const { rid, err } = core.opSync("op_webgpu_create_render_pipeline", { deviceRid: device.rid, label: descriptor.label, layout, @@ -1158,7 +1158,7 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_command_encoder", { + const { rid, err } = core.opSync("op_webgpu_create_command_encoder", { deviceRid: device.rid, ...descriptor, }); @@ -1190,7 +1190,7 @@ }, ); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync( + const { rid, err } = core.opSync( "op_webgpu_create_render_bundle_encoder", { deviceRid: device.rid, @@ -1224,7 +1224,7 @@ }, ); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_query_set", { + const { rid, err } = core.opSync("op_webgpu_create_query_set", { deviceRid: device.rid, ...descriptor, }); @@ -1347,7 +1347,7 @@ }); return rid; }); - const { err } = core.jsonOpSync("op_webgpu_queue_submit", { + const { err } = core.opSync("op_webgpu_queue_submit", { queueRid: device.rid, commandBuffers: commandBufferRids, }); @@ -1402,7 +1402,7 @@ selfContext: "this", resourceContext: "Argument 1", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_write_buffer", { queueRid: device.rid, @@ -1452,7 +1452,7 @@ selfContext: "this", resourceContext: "texture", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_write_texture", { queueRid: device.rid, @@ -1652,7 +1652,7 @@ this[_mapMode] = mode; this[_state] = "mapping pending"; - const { err } = await core.jsonOpAsync( + const { err } = await core.opAsync( "op_webgpu_buffer_get_map_async", { bufferRid, @@ -1748,7 +1748,7 @@ } const buffer = new ArrayBuffer(rangeSize); - const { rid } = core.jsonOpSync( + const { rid } = core.opSync( "op_webgpu_buffer_get_mapped_range", { bufferRid, @@ -1805,7 +1805,7 @@ throw new DOMException(`${prefix}: invalid state.`, "OperationError"); } for (const [buffer, mappedRid] of mappedRanges) { - const { err } = core.jsonOpSync("op_webgpu_buffer_unmap", { + const { err } = core.opSync("op_webgpu_buffer_unmap", { bufferRid, mappedRid, }, ...(write ? [new Uint8Array(buffer)] : [])); @@ -1943,7 +1943,7 @@ }); const device = assertDevice(this, { prefix, context: "this" }); const textureRid = assertResource(this, { prefix, context: "this" }); - const { rid, err } = core.jsonOpSync("op_webgpu_create_texture_view", { + const { rid, err } = core.opSync("op_webgpu_create_texture_view", { textureRid, ...descriptor, }); @@ -2328,7 +2328,7 @@ prefix, context: "this", }); - const { rid, label, err } = core.jsonOpSync( + const { rid, label, err } = core.opSync( "op_webgpu_compute_pipeline_get_bind_group_layout", { computePipelineRid, index }, ); @@ -2403,7 +2403,7 @@ prefix, context: "this", }); - const { rid, label, err } = core.jsonOpSync( + const { rid, label, err } = core.opSync( "op_webgpu_render_pipeline_get_bind_group_layout", { renderPipelineRid, index }, ); @@ -2628,7 +2628,7 @@ }, ); - const { rid } = core.jsonOpSync( + const { rid } = core.opSync( "op_webgpu_command_encoder_begin_render_pass", { commandEncoderRid, @@ -2665,7 +2665,7 @@ context: "this", }); - const { rid } = core.jsonOpSync( + const { rid } = core.opSync( "op_webgpu_command_encoder_begin_compute_pass", { commandEncoderRid, @@ -2744,7 +2744,7 @@ selfContext: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_copy_buffer_to_buffer", { commandEncoderRid, @@ -2804,7 +2804,7 @@ selfContext: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_copy_buffer_to_texture", { commandEncoderRid, @@ -2870,7 +2870,7 @@ resourceContext: "buffer in Argument 2", selfContext: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_copy_texture_to_buffer", { commandEncoderRid, @@ -2936,7 +2936,7 @@ resourceContext: "texture in Argument 2", selfContext: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_copy_texture_to_texture", { commandEncoderRid, @@ -2977,7 +2977,7 @@ prefix, context: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_push_debug_group", { commandEncoderRid, @@ -2995,7 +2995,7 @@ prefix, context: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_pop_debug_group", { commandEncoderRid, @@ -3021,7 +3021,7 @@ prefix, context: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_insert_debug_marker", { commandEncoderRid, @@ -3062,7 +3062,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_write_timestamp", { commandEncoderRid, @@ -3134,7 +3134,7 @@ resourceContext: "Argument 3", selfContext: "this", }); - const { err } = core.jsonOpSync( + const { err } = core.opSync( "op_webgpu_command_encoder_resolve_query_set", { commandEncoderRid, @@ -3164,7 +3164,7 @@ prefix, context: "this", }); - const { rid, err } = core.jsonOpSync("op_webgpu_command_encoder_finish", { + const { rid, err } = core.opSync("op_webgpu_command_encoder_finish", { commandEncoderRid, ...descriptor, }); @@ -3264,7 +3264,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_set_viewport", { + core.opSync("op_webgpu_render_pass_set_viewport", { renderPassRid, x, y, @@ -3312,7 +3312,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_set_scissor_rect", { + core.opSync("op_webgpu_render_pass_set_scissor_rect", { renderPassRid, x, y, @@ -3342,7 +3342,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_set_blend_color", { + core.opSync("op_webgpu_render_pass_set_blend_color", { renderPassRid, color: normalizeGPUColor(color), }); @@ -3369,7 +3369,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_set_stencil_reference", { + core.opSync("op_webgpu_render_pass_set_stencil_reference", { renderPassRid, reference, }); @@ -3418,7 +3418,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_begin_pipeline_statistics_query", { + core.opSync("op_webgpu_render_pass_begin_pipeline_statistics_query", { renderPassRid, querySet: querySetRid, queryIndex, @@ -3438,7 +3438,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_end_pipeline_statistics_query", { + core.opSync("op_webgpu_render_pass_end_pipeline_statistics_query", { renderPassRid, }); } @@ -3478,7 +3478,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_write_timestamp", { + core.opSync("op_webgpu_render_pass_write_timestamp", { renderPassRid, querySet: querySetRid, queryIndex, @@ -3516,7 +3516,7 @@ }); return rid; }); - core.jsonOpSync("op_webgpu_render_pass_execute_bundles", { + core.opSync("op_webgpu_render_pass_execute_bundles", { renderPassRid, bundles: bundleRids, }); @@ -3534,7 +3534,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - const { err } = core.jsonOpSync("op_webgpu_render_pass_end_pass", { + const { err } = core.opSync("op_webgpu_render_pass_end_pass", { commandEncoderRid, renderPassRid, }); @@ -3572,7 +3572,7 @@ selfContext: "this", }); if (dynamicOffsetsData instanceof Uint32Array) { - core.jsonOpSync( + core.opSync( "op_webgpu_render_pass_set_bind_group", { renderPassRid, @@ -3585,7 +3585,7 @@ ); } else { dynamicOffsetsData ??= []; - core.jsonOpSync("op_webgpu_render_pass_set_bind_group", { + core.opSync("op_webgpu_render_pass_set_bind_group", { renderPassRid, index, bindGroup: bindGroupRid, @@ -3617,7 +3617,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_push_debug_group", { + core.opSync("op_webgpu_render_pass_push_debug_group", { renderPassRid, groupLabel, }); @@ -3636,7 +3636,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_pop_debug_group", { + core.opSync("op_webgpu_render_pass_pop_debug_group", { renderPassRid, }); } @@ -3662,7 +3662,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_insert_debug_marker", { + core.opSync("op_webgpu_render_pass_insert_debug_marker", { renderPassRid, markerLabel, }); @@ -3698,7 +3698,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_set_pipeline", { + core.opSync("op_webgpu_render_pass_set_pipeline", { renderPassRid, pipeline: pipelineRid, }); @@ -3749,7 +3749,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_set_index_buffer", { + core.opSync("op_webgpu_render_pass_set_index_buffer", { renderPassRid, buffer: bufferRid, indexFormat, @@ -3803,7 +3803,7 @@ resourceContext: "Argument 2", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_set_vertex_buffer", { + core.opSync("op_webgpu_render_pass_set_vertex_buffer", { renderPassRid, slot, buffer: bufferRid, @@ -3847,7 +3847,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_draw", { + core.opSync("op_webgpu_render_pass_draw", { renderPassRid, vertexCount, instanceCount, @@ -3903,7 +3903,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_render_pass_draw_indexed", { + core.opSync("op_webgpu_render_pass_draw_indexed", { renderPassRid, indexCount, instanceCount, @@ -3948,7 +3948,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_draw_indirect", { + core.opSync("op_webgpu_render_pass_draw_indirect", { renderPassRid, indirectBuffer: indirectBufferRid, indirectOffset, @@ -3990,7 +3990,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_pass_draw_indexed_indirect", { + core.opSync("op_webgpu_render_pass_draw_indexed_indirect", { renderPassRid, indirectBuffer: indirectBufferRid, indirectOffset, @@ -4072,7 +4072,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_compute_pass_set_pipeline", { + core.opSync("op_webgpu_compute_pass_set_pipeline", { computePassRid, pipeline: pipelineRid, }); @@ -4099,7 +4099,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_compute_pass_dispatch", { + core.opSync("op_webgpu_compute_pass_dispatch", { computePassRid, x, y, @@ -4142,7 +4142,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_compute_pass_dispatch_indirect", { + core.opSync("op_webgpu_compute_pass_dispatch_indirect", { computePassRid: computePassRid, indirectBuffer: indirectBufferRid, indirectOffset, @@ -4184,7 +4184,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync( + core.opSync( "op_webgpu_compute_pass_begin_pipeline_statistics_query", { computePassRid, @@ -4207,7 +4207,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_compute_pass_end_pipeline_statistics_query", { + core.opSync("op_webgpu_compute_pass_end_pipeline_statistics_query", { computePassRid, }); } @@ -4247,7 +4247,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_compute_pass_write_timestamp", { + core.opSync("op_webgpu_compute_pass_write_timestamp", { computePassRid, querySet: querySetRid, queryIndex, @@ -4266,7 +4266,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - const { err } = core.jsonOpSync("op_webgpu_compute_pass_end_pass", { + const { err } = core.opSync("op_webgpu_compute_pass_end_pass", { commandEncoderRid, computePassRid, }); @@ -4304,7 +4304,7 @@ selfContext: "this", }); if (dynamicOffsetsData instanceof Uint32Array) { - core.jsonOpSync( + core.opSync( "op_webgpu_compute_pass_set_bind_group", { computePassRid, @@ -4317,7 +4317,7 @@ ); } else { dynamicOffsetsData ??= []; - core.jsonOpSync("op_webgpu_compute_pass_set_bind_group", { + core.opSync("op_webgpu_compute_pass_set_bind_group", { computePassRid, index, bindGroup: bindGroupRid, @@ -4349,7 +4349,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_compute_pass_push_debug_group", { + core.opSync("op_webgpu_compute_pass_push_debug_group", { computePassRid, groupLabel, }); @@ -4368,7 +4368,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_compute_pass_pop_debug_group", { + core.opSync("op_webgpu_compute_pass_pop_debug_group", { computePassRid, }); } @@ -4394,7 +4394,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.jsonOpSync("op_webgpu_compute_pass_insert_debug_marker", { + core.opSync("op_webgpu_compute_pass_insert_debug_marker", { computePassRid, markerLabel, }); @@ -4508,7 +4508,7 @@ prefix, context: "this", }); - const { rid, err } = core.jsonOpSync( + const { rid, err } = core.opSync( "op_webgpu_render_bundle_encoder_finish", { renderBundleEncoderRid, @@ -4553,7 +4553,7 @@ selfContext: "this", }); if (dynamicOffsetsData instanceof Uint32Array) { - core.jsonOpSync( + core.opSync( "op_webgpu_render_bundle_encoder_set_bind_group", { renderBundleEncoderRid, @@ -4566,7 +4566,7 @@ ); } else { dynamicOffsetsData ??= []; - core.jsonOpSync("op_webgpu_render_bundle_encoder_set_bind_group", { + core.opSync("op_webgpu_render_bundle_encoder_set_bind_group", { renderBundleEncoderRid, index, bindGroup: bindGroupRid, @@ -4594,7 +4594,7 @@ prefix, context: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_push_debug_group", { + core.opSync("op_webgpu_render_bundle_encoder_push_debug_group", { renderBundleEncoderRid, groupLabel, }); @@ -4609,7 +4609,7 @@ prefix, context: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_pop_debug_group", { + core.opSync("op_webgpu_render_bundle_encoder_pop_debug_group", { renderBundleEncoderRid, }); } @@ -4631,7 +4631,7 @@ prefix, context: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_push_debug_group", { + core.opSync("op_webgpu_render_bundle_encoder_push_debug_group", { renderBundleEncoderRid, markerLabel, }); @@ -4663,7 +4663,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_set_pipeline", { + core.opSync("op_webgpu_render_bundle_encoder_set_pipeline", { renderBundleEncoderRid, pipeline: pipelineRid, }); @@ -4710,7 +4710,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_set_index_buffer", { + core.opSync("op_webgpu_render_bundle_encoder_set_index_buffer", { renderBundleEncoderRid, buffer: bufferRid, indexFormat, @@ -4760,7 +4760,7 @@ resourceContext: "Argument 2", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_set_vertex_buffer", { + core.opSync("op_webgpu_render_bundle_encoder_set_vertex_buffer", { renderBundleEncoderRid, slot, buffer: bufferRid, @@ -4800,7 +4800,7 @@ prefix, context: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_draw", { + core.opSync("op_webgpu_render_bundle_encoder_draw", { renderBundleEncoderRid, vertexCount, instanceCount, @@ -4852,7 +4852,7 @@ prefix, context: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_draw_indexed", { + core.opSync("op_webgpu_render_bundle_encoder_draw_indexed", { renderBundleEncoderRid, indexCount, instanceCount, @@ -4893,7 +4893,7 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.jsonOpSync("op_webgpu_render_bundle_encoder_draw_indirect", { + core.opSync("op_webgpu_render_bundle_encoder_draw_indirect", { renderBundleEncoderRid, indirectBuffer: indirectBufferRid, indirectOffset, diff --git a/op_crates/websocket/01_websocket.js b/op_crates/websocket/01_websocket.js index 60fd7d4672..17ba601a28 100644 --- a/op_crates/websocket/01_websocket.js +++ b/op_crates/websocket/01_websocket.js @@ -99,7 +99,7 @@ this.#url = wsURL.href; - core.jsonOpSync("op_ws_check_permission", this.#url); + core.opSync("op_ws_check_permission", this.#url); if (protocols && typeof protocols === "string") { protocols = [protocols]; @@ -114,7 +114,7 @@ ); } - core.jsonOpAsync("op_ws_create", { + core.opAsync("op_ws_create", { url: wsURL.href, protocols: protocols.join(", "), }).then((create) => { @@ -124,7 +124,7 @@ this.#protocol = create.protocol; if (this.#readyState === CLOSING) { - core.jsonOpAsync("op_ws_close", { + core.opAsync("op_ws_close", { rid: this.#rid, }).then(() => { this.#readyState = CLOSED; @@ -229,7 +229,7 @@ const sendTypedArray = (ta) => { this.#bufferedAmount += ta.size; - core.jsonOpAsync("op_ws_send", { + core.opAsync("op_ws_send", { rid: this.#rid, kind: "binary", }, ta).then(() => { @@ -256,7 +256,7 @@ const encoder = new TextEncoder(); const d = encoder.encode(string); this.#bufferedAmount += d.size; - core.jsonOpAsync("op_ws_send", { + core.opAsync("op_ws_send", { rid: this.#rid, kind: "text", text: string, @@ -287,7 +287,7 @@ } else if (this.#readyState === OPEN) { this.#readyState = CLOSING; - core.jsonOpAsync("op_ws_close", { + core.opAsync("op_ws_close", { rid: this.#rid, code, reason, @@ -307,7 +307,7 @@ async #eventLoop() { while (this.#readyState === OPEN) { - const message = await core.jsonOpAsync( + const message = await core.opAsync( "op_ws_next_event", this.#rid, ); @@ -344,7 +344,7 @@ } case "ping": - core.jsonOpAsync("op_ws_send", { + core.opAsync("op_ws_send", { rid: this.#rid, kind: "pong", }); diff --git a/runtime/js/11_timers.js b/runtime/js/11_timers.js index eef1d39b29..cfd9ad72d2 100644 --- a/runtime/js/11_timers.js +++ b/runtime/js/11_timers.js @@ -6,23 +6,23 @@ const core = window.Deno.core; function opStopGlobalTimer() { - core.jsonOpSync("op_global_timer_stop"); + core.opSync("op_global_timer_stop"); } function opStartGlobalTimer(timeout) { - return core.jsonOpSync("op_global_timer_start", timeout); + return core.opSync("op_global_timer_start", timeout); } async function opWaitGlobalTimer() { - await core.jsonOpAsync("op_global_timer"); + await core.opAsync("op_global_timer"); } function opNow() { - return core.jsonOpSync("op_now"); + return core.opSync("op_now"); } function sleepSync(millis = 0) { - return core.jsonOpSync("op_sleep_sync", millis); + return core.opSync("op_sleep_sync", millis); } // Derived from https://github.com/vadimg/js_bintrees. MIT Licensed. diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js index b111957132..2c602ab606 100644 --- a/runtime/js/11_workers.js +++ b/runtime/js/11_workers.js @@ -17,7 +17,7 @@ permissions, name, ) { - return core.jsonOpSync("op_create_worker", { + return core.opSync("op_create_worker", { hasSourceCode, name, permissions, @@ -28,15 +28,15 @@ } function hostTerminateWorker(id) { - core.jsonOpSync("op_host_terminate_worker", id); + core.opSync("op_host_terminate_worker", id); } function hostPostMessage(id, data) { - core.jsonOpSync("op_host_post_message", id, data); + core.opSync("op_host_post_message", id, data); } function hostGetMessage(id) { - return core.jsonOpAsync("op_host_get_message", id); + return core.opAsync("op_host_get_message", id); } const encoder = new TextEncoder(); @@ -268,7 +268,7 @@ if (globalThis instanceof Window) { throw new Error("Unhandled error event reached main worker."); } else { - core.jsonOpSync( + core.opSync( "op_host_unhandled_error", event.error.message, ); @@ -287,7 +287,7 @@ if (globalThis instanceof Window) { throw new Error("Unhandled error event reached main worker."); } else { - core.jsonOpSync( + core.opSync( "op_host_unhandled_error", event.error.message, ); diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js index a6b6aeebdb..8df3de92fb 100644 --- a/runtime/js/12_io.js +++ b/runtime/js/12_io.js @@ -81,7 +81,7 @@ return 0; } - const nread = core.binOpSync("op_read_sync", rid, buffer); + const nread = core.opSync("op_read_sync", rid, buffer); return nread === 0 ? null : nread; } @@ -94,17 +94,17 @@ return 0; } - const nread = await core.binOpAsync("op_read_async", rid, buffer); + const nread = await core.opAsync("op_read_async", rid, buffer); return nread === 0 ? null : nread; } function writeSync(rid, data) { - return core.binOpSync("op_write_sync", rid, data); + return core.opSync("op_write_sync", rid, data); } async function write(rid, data) { - return await core.binOpAsync("op_write_async", rid, data); + return await core.opAsync("op_write_async", rid, data); } const READ_PER_ITER = 32 * 1024; diff --git a/runtime/js/30_fs.js b/runtime/js/30_fs.js index af2aebd3ec..72126e6bbb 100644 --- a/runtime/js/30_fs.js +++ b/runtime/js/30_fs.js @@ -7,11 +7,11 @@ const build = window.__bootstrap.build.build; function chmodSync(path, mode) { - core.jsonOpSync("op_chmod_sync", { path: pathFromURL(path), mode }); + core.opSync("op_chmod_sync", { path: pathFromURL(path), mode }); } async function chmod(path, mode) { - await core.jsonOpAsync("op_chmod_async", { path: pathFromURL(path), mode }); + await core.opAsync("op_chmod_async", { path: pathFromURL(path), mode }); } function chownSync( @@ -19,7 +19,7 @@ uid, gid, ) { - core.jsonOpSync("op_chown_sync", { path: pathFromURL(path), uid, gid }); + core.opSync("op_chown_sync", { path: pathFromURL(path), uid, gid }); } async function chown( @@ -27,7 +27,7 @@ uid, gid, ) { - await core.jsonOpAsync( + await core.opAsync( "op_chown_async", { path: pathFromURL(path), uid, gid }, ); @@ -37,7 +37,7 @@ fromPath, toPath, ) { - core.jsonOpSync("op_copy_file_sync", { + core.opSync("op_copy_file_sync", { from: pathFromURL(fromPath), to: pathFromURL(toPath), }); @@ -47,34 +47,34 @@ fromPath, toPath, ) { - await core.jsonOpAsync("op_copy_file_async", { + await core.opAsync("op_copy_file_async", { from: pathFromURL(fromPath), to: pathFromURL(toPath), }); } function cwd() { - return core.jsonOpSync("op_cwd"); + return core.opSync("op_cwd"); } function chdir(directory) { - core.jsonOpSync("op_chdir", directory); + core.opSync("op_chdir", directory); } function makeTempDirSync(options = {}) { - return core.jsonOpSync("op_make_temp_dir_sync", options); + return core.opSync("op_make_temp_dir_sync", options); } function makeTempDir(options = {}) { - return core.jsonOpAsync("op_make_temp_dir_async", options); + return core.opAsync("op_make_temp_dir_async", options); } function makeTempFileSync(options = {}) { - return core.jsonOpSync("op_make_temp_file_sync", options); + return core.opSync("op_make_temp_file_sync", options); } function makeTempFile(options = {}) { - return core.jsonOpAsync("op_make_temp_file_async", options); + return core.opAsync("op_make_temp_file_async", options); } function mkdirArgs(path, options) { @@ -91,24 +91,24 @@ } function mkdirSync(path, options) { - core.jsonOpSync("op_mkdir_sync", mkdirArgs(path, options)); + core.opSync("op_mkdir_sync", mkdirArgs(path, options)); } async function mkdir( path, options, ) { - await core.jsonOpAsync("op_mkdir_async", mkdirArgs(path, options)); + await core.opAsync("op_mkdir_async", mkdirArgs(path, options)); } function readDirSync(path) { - return core.jsonOpSync("op_read_dir_sync", pathFromURL(path))[ + return core.opSync("op_read_dir_sync", pathFromURL(path))[ Symbol.iterator ](); } function readDir(path) { - const array = core.jsonOpAsync( + const array = core.opAsync( "op_read_dir_async", pathFromURL(path), ); @@ -120,26 +120,26 @@ } function readLinkSync(path) { - return core.jsonOpSync("op_read_link_sync", pathFromURL(path)); + return core.opSync("op_read_link_sync", pathFromURL(path)); } function readLink(path) { - return core.jsonOpAsync("op_read_link_async", pathFromURL(path)); + return core.opAsync("op_read_link_async", pathFromURL(path)); } function realPathSync(path) { - return core.jsonOpSync("op_realpath_sync", path); + return core.opSync("op_realpath_sync", path); } function realPath(path) { - return core.jsonOpAsync("op_realpath_async", path); + return core.opAsync("op_realpath_async", path); } function removeSync( path, options = {}, ) { - core.jsonOpSync("op_remove_sync", { + core.opSync("op_remove_sync", { path: pathFromURL(path), recursive: !!options.recursive, }); @@ -149,18 +149,18 @@ path, options = {}, ) { - await core.jsonOpAsync("op_remove_async", { + await core.opAsync("op_remove_async", { path: pathFromURL(path), recursive: !!options.recursive, }); } function renameSync(oldpath, newpath) { - core.jsonOpSync("op_rename_sync", { oldpath, newpath }); + core.opSync("op_rename_sync", { oldpath, newpath }); } async function rename(oldpath, newpath) { - await core.jsonOpAsync("op_rename_async", { oldpath, newpath }); + await core.opAsync("op_rename_async", { oldpath, newpath }); } function parseFileInfo(response) { @@ -189,15 +189,15 @@ } function fstatSync(rid) { - return parseFileInfo(core.jsonOpSync("op_fstat_sync", rid)); + return parseFileInfo(core.opSync("op_fstat_sync", rid)); } async function fstat(rid) { - return parseFileInfo(await core.jsonOpAsync("op_fstat_async", rid)); + return parseFileInfo(await core.opAsync("op_fstat_async", rid)); } async function lstat(path) { - const res = await core.jsonOpAsync("op_stat_async", { + const res = await core.opAsync("op_stat_async", { path: pathFromURL(path), lstat: true, }); @@ -205,7 +205,7 @@ } function lstatSync(path) { - const res = core.jsonOpSync("op_stat_sync", { + const res = core.opSync("op_stat_sync", { path: pathFromURL(path), lstat: true, }); @@ -213,7 +213,7 @@ } async function stat(path) { - const res = await core.jsonOpAsync("op_stat_async", { + const res = await core.opAsync("op_stat_async", { path: pathFromURL(path), lstat: false, }); @@ -221,7 +221,7 @@ } function statSync(path) { - const res = core.jsonOpSync("op_stat_sync", { + const res = core.opSync("op_stat_sync", { path: pathFromURL(path), lstat: false, }); @@ -237,31 +237,31 @@ } function ftruncateSync(rid, len) { - core.jsonOpSync("op_ftruncate_sync", { rid, len: coerceLen(len) }); + core.opSync("op_ftruncate_sync", { rid, len: coerceLen(len) }); } async function ftruncate(rid, len) { - await core.jsonOpAsync("op_ftruncate_async", { rid, len: coerceLen(len) }); + await core.opAsync("op_ftruncate_async", { rid, len: coerceLen(len) }); } function truncateSync(path, len) { - core.jsonOpSync("op_truncate_sync", { path, len: coerceLen(len) }); + core.opSync("op_truncate_sync", { path, len: coerceLen(len) }); } async function truncate(path, len) { - await core.jsonOpAsync("op_truncate_async", { path, len: coerceLen(len) }); + await core.opAsync("op_truncate_async", { path, len: coerceLen(len) }); } function umask(mask) { - return core.jsonOpSync("op_umask", mask); + return core.opSync("op_umask", mask); } function linkSync(oldpath, newpath) { - core.jsonOpSync("op_link_sync", { oldpath, newpath }); + core.opSync("op_link_sync", { oldpath, newpath }); } async function link(oldpath, newpath) { - await core.jsonOpAsync("op_link_async", { oldpath, newpath }); + await core.opAsync("op_link_async", { oldpath, newpath }); } function toUnixTimeFromEpoch(value) { @@ -290,7 +290,7 @@ atime, mtime, ) { - core.jsonOpSync("op_futime_sync", { + core.opSync("op_futime_sync", { rid, atime: toUnixTimeFromEpoch(atime), mtime: toUnixTimeFromEpoch(mtime), @@ -302,7 +302,7 @@ atime, mtime, ) { - await core.jsonOpAsync("op_futime_async", { + await core.opAsync("op_futime_async", { rid, atime: toUnixTimeFromEpoch(atime), mtime: toUnixTimeFromEpoch(mtime), @@ -314,7 +314,7 @@ atime, mtime, ) { - core.jsonOpSync("op_utime_sync", { + core.opSync("op_utime_sync", { path, atime: toUnixTimeFromEpoch(atime), mtime: toUnixTimeFromEpoch(mtime), @@ -326,7 +326,7 @@ atime, mtime, ) { - await core.jsonOpAsync("op_utime_async", { + await core.opAsync("op_utime_async", { path, atime: toUnixTimeFromEpoch(atime), mtime: toUnixTimeFromEpoch(mtime), @@ -338,7 +338,7 @@ newpath, options, ) { - core.jsonOpSync("op_symlink_sync", { oldpath, newpath, options }); + core.opSync("op_symlink_sync", { oldpath, newpath, options }); } async function symlink( @@ -346,23 +346,23 @@ newpath, options, ) { - await core.jsonOpAsync("op_symlink_async", { oldpath, newpath, options }); + await core.opAsync("op_symlink_async", { oldpath, newpath, options }); } function fdatasyncSync(rid) { - core.jsonOpSync("op_fdatasync_sync", rid); + core.opSync("op_fdatasync_sync", rid); } async function fdatasync(rid) { - await core.jsonOpAsync("op_fdatasync_async", rid); + await core.opAsync("op_fdatasync_async", rid); } function fsyncSync(rid) { - core.jsonOpSync("op_fsync_sync", rid); + core.opSync("op_fsync_sync", rid); } async function fsync(rid) { - await core.jsonOpAsync("op_fsync_async", rid); + await core.opAsync("op_fsync_async", rid); } window.__bootstrap.fs = { diff --git a/runtime/js/30_metrics.js b/runtime/js/30_metrics.js index ed062fce38..ecc1cfc64e 100644 --- a/runtime/js/30_metrics.js +++ b/runtime/js/30_metrics.js @@ -5,7 +5,7 @@ const core = window.Deno.core; function metrics() { - const { combined, ops } = core.jsonOpSync("op_metrics"); + const { combined, ops } = core.opSync("op_metrics"); if (ops) { combined.ops = ops; } diff --git a/runtime/js/30_net.js b/runtime/js/30_net.js index 56fb94f26b..2d4b1e48e5 100644 --- a/runtime/js/30_net.js +++ b/runtime/js/30_net.js @@ -7,23 +7,23 @@ const { read, write } = window.__bootstrap.io; function shutdown(rid) { - return core.jsonOpAsync("op_shutdown", rid); + return core.opAsync("op_shutdown", rid); } function opAccept(rid, transport) { - return core.jsonOpAsync("op_accept", { rid, transport }); + return core.opAsync("op_accept", { rid, transport }); } function opListen(args) { - return core.jsonOpSync("op_listen", args); + return core.opSync("op_listen", args); } function opConnect(args) { - return core.jsonOpAsync("op_connect", args); + return core.opAsync("op_connect", args); } function opReceive(rid, transport, zeroCopy) { - return core.jsonOpAsync( + return core.opAsync( "op_datagram_receive", { rid, transport }, zeroCopy, @@ -31,11 +31,11 @@ } function opSend(args, zeroCopy) { - return core.jsonOpAsync("op_datagram_send", args, zeroCopy); + return core.opAsync("op_datagram_send", args, zeroCopy); } function resolveDns(query, recordType, options) { - return core.jsonOpAsync("op_dns_resolve", { query, recordType, options }); + return core.opAsync("op_dns_resolve", { query, recordType, options }); } class Conn { diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js index 0ce8317751..2d11d6fde5 100644 --- a/runtime/js/30_os.js +++ b/runtime/js/30_os.js @@ -5,23 +5,23 @@ const core = window.Deno.core; function loadavg() { - return core.jsonOpSync("op_loadavg"); + return core.opSync("op_loadavg"); } function hostname() { - return core.jsonOpSync("op_hostname"); + return core.opSync("op_hostname"); } function osRelease() { - return core.jsonOpSync("op_os_release"); + return core.opSync("op_os_release"); } function systemMemoryInfo() { - return core.jsonOpSync("op_system_memory_info"); + return core.opSync("op_system_memory_info"); } function systemCpuInfo() { - const { cores, speed } = core.jsonOpSync("op_system_cpu_info"); + const { cores, speed } = core.opSync("op_system_cpu_info"); // Map nulls to undefined for compatibility return { cores: cores ?? undefined, @@ -49,33 +49,33 @@ return; } - core.jsonOpSync("op_exit", code); + core.opSync("op_exit", code); throw new Error("Code not reachable"); } function setEnv(key, value) { - core.jsonOpSync("op_set_env", { key, value }); + core.opSync("op_set_env", { key, value }); } function getEnv(key) { - return core.jsonOpSync("op_get_env", key) ?? undefined; + return core.opSync("op_get_env", key) ?? undefined; } function deleteEnv(key) { - core.jsonOpSync("op_delete_env", key); + core.opSync("op_delete_env", key); } const env = { get: getEnv, toObject() { - return core.jsonOpSync("op_env"); + return core.opSync("op_env"); }, set: setEnv, delete: deleteEnv, }; function execPath() { - return core.jsonOpSync("op_exec_path"); + return core.opSync("op_exec_path"); } window.__bootstrap.os = { diff --git a/runtime/js/40_compiler_api.js b/runtime/js/40_compiler_api.js index cce12f2f8e..b30ffc5d52 100644 --- a/runtime/js/40_compiler_api.js +++ b/runtime/js/40_compiler_api.js @@ -39,7 +39,7 @@ * @returns {Promise} */ function opEmit(request) { - return core.jsonOpAsync("op_emit", request); + return core.opAsync("op_emit", request); } /** diff --git a/runtime/js/40_error_stack.js b/runtime/js/40_error_stack.js index 9bc6567a05..e739750440 100644 --- a/runtime/js/40_error_stack.js +++ b/runtime/js/40_error_stack.js @@ -5,11 +5,11 @@ const core = window.Deno.core; function opFormatDiagnostics(diagnostics) { - return core.jsonOpSync("op_format_diagnostic", diagnostics); + return core.opSync("op_format_diagnostic", diagnostics); } function opApplySourceMap(location) { - const res = core.jsonOpSync("op_apply_source_map", location); + const res = core.opSync("op_apply_source_map", location); return { fileName: res.fileName, lineNumber: res.lineNumber, diff --git a/runtime/js/40_files.js b/runtime/js/40_files.js index d552b4ba50..82cf19ffc2 100644 --- a/runtime/js/40_files.js +++ b/runtime/js/40_files.js @@ -12,7 +12,7 @@ offset, whence, ) { - return core.jsonOpSync("op_seek_sync", { rid, offset, whence }); + return core.opSync("op_seek_sync", { rid, offset, whence }); } function seek( @@ -20,7 +20,7 @@ offset, whence, ) { - return core.jsonOpAsync("op_seek_async", { rid, offset, whence }); + return core.opAsync("op_seek_async", { rid, offset, whence }); } function openSync( @@ -29,7 +29,7 @@ ) { checkOpenOptions(options); const mode = options?.mode; - const rid = core.jsonOpSync( + const rid = core.opSync( "op_open_sync", { path: pathFromURL(path), options, mode }, ); @@ -43,7 +43,7 @@ ) { checkOpenOptions(options); const mode = options?.mode; - const rid = await core.jsonOpAsync( + const rid = await core.opAsync( "op_open_async", { path: pathFromURL(path), options, mode }, ); diff --git a/runtime/js/40_fs_events.js b/runtime/js/40_fs_events.js index 06ad3a29cf..a1a9877b42 100644 --- a/runtime/js/40_fs_events.js +++ b/runtime/js/40_fs_events.js @@ -10,7 +10,7 @@ constructor(paths, options) { const { recursive } = options; - this.#rid = core.jsonOpSync("op_fs_events_open", { recursive, paths }); + this.#rid = core.opSync("op_fs_events_open", { recursive, paths }); } get rid() { @@ -19,7 +19,7 @@ async next() { try { - const value = await core.jsonOpAsync("op_fs_events_poll", this.rid); + const value = await core.opAsync("op_fs_events_poll", this.rid); return value ? { value, done: false } : { value: undefined, done: true }; diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js index d9dff7b528..4a2dcdf4a3 100644 --- a/runtime/js/40_http.js +++ b/runtime/js/40_http.js @@ -10,7 +10,7 @@ const { ReadableStream } = window.__bootstrap.streams; function serveHttp(conn) { - const rid = Deno.core.jsonOpSync("op_http_start", conn.rid); + const rid = Deno.core.opSync("op_http_start", conn.rid); return new HttpConn(rid); } @@ -30,7 +30,7 @@ async nextRequest() { let nextRequest; try { - nextRequest = await Deno.core.jsonOpAsync( + nextRequest = await Deno.core.opAsync( "op_http_request_next", this.#rid, ); @@ -88,7 +88,7 @@ } function readRequest(requestRid, zeroCopyBuf) { - return Deno.core.jsonOpAsync( + return Deno.core.opAsync( "op_http_request_read", requestRid, zeroCopyBuf, @@ -129,7 +129,7 @@ zeroCopyBuf = null; } - const responseBodyRid = Deno.core.jsonOpSync("op_http_response", [ + const responseBodyRid = Deno.core.opSync("op_http_response", [ responseSenderRid, resp.status ?? 200, flattenHeaders(resp.headers), @@ -149,7 +149,7 @@ chunk.byteOffset, chunk.byteLength, ); - await Deno.core.jsonOpAsync( + await Deno.core.opAsync( "op_http_response_write", responseBodyRid, data, @@ -158,7 +158,7 @@ // Once all chunks are sent, and the request body is closed, we can close // the response body. - await Deno.core.jsonOpAsync("op_http_response_close", responseBodyRid); + await Deno.core.opAsync("op_http_response_close", responseBodyRid); } }; } diff --git a/runtime/js/40_permissions.js b/runtime/js/40_permissions.js index 7a81ca4251..dd4ce55337 100644 --- a/runtime/js/40_permissions.js +++ b/runtime/js/40_permissions.js @@ -31,7 +31,7 @@ * @returns {Deno.PermissionState} */ function opQuery(desc) { - return core.jsonOpSync("op_query_permission", desc); + return core.opSync("op_query_permission", desc); } /** @@ -39,7 +39,7 @@ * @returns {Deno.PermissionState} */ function opRevoke(desc) { - return core.jsonOpSync("op_revoke_permission", desc); + return core.opSync("op_revoke_permission", desc); } /** @@ -47,7 +47,7 @@ * @returns {Deno.PermissionState} */ function opRequest(desc) { - return core.jsonOpSync("op_request_permission", desc); + return core.opSync("op_request_permission", desc); } class PermissionStatus extends EventTarget { diff --git a/runtime/js/40_plugins.js b/runtime/js/40_plugins.js index 5ebcfddada..e9a3142b43 100644 --- a/runtime/js/40_plugins.js +++ b/runtime/js/40_plugins.js @@ -5,7 +5,7 @@ const core = window.Deno.core; function openPlugin(filename) { - return core.jsonOpSync("op_open_plugin", filename); + return core.opSync("op_open_plugin", filename); } window.__bootstrap.plugins = { diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js index a93818b95a..91e37701a2 100644 --- a/runtime/js/40_process.js +++ b/runtime/js/40_process.js @@ -8,16 +8,16 @@ const { assert, pathFromURL } = window.__bootstrap.util; function opKill(pid, signo) { - core.jsonOpSync("op_kill", { pid, signo }); + core.opSync("op_kill", { pid, signo }); } function opRunStatus(rid) { - return core.jsonOpAsync("op_run_status", rid); + return core.opAsync("op_run_status", rid); } function opRun(request) { assert(request.cmd.length > 0); - return core.jsonOpSync("op_run", request); + return core.opSync("op_run", request); } async function runStatus(rid) { diff --git a/runtime/js/40_signals.js b/runtime/js/40_signals.js index e222a91995..dfc6047590 100644 --- a/runtime/js/40_signals.js +++ b/runtime/js/40_signals.js @@ -7,15 +7,15 @@ const { errors } = window.__bootstrap.errors; function bindSignal(signo) { - return core.jsonOpSync("op_signal_bind", signo); + return core.opSync("op_signal_bind", signo); } function pollSignal(rid) { - return core.jsonOpAsync("op_signal_poll", rid); + return core.opAsync("op_signal_poll", rid); } function unbindSignal(rid) { - core.jsonOpSync("op_signal_unbind", rid); + core.opSync("op_signal_unbind", rid); } // From `kill -l` diff --git a/runtime/js/40_tls.js b/runtime/js/40_tls.js index e11754b0d1..4fafe90792 100644 --- a/runtime/js/40_tls.js +++ b/runtime/js/40_tls.js @@ -8,19 +8,19 @@ function opConnectTls( args, ) { - return core.jsonOpAsync("op_connect_tls", args); + return core.opAsync("op_connect_tls", args); } function opAcceptTLS(rid) { - return core.jsonOpAsync("op_accept_tls", rid); + return core.opAsync("op_accept_tls", rid); } function opListenTls(args) { - return core.jsonOpSync("op_listen_tls", args); + return core.opSync("op_listen_tls", args); } function opStartTls(args) { - return core.jsonOpAsync("op_start_tls", args); + return core.opAsync("op_start_tls", args); } async function connectTls({ diff --git a/runtime/js/40_tty.js b/runtime/js/40_tty.js index 9b23b1ec19..e76d7d90e8 100644 --- a/runtime/js/40_tty.js +++ b/runtime/js/40_tty.js @@ -5,11 +5,11 @@ const core = window.Deno.core; function consoleSize(rid) { - return core.jsonOpSync("op_console_size", rid); + return core.opSync("op_console_size", rid); } function isatty(rid) { - return core.jsonOpSync("op_isatty", rid); + return core.opSync("op_isatty", rid); } const DEFAULT_SET_RAW_OPTIONS = { @@ -18,7 +18,7 @@ function setRaw(rid, mode, options = {}) { const rOptions = { ...DEFAULT_SET_RAW_OPTIONS, ...options }; - core.jsonOpSync("op_set_raw", { rid, mode, options: rOptions }); + core.opSync("op_set_raw", { rid, mode, options: rOptions }); } window.__bootstrap.tty = { diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 7f24e10cd6..9777550072 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -129,15 +129,15 @@ delete Object.prototype.__proto__; } function opPostMessage(data) { - core.jsonOpSync("op_worker_post_message", null, data); + core.opSync("op_worker_post_message", null, data); } function opCloseWorker() { - core.jsonOpSync("op_worker_close"); + core.opSync("op_worker_close"); } function opMainModule() { - return core.jsonOpSync("op_main_module"); + return core.opSync("op_main_module"); } function runtimeStart(runtimeOptions, source) { diff --git a/runtime/ops/crypto.rs b/runtime/ops/crypto.rs index 43a9d11267..432cc0185c 100644 --- a/runtime/ops/crypto.rs +++ b/runtime/ops/crypto.rs @@ -10,7 +10,7 @@ pub fn init(rt: &mut deno_core::JsRuntime, maybe_seed: Option) { let mut state = op_state.borrow_mut(); state.put::(rng); } - super::reg_json_sync( + super::reg_sync( rt, "op_crypto_get_random_values", op_crypto_get_random_values, diff --git a/runtime/ops/fetch.rs b/runtime/ops/fetch.rs index 3cb0c6c780..17656974a3 100644 --- a/runtime/ops/fetch.rs +++ b/runtime/ops/fetch.rs @@ -20,19 +20,19 @@ pub fn init( ca_data, }); } - super::reg_json_sync(rt, "op_fetch", deno_fetch::op_fetch::); - super::reg_json_async(rt, "op_fetch_send", deno_fetch::op_fetch_send); - super::reg_json_async( + super::reg_sync(rt, "op_fetch", deno_fetch::op_fetch::); + super::reg_async(rt, "op_fetch_send", deno_fetch::op_fetch_send); + super::reg_async( rt, "op_fetch_request_write", deno_fetch::op_fetch_request_write, ); - super::reg_json_async( + super::reg_async( rt, "op_fetch_response_read", deno_fetch::op_fetch_response_read, ); - super::reg_json_sync( + super::reg_sync( rt, "op_create_http_client", deno_fetch::op_create_http_client::, diff --git a/runtime/ops/file.rs b/runtime/ops/file.rs index e7f68b2074..8f471ebbd1 100644 --- a/runtime/ops/file.rs +++ b/runtime/ops/file.rs @@ -18,14 +18,6 @@ pub fn init( op_state.put(Location(location)); } } - super::reg_json_sync( - rt, - "op_file_create_object_url", - op_file_create_object_url, - ); - super::reg_json_sync( - rt, - "op_file_revoke_object_url", - op_file_revoke_object_url, - ); + super::reg_sync(rt, "op_file_create_object_url", op_file_create_object_url); + super::reg_sync(rt, "op_file_revoke_object_url", op_file_revoke_object_url); } diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index aa3780624a..19933dcb6d 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -34,79 +34,79 @@ use deno_core::error::generic_error; use deno_core::error::not_supported; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_open_sync", op_open_sync); - super::reg_json_async(rt, "op_open_async", op_open_async); + super::reg_sync(rt, "op_open_sync", op_open_sync); + super::reg_async(rt, "op_open_async", op_open_async); - super::reg_json_sync(rt, "op_seek_sync", op_seek_sync); - super::reg_json_async(rt, "op_seek_async", op_seek_async); + super::reg_sync(rt, "op_seek_sync", op_seek_sync); + super::reg_async(rt, "op_seek_async", op_seek_async); - super::reg_json_sync(rt, "op_fdatasync_sync", op_fdatasync_sync); - super::reg_json_async(rt, "op_fdatasync_async", op_fdatasync_async); + super::reg_sync(rt, "op_fdatasync_sync", op_fdatasync_sync); + super::reg_async(rt, "op_fdatasync_async", op_fdatasync_async); - super::reg_json_sync(rt, "op_fsync_sync", op_fsync_sync); - super::reg_json_async(rt, "op_fsync_async", op_fsync_async); + super::reg_sync(rt, "op_fsync_sync", op_fsync_sync); + super::reg_async(rt, "op_fsync_async", op_fsync_async); - super::reg_json_sync(rt, "op_fstat_sync", op_fstat_sync); - super::reg_json_async(rt, "op_fstat_async", op_fstat_async); + super::reg_sync(rt, "op_fstat_sync", op_fstat_sync); + super::reg_async(rt, "op_fstat_async", op_fstat_async); - super::reg_json_sync(rt, "op_umask", op_umask); - super::reg_json_sync(rt, "op_chdir", op_chdir); + super::reg_sync(rt, "op_umask", op_umask); + super::reg_sync(rt, "op_chdir", op_chdir); - super::reg_json_sync(rt, "op_mkdir_sync", op_mkdir_sync); - super::reg_json_async(rt, "op_mkdir_async", op_mkdir_async); + super::reg_sync(rt, "op_mkdir_sync", op_mkdir_sync); + super::reg_async(rt, "op_mkdir_async", op_mkdir_async); - super::reg_json_sync(rt, "op_chmod_sync", op_chmod_sync); - super::reg_json_async(rt, "op_chmod_async", op_chmod_async); + super::reg_sync(rt, "op_chmod_sync", op_chmod_sync); + super::reg_async(rt, "op_chmod_async", op_chmod_async); - super::reg_json_sync(rt, "op_chown_sync", op_chown_sync); - super::reg_json_async(rt, "op_chown_async", op_chown_async); + super::reg_sync(rt, "op_chown_sync", op_chown_sync); + super::reg_async(rt, "op_chown_async", op_chown_async); - super::reg_json_sync(rt, "op_remove_sync", op_remove_sync); - super::reg_json_async(rt, "op_remove_async", op_remove_async); + super::reg_sync(rt, "op_remove_sync", op_remove_sync); + super::reg_async(rt, "op_remove_async", op_remove_async); - super::reg_json_sync(rt, "op_copy_file_sync", op_copy_file_sync); - super::reg_json_async(rt, "op_copy_file_async", op_copy_file_async); + super::reg_sync(rt, "op_copy_file_sync", op_copy_file_sync); + super::reg_async(rt, "op_copy_file_async", op_copy_file_async); - super::reg_json_sync(rt, "op_stat_sync", op_stat_sync); - super::reg_json_async(rt, "op_stat_async", op_stat_async); + super::reg_sync(rt, "op_stat_sync", op_stat_sync); + super::reg_async(rt, "op_stat_async", op_stat_async); - super::reg_json_sync(rt, "op_realpath_sync", op_realpath_sync); - super::reg_json_async(rt, "op_realpath_async", op_realpath_async); + super::reg_sync(rt, "op_realpath_sync", op_realpath_sync); + super::reg_async(rt, "op_realpath_async", op_realpath_async); - super::reg_json_sync(rt, "op_read_dir_sync", op_read_dir_sync); - super::reg_json_async(rt, "op_read_dir_async", op_read_dir_async); + super::reg_sync(rt, "op_read_dir_sync", op_read_dir_sync); + super::reg_async(rt, "op_read_dir_async", op_read_dir_async); - super::reg_json_sync(rt, "op_rename_sync", op_rename_sync); - super::reg_json_async(rt, "op_rename_async", op_rename_async); + super::reg_sync(rt, "op_rename_sync", op_rename_sync); + super::reg_async(rt, "op_rename_async", op_rename_async); - super::reg_json_sync(rt, "op_link_sync", op_link_sync); - super::reg_json_async(rt, "op_link_async", op_link_async); + super::reg_sync(rt, "op_link_sync", op_link_sync); + super::reg_async(rt, "op_link_async", op_link_async); - super::reg_json_sync(rt, "op_symlink_sync", op_symlink_sync); - super::reg_json_async(rt, "op_symlink_async", op_symlink_async); + super::reg_sync(rt, "op_symlink_sync", op_symlink_sync); + super::reg_async(rt, "op_symlink_async", op_symlink_async); - super::reg_json_sync(rt, "op_read_link_sync", op_read_link_sync); - super::reg_json_async(rt, "op_read_link_async", op_read_link_async); + super::reg_sync(rt, "op_read_link_sync", op_read_link_sync); + super::reg_async(rt, "op_read_link_async", op_read_link_async); - super::reg_json_sync(rt, "op_ftruncate_sync", op_ftruncate_sync); - super::reg_json_async(rt, "op_ftruncate_async", op_ftruncate_async); + super::reg_sync(rt, "op_ftruncate_sync", op_ftruncate_sync); + super::reg_async(rt, "op_ftruncate_async", op_ftruncate_async); - super::reg_json_sync(rt, "op_truncate_sync", op_truncate_sync); - super::reg_json_async(rt, "op_truncate_async", op_truncate_async); + super::reg_sync(rt, "op_truncate_sync", op_truncate_sync); + super::reg_async(rt, "op_truncate_async", op_truncate_async); - super::reg_json_sync(rt, "op_make_temp_dir_sync", op_make_temp_dir_sync); - super::reg_json_async(rt, "op_make_temp_dir_async", op_make_temp_dir_async); + super::reg_sync(rt, "op_make_temp_dir_sync", op_make_temp_dir_sync); + super::reg_async(rt, "op_make_temp_dir_async", op_make_temp_dir_async); - super::reg_json_sync(rt, "op_make_temp_file_sync", op_make_temp_file_sync); - super::reg_json_async(rt, "op_make_temp_file_async", op_make_temp_file_async); + super::reg_sync(rt, "op_make_temp_file_sync", op_make_temp_file_sync); + super::reg_async(rt, "op_make_temp_file_async", op_make_temp_file_async); - super::reg_json_sync(rt, "op_cwd", op_cwd); + super::reg_sync(rt, "op_cwd", op_cwd); - super::reg_json_sync(rt, "op_futime_sync", op_futime_sync); - super::reg_json_async(rt, "op_futime_async", op_futime_async); + super::reg_sync(rt, "op_futime_sync", op_futime_sync); + super::reg_async(rt, "op_futime_async", op_futime_async); - super::reg_json_sync(rt, "op_utime_sync", op_utime_sync); - super::reg_json_async(rt, "op_utime_async", op_utime_async); + super::reg_sync(rt, "op_utime_sync", op_utime_sync); + super::reg_async(rt, "op_utime_async", op_utime_async); } #[derive(Deserialize)] diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index 30ab69ba58..8bc9c4c579 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -28,8 +28,8 @@ use std::rc::Rc; use tokio::sync::mpsc; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_fs_events_open", op_fs_events_open); - super::reg_json_async(rt, "op_fs_events_poll", op_fs_events_poll); + super::reg_sync(rt, "op_fs_events_open", op_fs_events_open); + super::reg_async(rt, "op_fs_events_poll", op_fs_events_poll); } struct FsEventsResource { diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index 9cf4ff9d51..f209662c43 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -43,14 +43,14 @@ use tokio_rustls::server::TlsStream; use tokio_util::io::StreamReader; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_http_start", op_http_start); + super::reg_sync(rt, "op_http_start", op_http_start); - super::reg_json_async(rt, "op_http_request_next", op_http_request_next); - super::reg_json_async(rt, "op_http_request_read", op_http_request_read); + super::reg_async(rt, "op_http_request_next", op_http_request_next); + super::reg_async(rt, "op_http_request_read", op_http_request_read); - super::reg_json_sync(rt, "op_http_response", op_http_response); - super::reg_json_async(rt, "op_http_response_write", op_http_response_write); - super::reg_json_async(rt, "op_http_response_close", op_http_response_close); + super::reg_sync(rt, "op_http_response", op_http_response); + super::reg_async(rt, "op_http_response_write", op_http_response_write); + super::reg_async(rt, "op_http_response_close", op_http_response_close); } struct ServiceInner { diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index f8ab92704c..0e4e3f42a1 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -96,13 +96,13 @@ lazy_static::lazy_static! { } pub fn init(rt: &mut JsRuntime) { - super::reg_bin_async(rt, "op_read_async", op_read_async); - super::reg_bin_async(rt, "op_write_async", op_write_async); + super::reg_async(rt, "op_read_async", op_read_async); + super::reg_async(rt, "op_write_async", op_write_async); - super::reg_bin_sync(rt, "op_read_sync", op_read_sync); - super::reg_bin_sync(rt, "op_write_sync", op_write_sync); + super::reg_sync(rt, "op_read_sync", op_read_sync); + super::reg_sync(rt, "op_write_sync", op_write_sync); - super::reg_json_async(rt, "op_shutdown", op_shutdown); + super::reg_async(rt, "op_shutdown", op_shutdown); } pub fn get_stdio() -> ( diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index d9bd2ba835..825950d65e 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -27,59 +27,35 @@ pub mod websocket; pub mod worker_host; use crate::metrics::metrics_op; -use deno_core::bin_op_async; -use deno_core::bin_op_sync; use deno_core::error::AnyError; -use deno_core::json_op_async; -use deno_core::json_op_sync; +use deno_core::op_async; +use deno_core::op_sync; use deno_core::serde::de::DeserializeOwned; use deno_core::serde::Serialize; use deno_core::JsRuntime; use deno_core::OpState; -use deno_core::ValueOrVector; use deno_core::ZeroCopyBuf; use std::cell::RefCell; use std::future::Future; use std::rc::Rc; -pub fn reg_json_async( - rt: &mut JsRuntime, - name: &'static str, - op_fn: F, -) where +pub fn reg_async(rt: &mut JsRuntime, name: &'static str, op_fn: F) +where F: Fn(Rc>, V, Option) -> R + 'static, V: DeserializeOwned, R: Future> + 'static, RV: Serialize + 'static, { - rt.register_op(name, metrics_op(name, json_op_async(op_fn))); + rt.register_op(name, metrics_op(name, op_async(op_fn))); } -pub fn reg_json_sync(rt: &mut JsRuntime, name: &'static str, op_fn: F) +pub fn reg_sync(rt: &mut JsRuntime, name: &'static str, op_fn: F) where F: Fn(&mut OpState, V, Option) -> Result + 'static, V: DeserializeOwned, R: Serialize + 'static, { - rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); -} - -pub fn reg_bin_async(rt: &mut JsRuntime, name: &'static str, op_fn: F) -where - F: Fn(Rc>, u32, Option) -> R + 'static, - R: Future> + 'static, - RV: ValueOrVector, -{ - rt.register_op(name, metrics_op(name, bin_op_async(op_fn))); -} - -pub fn reg_bin_sync(rt: &mut JsRuntime, name: &'static str, op_fn: F) -where - F: - Fn(&mut OpState, u32, Option) -> Result + 'static, - R: ValueOrVector, -{ - rt.register_op(name, metrics_op(name, bin_op_sync(op_fn))); + rt.register_op(name, metrics_op(name, op_sync(op_fn))); } /// `UnstableChecker` is a struct so it can be placed inside `GothamState`; diff --git a/runtime/ops/net.rs b/runtime/ops/net.rs index 934ff79265..ee762ed471 100644 --- a/runtime/ops/net.rs +++ b/runtime/ops/net.rs @@ -43,12 +43,12 @@ use crate::ops::io::UnixStreamResource; use std::path::Path; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_async(rt, "op_accept", op_accept); - super::reg_json_async(rt, "op_connect", op_connect); - super::reg_json_sync(rt, "op_listen", op_listen); - super::reg_json_async(rt, "op_datagram_receive", op_datagram_receive); - super::reg_json_async(rt, "op_datagram_send", op_datagram_send); - super::reg_json_async(rt, "op_dns_resolve", op_dns_resolve); + super::reg_async(rt, "op_accept", op_accept); + super::reg_async(rt, "op_connect", op_connect); + super::reg_sync(rt, "op_listen", op_listen); + super::reg_async(rt, "op_datagram_receive", op_datagram_receive); + super::reg_async(rt, "op_datagram_send", op_datagram_send); + super::reg_async(rt, "op_dns_resolve", op_dns_resolve); } #[derive(Serialize)] diff --git a/runtime/ops/os.rs b/runtime/ops/os.rs index b13b54d22e..b9511fcdc3 100644 --- a/runtime/ops/os.rs +++ b/runtime/ops/os.rs @@ -12,17 +12,17 @@ use std::collections::HashMap; use std::env; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_exit", op_exit); - super::reg_json_sync(rt, "op_env", op_env); - super::reg_json_sync(rt, "op_exec_path", op_exec_path); - super::reg_json_sync(rt, "op_set_env", op_set_env); - super::reg_json_sync(rt, "op_get_env", op_get_env); - super::reg_json_sync(rt, "op_delete_env", op_delete_env); - super::reg_json_sync(rt, "op_hostname", op_hostname); - super::reg_json_sync(rt, "op_loadavg", op_loadavg); - super::reg_json_sync(rt, "op_os_release", op_os_release); - super::reg_json_sync(rt, "op_system_memory_info", op_system_memory_info); - super::reg_json_sync(rt, "op_system_cpu_info", op_system_cpu_info); + super::reg_sync(rt, "op_exit", op_exit); + super::reg_sync(rt, "op_env", op_env); + super::reg_sync(rt, "op_exec_path", op_exec_path); + super::reg_sync(rt, "op_set_env", op_set_env); + super::reg_sync(rt, "op_get_env", op_get_env); + super::reg_sync(rt, "op_delete_env", op_delete_env); + super::reg_sync(rt, "op_hostname", op_hostname); + super::reg_sync(rt, "op_loadavg", op_loadavg); + super::reg_sync(rt, "op_os_release", op_os_release); + super::reg_sync(rt, "op_system_memory_info", op_system_memory_info); + super::reg_sync(rt, "op_system_cpu_info", op_system_cpu_info); } fn op_exec_path( diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index 77d095d84e..ce89def548 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -11,9 +11,9 @@ use serde::Deserialize; use std::path::Path; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_query_permission", op_query_permission); - super::reg_json_sync(rt, "op_revoke_permission", op_revoke_permission); - super::reg_json_sync(rt, "op_request_permission", op_request_permission); + super::reg_sync(rt, "op_query_permission", op_query_permission); + super::reg_sync(rt, "op_revoke_permission", op_revoke_permission); + super::reg_sync(rt, "op_request_permission", op_request_permission); } #[derive(Deserialize)] diff --git a/runtime/ops/plugin.rs b/runtime/ops/plugin.rs index d0fc989f46..c265c757f4 100644 --- a/runtime/ops/plugin.rs +++ b/runtime/ops/plugin.rs @@ -23,7 +23,7 @@ use std::task::Context; use std::task::Poll; pub fn init(rt: &mut JsRuntime) { - super::reg_json_sync(rt, "op_open_plugin", op_open_plugin); + super::reg_sync(rt, "op_open_plugin", op_open_plugin); } pub fn op_open_plugin( diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 4b49e21f3f..bf074db2ca 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -26,9 +26,9 @@ use tokio::process::Command; use std::os::unix::process::ExitStatusExt; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_run", op_run); - super::reg_json_async(rt, "op_run_status", op_run_status); - super::reg_json_sync(rt, "op_kill", op_kill); + super::reg_sync(rt, "op_run", op_run); + super::reg_async(rt, "op_run_status", op_run_status); + super::reg_sync(rt, "op_kill", op_kill); } fn clone_file( diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index d694cb9c93..d90e925934 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -17,8 +17,8 @@ pub fn init(rt: &mut deno_core::JsRuntime, main_module: ModuleSpecifier) { let mut state = op_state.borrow_mut(); state.put::(main_module); } - super::reg_json_sync(rt, "op_main_module", op_main_module); - super::reg_json_sync(rt, "op_metrics", op_metrics); + super::reg_sync(rt, "op_main_module", op_main_module); + super::reg_sync(rt, "op_metrics", op_metrics); } fn op_main_module( diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 5235da6120..2a19e4e981 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -25,9 +25,9 @@ use std::borrow::Cow; use tokio::signal::unix::{signal, Signal, SignalKind}; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_signal_bind", op_signal_bind); - super::reg_json_sync(rt, "op_signal_unbind", op_signal_unbind); - super::reg_json_async(rt, "op_signal_poll", op_signal_poll); + super::reg_sync(rt, "op_signal_bind", op_signal_bind); + super::reg_sync(rt, "op_signal_unbind", op_signal_unbind); + super::reg_async(rt, "op_signal_poll", op_signal_poll); } #[cfg(unix)] diff --git a/runtime/ops/timers.rs b/runtime/ops/timers.rs index aee38cf8d3..8e709440e1 100644 --- a/runtime/ops/timers.rs +++ b/runtime/ops/timers.rs @@ -69,11 +69,11 @@ pub fn init(rt: &mut deno_core::JsRuntime) { state.put::(GlobalTimer::default()); state.put::(StartTime::now()); } - super::reg_json_sync(rt, "op_global_timer_stop", op_global_timer_stop); - super::reg_json_sync(rt, "op_global_timer_start", op_global_timer_start); - super::reg_json_async(rt, "op_global_timer", op_global_timer); - super::reg_json_sync(rt, "op_now", op_now); - super::reg_json_sync(rt, "op_sleep_sync", op_sleep_sync); + super::reg_sync(rt, "op_global_timer_stop", op_global_timer_stop); + super::reg_sync(rt, "op_global_timer_start", op_global_timer_start); + super::reg_async(rt, "op_global_timer", op_global_timer); + super::reg_sync(rt, "op_now", op_now); + super::reg_sync(rt, "op_sleep_sync", op_sleep_sync); } #[allow(clippy::unnecessary_wraps)] diff --git a/runtime/ops/tls.rs b/runtime/ops/tls.rs index 36762d66c6..10293cf929 100644 --- a/runtime/ops/tls.rs +++ b/runtime/ops/tls.rs @@ -71,10 +71,10 @@ impl StoresClientSessions for ClientSessionMemoryCache { } pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_async(rt, "op_start_tls", op_start_tls); - super::reg_json_async(rt, "op_connect_tls", op_connect_tls); - super::reg_json_sync(rt, "op_listen_tls", op_listen_tls); - super::reg_json_async(rt, "op_accept_tls", op_accept_tls); + super::reg_async(rt, "op_start_tls", op_start_tls); + super::reg_async(rt, "op_connect_tls", op_connect_tls); + super::reg_sync(rt, "op_listen_tls", op_listen_tls); + super::reg_async(rt, "op_accept_tls", op_accept_tls); } #[derive(Deserialize)] diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index 9af72b5cde..a62a9ba029 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -44,9 +44,9 @@ fn get_windows_handle( } pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_set_raw", op_set_raw); - super::reg_json_sync(rt, "op_isatty", op_isatty); - super::reg_json_sync(rt, "op_console_size", op_console_size); + super::reg_sync(rt, "op_set_raw", op_set_raw); + super::reg_sync(rt, "op_isatty", op_isatty); + super::reg_sync(rt, "op_console_size", op_console_size); } #[derive(Deserialize)] diff --git a/runtime/ops/url.rs b/runtime/ops/url.rs index 4add9132d6..5168a7242a 100644 --- a/runtime/ops/url.rs +++ b/runtime/ops/url.rs @@ -4,13 +4,9 @@ use deno_url::op_url_parse_search_params; use deno_url::op_url_stringify_search_params; pub fn init(rt: &mut deno_core::JsRuntime) { - super::reg_json_sync(rt, "op_url_parse", op_url_parse); - super::reg_json_sync( - rt, - "op_url_parse_search_params", - op_url_parse_search_params, - ); - super::reg_json_sync( + super::reg_sync(rt, "op_url_parse", op_url_parse); + super::reg_sync(rt, "op_url_parse_search_params", op_url_parse_search_params); + super::reg_sync( rt, "op_url_stringify_search_params", op_url_stringify_search_params, diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index 5f63a03b7a..68cef110c7 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -12,7 +12,7 @@ pub fn init( ) { // Post message to host as guest worker. let sender_ = sender.clone(); - super::reg_json_sync( + super::reg_sync( rt, "op_worker_post_message", move |_state, _args: (), buf| { @@ -27,15 +27,11 @@ pub fn init( ); // Notify host that guest worker closes. - super::reg_json_sync( - rt, - "op_worker_close", - move |_state, _args: (), _bufs| { - // Notify parent that we're finished - sender.clone().close_channel(); - // Terminate execution of current worker - handle.terminate(); - Ok(()) - }, - ); + super::reg_sync(rt, "op_worker_close", move |_state, _args: (), _bufs| { + // Notify parent that we're finished + sender.clone().close_channel(); + // Terminate execution of current worker + handle.terminate(); + Ok(()) + }); } diff --git a/runtime/ops/webgpu.rs b/runtime/ops/webgpu.rs index d48913ce83..55c6d18173 100644 --- a/runtime/ops/webgpu.rs +++ b/runtime/ops/webgpu.rs @@ -10,40 +10,28 @@ pub fn init(rt: &mut deno_core::JsRuntime) { state.put(Unstable(unstable)); } - super::reg_json_async( - rt, - "op_webgpu_request_adapter", - op_webgpu_request_adapter, - ); - super::reg_json_async( - rt, - "op_webgpu_request_device", - op_webgpu_request_device, - ); - super::reg_json_sync( - rt, - "op_webgpu_create_query_set", - op_webgpu_create_query_set, - ); + super::reg_async(rt, "op_webgpu_request_adapter", op_webgpu_request_adapter); + super::reg_async(rt, "op_webgpu_request_device", op_webgpu_request_device); + super::reg_sync(rt, "op_webgpu_create_query_set", op_webgpu_create_query_set); { // buffer - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_buffer", buffer::op_webgpu_create_buffer, ); - super::reg_json_async( + super::reg_async( rt, "op_webgpu_buffer_get_map_async", buffer::op_webgpu_buffer_get_map_async, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_buffer_get_mapped_range", buffer::op_webgpu_buffer_get_mapped_range, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_buffer_unmap", buffer::op_webgpu_buffer_unmap, @@ -51,12 +39,12 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // texture - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_texture", texture::op_webgpu_create_texture, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_texture_view", texture::op_webgpu_create_texture_view, @@ -64,7 +52,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // sampler - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_sampler", sampler::op_webgpu_create_sampler, @@ -72,17 +60,17 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // binding - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_bind_group_layout", binding::op_webgpu_create_bind_group_layout, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_pipeline_layout", binding::op_webgpu_create_pipeline_layout, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_bind_group", binding::op_webgpu_create_bind_group, @@ -90,22 +78,22 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // pipeline - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_compute_pipeline", pipeline::op_webgpu_create_compute_pipeline, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pipeline_get_bind_group_layout", pipeline::op_webgpu_compute_pipeline_get_bind_group_layout, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_render_pipeline", pipeline::op_webgpu_create_render_pipeline, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pipeline_get_bind_group_layout", pipeline::op_webgpu_render_pipeline_get_bind_group_layout, @@ -113,67 +101,67 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // command_encoder - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_command_encoder", command_encoder::op_webgpu_create_command_encoder, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_begin_render_pass", command_encoder::op_webgpu_command_encoder_begin_render_pass, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_begin_compute_pass", command_encoder::op_webgpu_command_encoder_begin_compute_pass, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_copy_buffer_to_buffer", command_encoder::op_webgpu_command_encoder_copy_buffer_to_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_copy_buffer_to_texture", command_encoder::op_webgpu_command_encoder_copy_buffer_to_texture, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_copy_texture_to_buffer", command_encoder::op_webgpu_command_encoder_copy_texture_to_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_copy_texture_to_texture", command_encoder::op_webgpu_command_encoder_copy_texture_to_texture, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_push_debug_group", command_encoder::op_webgpu_command_encoder_push_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_pop_debug_group", command_encoder::op_webgpu_command_encoder_pop_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_insert_debug_marker", command_encoder::op_webgpu_command_encoder_insert_debug_marker, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_write_timestamp", command_encoder::op_webgpu_command_encoder_write_timestamp, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_resolve_query_set", command_encoder::op_webgpu_command_encoder_resolve_query_set, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_command_encoder_finish", command_encoder::op_webgpu_command_encoder_finish, @@ -181,102 +169,102 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // render_pass - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_viewport", render_pass::op_webgpu_render_pass_set_viewport, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_scissor_rect", render_pass::op_webgpu_render_pass_set_scissor_rect, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_blend_color", render_pass::op_webgpu_render_pass_set_blend_color, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_stencil_reference", render_pass::op_webgpu_render_pass_set_stencil_reference, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_begin_pipeline_statistics_query", render_pass::op_webgpu_render_pass_begin_pipeline_statistics_query, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_end_pipeline_statistics_query", render_pass::op_webgpu_render_pass_end_pipeline_statistics_query, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_write_timestamp", render_pass::op_webgpu_render_pass_write_timestamp, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_execute_bundles", render_pass::op_webgpu_render_pass_execute_bundles, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_end_pass", render_pass::op_webgpu_render_pass_end_pass, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_bind_group", render_pass::op_webgpu_render_pass_set_bind_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_push_debug_group", render_pass::op_webgpu_render_pass_push_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_pop_debug_group", render_pass::op_webgpu_render_pass_pop_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_insert_debug_marker", render_pass::op_webgpu_render_pass_insert_debug_marker, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_pipeline", render_pass::op_webgpu_render_pass_set_pipeline, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_index_buffer", render_pass::op_webgpu_render_pass_set_index_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_set_vertex_buffer", render_pass::op_webgpu_render_pass_set_vertex_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_draw", render_pass::op_webgpu_render_pass_draw, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_draw_indexed", render_pass::op_webgpu_render_pass_draw_indexed, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_draw_indirect", render_pass::op_webgpu_render_pass_draw_indirect, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_pass_draw_indexed_indirect", render_pass::op_webgpu_render_pass_draw_indexed_indirect, @@ -284,42 +272,42 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // compute_pass - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_set_pipeline", compute_pass::op_webgpu_compute_pass_set_pipeline, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_dispatch", compute_pass::op_webgpu_compute_pass_dispatch, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_dispatch_indirect", compute_pass::op_webgpu_compute_pass_dispatch_indirect, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_end_pass", compute_pass::op_webgpu_compute_pass_end_pass, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_set_bind_group", compute_pass::op_webgpu_compute_pass_set_bind_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_push_debug_group", compute_pass::op_webgpu_compute_pass_push_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_pop_debug_group", compute_pass::op_webgpu_compute_pass_pop_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_compute_pass_insert_debug_marker", compute_pass::op_webgpu_compute_pass_insert_debug_marker, @@ -327,62 +315,62 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // bundle - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_render_bundle_encoder", bundle::op_webgpu_create_render_bundle_encoder, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_finish", bundle::op_webgpu_render_bundle_encoder_finish, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_set_bind_group", bundle::op_webgpu_render_bundle_encoder_set_bind_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_push_debug_group", bundle::op_webgpu_render_bundle_encoder_push_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_pop_debug_group", bundle::op_webgpu_render_bundle_encoder_pop_debug_group, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_insert_debug_marker", bundle::op_webgpu_render_bundle_encoder_insert_debug_marker, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_set_pipeline", bundle::op_webgpu_render_bundle_encoder_set_pipeline, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_set_index_buffer", bundle::op_webgpu_render_bundle_encoder_set_index_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_set_vertex_buffer", bundle::op_webgpu_render_bundle_encoder_set_vertex_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_draw", bundle::op_webgpu_render_bundle_encoder_draw, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_draw_indexed", bundle::op_webgpu_render_bundle_encoder_draw_indexed, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_render_bundle_encoder_draw_indirect", bundle::op_webgpu_render_bundle_encoder_draw_indirect, @@ -390,17 +378,17 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // queue - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_queue_submit", queue::op_webgpu_queue_submit, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_write_buffer", queue::op_webgpu_write_buffer, ); - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_write_texture", queue::op_webgpu_write_texture, @@ -408,7 +396,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) { } { // shader - super::reg_json_sync( + super::reg_sync( rt, "op_webgpu_create_shader_module", shader::op_webgpu_create_shader_module, diff --git a/runtime/ops/websocket.rs b/runtime/ops/websocket.rs index 1563961d75..1c44f8b80b 100644 --- a/runtime/ops/websocket.rs +++ b/runtime/ops/websocket.rs @@ -21,13 +21,13 @@ pub fn init( state.put::(WsCaData(ca_data)); } } - super::reg_json_sync( + super::reg_sync( rt, "op_ws_check_permission", op_ws_check_permission::, ); - super::reg_json_async(rt, "op_ws_create", op_ws_create::); - super::reg_json_async(rt, "op_ws_send", op_ws_send); - super::reg_json_async(rt, "op_ws_close", op_ws_close); - super::reg_json_async(rt, "op_ws_next_event", op_ws_next_event); + super::reg_async(rt, "op_ws_create", op_ws_create::); + super::reg_async(rt, "op_ws_send", op_ws_send); + super::reg_async(rt, "op_ws_close", op_ws_close); + super::reg_async(rt, "op_ws_next_event", op_ws_next_event); } diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 2f297fb08f..92de420e31 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -80,15 +80,11 @@ pub fn init( let create_module_loader = CreateWebWorkerCbHolder(create_web_worker_cb); state.put::(create_module_loader); } - super::reg_json_sync(rt, "op_create_worker", op_create_worker); - super::reg_json_sync( - rt, - "op_host_terminate_worker", - op_host_terminate_worker, - ); - super::reg_json_sync(rt, "op_host_post_message", op_host_post_message); - super::reg_json_async(rt, "op_host_get_message", op_host_get_message); - super::reg_json_sync( + super::reg_sync(rt, "op_create_worker", op_create_worker); + super::reg_sync(rt, "op_host_terminate_worker", op_host_terminate_worker); + super::reg_sync(rt, "op_host_post_message", op_host_post_message); + super::reg_async(rt, "op_host_get_message", op_host_get_message); + super::reg_sync( rt, "op_host_unhandled_error", move |_state, message: String, _zero_copy| { diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index c30b715e40..68bbe1a5d9 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -231,8 +231,8 @@ impl WebWorker { Some(sender), options.create_web_worker_cb.clone(), ); - ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close); - ops::reg_json_sync(js_runtime, "op_resources", deno_core::op_resources); + ops::reg_sync(js_runtime, "op_close", deno_core::op_close); + ops::reg_sync(js_runtime, "op_resources", deno_core::op_resources); ops::url::init(js_runtime); ops::file::init( js_runtime, diff --git a/runtime/worker.rs b/runtime/worker.rs index 5db542b42d..2537255330 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -128,8 +128,8 @@ impl MainWorker { options.create_web_worker_cb.clone(), ); ops::crypto::init(js_runtime, options.seed); - ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close); - ops::reg_json_sync(js_runtime, "op_resources", deno_core::op_resources); + ops::reg_sync(js_runtime, "op_close", deno_core::op_close); + ops::reg_sync(js_runtime, "op_resources", deno_core::op_resources); ops::url::init(js_runtime); ops::file::init( js_runtime,