1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-12 09:03:42 -05:00

refactor(deno): remove concept of bin & json ops (#10145)

This commit is contained in:
Aaron O'Mullan 2021-04-12 21:55:05 +02:00 committed by GitHub
parent a20504642d
commit 46b1c653c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 534 additions and 1080 deletions

View file

@ -21,9 +21,6 @@ pub(crate) fn benchmark(
let hyper_hello_exe = target_path.join("test_server"); let hyper_hello_exe = target_path.join("test_server");
let hyper_hello_exe = hyper_hello_exe.to_str().unwrap(); 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 = target_path.join("examples/http_bench_json_ops");
let core_http_json_ops_exe = core_http_json_ops_exe.to_str().unwrap(); 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_proxy_tcp".to_string(),
deno_tcp_proxy(deno_exe, hyper_hello_exe)?, deno_tcp_proxy(deno_exe, hyper_hello_exe)?,
); );
// "core_http_bin_ops" was once called "deno_core_single" // "core_http_json_ops" previously had a "bin op" counterpart called "core_http_bin_ops",
// "core_http_bin_ops" was once called "deno_core_http_bench" // which was previously also called "deno_core_http_bench", "deno_core_single"
res.insert(
"core_http_bin_ops".to_string(),
core_http_bin_ops(core_http_bin_ops_exe)?,
);
res.insert( res.insert(
"core_http_json_ops".to_string(), "core_http_json_ops".to_string(),
core_http_json_ops(core_http_json_ops_exe)?, 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<HttpBenchmarkResult> {
println!("http_benchmark testing CORE http_bench_bin_ops");
run(&[exe], 4544, None, None)
}
fn core_http_json_ops(exe: &str) -> Result<HttpBenchmarkResult> { fn core_http_json_ops(exe: &str) -> Result<HttpBenchmarkResult> {
println!("http_benchmark testing CORE http_bench_json_ops"); println!("http_benchmark testing CORE http_bench_json_ops");
run(&[exe], 4544, None, None) run(&[exe], 4544, None, None)

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::custom_error; 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::Deserialize;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::serde_json::json; use deno_core::serde_json::json;
@ -156,7 +156,7 @@ fn create_compiler_snapshot(
}); });
js_runtime.register_op( js_runtime.register_op(
"op_build_info", "op_build_info",
json_op_sync(move |_state, _args: Value, _bufs| { op_sync(move |_state, _args: Value, _bufs| {
Ok(json!({ Ok(json!({
"buildSpecifier": build_specifier, "buildSpecifier": build_specifier,
"libs": build_libs, "libs": build_libs,
@ -167,7 +167,7 @@ fn create_compiler_snapshot(
// files, but a slightly different implementation at build time. // files, but a slightly different implementation at build time.
js_runtime.register_op( js_runtime.register_op(
"op_load", "op_load",
json_op_sync(move |_state, args, _bufs| { op_sync(move |_state, args, _bufs| {
let v: LoadArgs = serde_json::from_value(args)?; let v: LoadArgs = serde_json::from_value(args)?;
// we need a basic file to send to tsc to warm it up. // we need a basic file to send to tsc to warm it up.
if v.specifier == build_specifier { if v.specifier == build_specifier {

View file

@ -18,7 +18,7 @@ use crate::tsc_config::TsConfig;
use deno_core::error::anyhow; use deno_core::error::anyhow;
use deno_core::error::custom_error; use deno_core::error::custom_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::json_op_sync; use deno_core::op_sync;
use deno_core::resolve_url; use deno_core::resolve_url;
use deno_core::serde::de; use deno_core::serde::de;
use deno_core::serde::Deserialize; use deno_core::serde::Deserialize;
@ -1480,7 +1480,7 @@ where
V: de::DeserializeOwned, V: de::DeserializeOwned,
R: Serialize + 'static, R: Serialize + 'static,
{ {
json_op_sync(move |s, args, _bufs| { op_sync(move |s, args, _bufs| {
let state = s.borrow_mut::<State>(); let state = s.borrow_mut::<State>();
op_fn(state, args) op_fn(state, args)
}) })

View file

@ -15,8 +15,8 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_apply_source_map", op_apply_source_map); super::reg_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_format_diagnostic", op_format_diagnostic);
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -4,8 +4,8 @@ pub mod errors;
pub mod runtime_compiler; pub mod runtime_compiler;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::json_op_async; use deno_core::op_async;
use deno_core::json_op_sync; use deno_core::op_sync;
use deno_core::serde_json::Value; use deno_core::serde_json::Value;
use deno_core::JsRuntime; use deno_core::JsRuntime;
use deno_core::OpState; use deno_core::OpState;
@ -15,18 +15,18 @@ use std::cell::RefCell;
use std::future::Future; use std::future::Future;
use std::rc::Rc; use std::rc::Rc;
pub fn reg_json_async<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) pub fn reg_async<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where where
F: Fn(Rc<RefCell<OpState>>, Value, Option<ZeroCopyBuf>) -> R + 'static, F: Fn(Rc<RefCell<OpState>>, Value, Option<ZeroCopyBuf>) -> R + 'static,
R: Future<Output = Result<Value, AnyError>> + 'static, R: Future<Output = Result<Value, AnyError>> + '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<F>(rt: &mut JsRuntime, name: &'static str, op_fn: F) pub fn reg_sync<F>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where where
F: Fn(&mut OpState, Value, Option<ZeroCopyBuf>) -> Result<Value, AnyError> F: Fn(&mut OpState, Value, Option<ZeroCopyBuf>) -> Result<Value, AnyError>
+ 'static, + 'static,
{ {
rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); rt.register_op(name, metrics_op(name, op_sync(op_fn)));
} }

View file

@ -28,7 +28,7 @@ use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
pub fn init(rt: &mut deno_core::JsRuntime) { 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)] #[derive(Debug, Deserialize)]

View file

@ -9,7 +9,7 @@ unitTest(async function sendAsyncStackTrace() {
} catch (error) { } catch (error) {
const s = error.stack.toString(); const s = error.stack.toString();
console.log(s); console.log(s);
assertStringIncludes(s, "dispatch_bin_test.ts"); assertStringIncludes(s, "dispatch_test.ts");
assertStringIncludes(s, "read"); assertStringIncludes(s, "read");
} }
}); });
@ -21,10 +21,10 @@ declare global {
} }
} }
unitTest(async function binOpsAsyncBadResource(): Promise<void> { unitTest(async function opsAsyncBadResource(): Promise<void> {
try { try {
const nonExistingRid = 9999; const nonExistingRid = 9999;
await Deno.core.binOpAsync( await Deno.core.opAsync(
"op_read_async", "op_read_async",
nonExistingRid, nonExistingRid,
new Uint8Array(0), new Uint8Array(0),
@ -36,10 +36,10 @@ unitTest(async function binOpsAsyncBadResource(): Promise<void> {
} }
}); });
unitTest(function binOpsSyncBadResource(): void { unitTest(function opsSyncBadResource(): void {
try { try {
const nonExistingRid = 9999; 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) { } catch (e) {
if (!(e instanceof Deno.errors.BadResource)) { if (!(e instanceof Deno.errors.BadResource)) {
throw e; throw e;

View file

@ -15,7 +15,7 @@ import "./console_test.ts";
import "./copy_file_test.ts"; import "./copy_file_test.ts";
import "./custom_event_test.ts"; import "./custom_event_test.ts";
import "./dir_test.ts"; import "./dir_test.ts";
import "./dispatch_bin_test.ts"; import "./dispatch_test.ts";
import "./error_stack_test.ts"; import "./error_stack_test.ts";
import "./event_test.ts"; import "./event_test.ts";
import "./event_target_test.ts"; import "./event_target_test.ts";

View file

@ -10,7 +10,7 @@ use deno_core::error::anyhow;
use deno_core::error::bail; use deno_core::error::bail;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::error::Context; 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::resolve_url_or_path;
use deno_core::serde::Deserialize; use deno_core::serde::Deserialize;
use deno_core::serde_json; use deno_core::serde_json;
@ -227,7 +227,7 @@ fn op<F>(op_fn: F) -> Box<OpFn>
where where
F: Fn(&mut State, Value) -> Result<Value, AnyError> + 'static, F: Fn(&mut State, Value) -> Result<Value, AnyError> + 'static,
{ {
json_op_sync(move |s, args, _bufs| { op_sync(move |s, args, _bufs| {
let state = s.borrow_mut::<State>(); let state = s.borrow_mut::<State>();
op_fn(state, args) op_fn(state, args)
}) })

View file

@ -200,7 +200,7 @@ delete Object.prototype.__proto__;
debug( debug(
`snapshot.getText(${start}, ${end}) specifier: ${specifier} version: ${version}`, `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} * @returns {number}
@ -208,7 +208,7 @@ delete Object.prototype.__proto__;
getLength() { getLength() {
const { specifier, version } = this; const { specifier, version } = this;
debug(`snapshot.getLength() specifier: ${specifier} version: ${version}`); 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 * @param {ScriptSnapshot} oldSnapshot
@ -221,7 +221,7 @@ delete Object.prototype.__proto__;
debug( debug(
`snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`, `snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`,
); );
return core.jsonOpSync( return core.opSync(
"op_get_change_range", "op_get_change_range",
{ specifier, oldLength, oldVersion, version }, { specifier, oldLength, oldVersion, version },
); );
@ -229,7 +229,7 @@ delete Object.prototype.__proto__;
dispose() { dispose() {
const { specifier, version } = this; const { specifier, version } = this;
debug(`snapshot.dispose() specifier: ${specifier} version: ${version}`); 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) { readFile(specifier) {
debug(`host.readFile("${specifier}")`); debug(`host.readFile("${specifier}")`);
return core.jsonOpSync("op_load", { specifier }).data; return core.opSync("op_load", { specifier }).data;
}, },
getSourceFile( getSourceFile(
specifier, specifier,
@ -272,7 +272,7 @@ delete Object.prototype.__proto__;
specifier = normalizedToOriginalMap.get(specifier) ?? specifier; specifier = normalizedToOriginalMap.get(specifier) ?? specifier;
/** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */ /** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */
const { data, hash, scriptKind } = core.jsonOpSync( const { data, hash, scriptKind } = core.opSync(
"op_load", "op_load",
{ specifier }, { specifier },
); );
@ -304,7 +304,7 @@ delete Object.prototype.__proto__;
if (sourceFiles) { if (sourceFiles) {
maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName); maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName);
} }
return core.jsonOpSync( return core.opSync(
"op_emit", "op_emit",
{ maybeSpecifiers, fileName, data }, { maybeSpecifiers, fileName, data },
); );
@ -326,7 +326,7 @@ delete Object.prototype.__proto__;
debug(` base: ${base}`); debug(` base: ${base}`);
debug(` specifiers: ${specifiers.join(", ")}`); debug(` specifiers: ${specifiers.join(", ")}`);
/** @type {Array<[string, ts.Extension] | undefined>} */ /** @type {Array<[string, ts.Extension] | undefined>} */
const resolved = core.jsonOpSync("op_resolve", { const resolved = core.opSync("op_resolve", {
specifiers, specifiers,
base, base,
}); });
@ -349,7 +349,7 @@ delete Object.prototype.__proto__;
} }
}, },
createHash(data) { createHash(data) {
return core.jsonOpSync("op_create_hash", { data }).hash; return core.opSync("op_create_hash", { data }).hash;
}, },
// LanguageServiceHost // LanguageServiceHost
@ -359,7 +359,7 @@ delete Object.prototype.__proto__;
}, },
getScriptFileNames() { getScriptFileNames() {
debug("host.getScriptFileNames()"); debug("host.getScriptFileNames()");
return core.jsonOpSync("op_script_names", undefined); return core.opSync("op_script_names", undefined);
}, },
getScriptVersion(specifier) { getScriptVersion(specifier) {
debug(`host.getScriptVersion("${specifier}")`); debug(`host.getScriptVersion("${specifier}")`);
@ -367,7 +367,7 @@ delete Object.prototype.__proto__;
if (sourceFile) { if (sourceFile) {
return sourceFile.version ?? "1"; return sourceFile.version ?? "1";
} }
return core.jsonOpSync("op_script_version", { specifier }); return core.opSync("op_script_version", { specifier });
}, },
getScriptSnapshot(specifier) { getScriptSnapshot(specifier) {
debug(`host.getScriptSnapshot("${specifier}")`); debug(`host.getScriptSnapshot("${specifier}")`);
@ -386,7 +386,7 @@ delete Object.prototype.__proto__;
}; };
} }
/** @type {string | undefined} */ /** @type {string | undefined} */
const version = core.jsonOpSync("op_script_version", { specifier }); const version = core.opSync("op_script_version", { specifier });
if (version != null) { if (version != null) {
return new ScriptSnapshot(specifier, version); return new ScriptSnapshot(specifier, version);
} }
@ -505,7 +505,7 @@ delete Object.prototype.__proto__;
].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code)); ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));
performanceProgram({ program }); performanceProgram({ program });
core.jsonOpSync("op_respond", { core.opSync("op_respond", {
diagnostics: fromTypeScriptDiagnostic(diagnostics), diagnostics: fromTypeScriptDiagnostic(diagnostics),
stats: performanceEnd(), stats: performanceEnd(),
}); });
@ -517,7 +517,7 @@ delete Object.prototype.__proto__;
* @param {any} data * @param {any} data
*/ */
function respond(id, data = null) { 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 // A build time only op that provides some setup information that is used to
// ensure the snapshot is setup properly. // ensure the snapshot is setup properly.
/** @type {{ buildSpecifier: string; libs: string[] }} */ /** @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) { for (const lib of libs) {
const specifier = `lib.${lib}.d.ts`; const specifier = `lib.${lib}.d.ts`;
// we are using internal APIs here to "inject" our custom libraries into // we are using internal APIs here to "inject" our custom libraries into

View file

@ -34,7 +34,7 @@ declare global {
interface DenoCore { interface DenoCore {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
jsonOpSync<T>(name: string, params: T): any; opSync<T>(name: string, params: T): any;
ops(): void; ops(): void;
print(msg: string, code?: number): void; print(msg: string, code?: number): void;
registerErrorClass( registerErrorClass(

View file

@ -26,10 +26,6 @@ serde_json = { version = "1.0.64", features = ["preserve_order"] }
serde_v8 = { version = "0.1.0", path = "../serde_v8" } serde_v8 = { version = "0.1.0", path = "../serde_v8" }
url = { version = "2.2.1", features = ["serde"] } url = { version = "2.2.1", features = ["serde"] }
[[example]]
name = "http_bench_bin_ops"
path = "examples/http_bench_bin_ops.rs"
[[example]] [[example]]
name = "http_bench_json_ops" name = "http_bench_json_ops"
path = "examples/http_bench_json_ops.rs" path = "examples/http_bench_json_ops.rs"

View file

@ -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. encoding both the request and response into a Uint8Array.
Documentation for this crate is thin at the moment. Please see 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) [http_bench_ops.rs](https://github.com/denoland/deno/blob/main/core/examples/http_bench_ops.rs)
and
[http_bench_json_ops.rs](https://github.com/denoland/deno/blob/main/core/examples/http_bench_json_ops.rs)
as a simple example of usage. as a simple example of usage.
TypeScript support and a lot of other functionality is not available at this TypeScript support and a lot of other functionality is not available at this

View file

@ -1,9 +1,8 @@
use bencher::{benchmark_group, benchmark_main, Bencher}; use bencher::{benchmark_group, benchmark_main, Bencher};
use deno_core::bin_op_sync;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::json_op_async; use deno_core::op_async;
use deno_core::json_op_sync; use deno_core::op_sync;
use deno_core::v8; use deno_core::v8;
use deno_core::JsRuntime; use deno_core::JsRuntime;
use deno_core::Op; use deno_core::Op;
@ -16,9 +15,8 @@ use std::rc::Rc;
fn create_js_runtime() -> JsRuntime { fn create_js_runtime() -> JsRuntime {
let mut runtime = JsRuntime::new(Default::default()); let mut runtime = JsRuntime::new(Default::default());
runtime.register_op("pi_bin", bin_op_sync(|_, _, _| Ok(314159))); runtime.register_op("pi_json", op_sync(|_, _: (), _| Ok(314159)));
runtime.register_op("pi_json", json_op_sync(|_, _: (), _| Ok(314159))); runtime.register_op("pi_async", op_async(op_pi_async));
runtime.register_op("pi_async", json_op_async(op_pi_async));
runtime runtime
.register_op("nop", |_, _, _| Op::Sync(OpResponse::Value(Box::new(9)))); .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) { fn bench_op_pi_json(b: &mut Bencher) {
bench_runtime_js( bench_runtime_js(
b, b,
r#"for(let i=0; i < 1e3; i++) { 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( bench_runtime_js_async(
b, b,
r#"for(let i=0; i < 1e3; i++) { r#"for(let i=0; i < 1e3; i++) {
Deno.core.jsonOpAsync("pi_async", null); Deno.core.opAsync("pi_async", null);
}"#, }"#,
); );
} }
benchmark_group!( benchmark_group!(benches, bench_op_pi_json, bench_op_nop, bench_op_async);
benches,
bench_op_pi_bin,
bench_op_pi_json,
bench_op_nop,
bench_op_async
);
benchmark_main!(benches); benchmark_main!(benches);

View file

@ -102,7 +102,7 @@
return res; return res;
} }
function jsonOpAsync(opName, args = null, zeroCopy = null) { function opAsync(opName, args = null, zeroCopy = null) {
const promiseId = nextPromiseId++; const promiseId = nextPromiseId++;
const maybeError = dispatch(opName, promiseId, args, zeroCopy); const maybeError = dispatch(opName, promiseId, args, zeroCopy);
// Handle sync error (e.g: error parsing args) // Handle sync error (e.g: error parsing args)
@ -110,31 +110,21 @@
return setPromise(promiseId).then(unwrapOpResult); 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)); 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() { function resources() {
return Object.fromEntries(jsonOpSync("op_resources")); return Object.fromEntries(opSync("op_resources"));
} }
function close(rid) { function close(rid) {
jsonOpSync("op_close", rid); opSync("op_close", rid);
} }
Object.assign(window.Deno.core, { Object.assign(window.Deno.core, {
binOpAsync, opAsync,
binOpSync, opSync,
jsonOpAsync,
jsonOpSync,
dispatch: send, dispatch: send,
dispatchByName: dispatch, dispatchByName: dispatch,
ops, ops,

View file

@ -2,7 +2,7 @@
//! This example shows you how to define ops in Rust and then call them from //! This example shows you how to define ops in Rust and then call them from
//! JavaScript. //! JavaScript.
use deno_core::json_op_sync; use deno_core::op_sync;
use deno_core::JsRuntime; use deno_core::JsRuntime;
use std::io::Write; use std::io::Write;
@ -26,7 +26,7 @@ fn main() {
// The op_fn callback takes a state object OpState, // The op_fn callback takes a state object OpState,
// a structured arg of type `T` and an optional ZeroCopyBuf, // a structured arg of type `T` and an optional ZeroCopyBuf,
// a mutable reference to a JavaScript ArrayBuffer // a mutable reference to a JavaScript ArrayBuffer
json_op_sync(|_state, msg: Option<String>, zero_copy| { op_sync(|_state, msg: Option<String>, zero_copy| {
let mut out = std::io::stdout(); let mut out = std::io::stdout();
// Write msg to stdout // Write msg to stdout
@ -46,10 +46,10 @@ fn main() {
// Register the JSON op for summing a number array. // Register the JSON op for summing a number array.
runtime.register_op( runtime.register_op(
"op_sum", "op_sum",
// The json_op_sync function automatically deserializes // The op_sync function automatically deserializes
// the first ZeroCopyBuf and serializes the return value // the first ZeroCopyBuf and serializes the return value
// to reduce boilerplate // to reduce boilerplate
json_op_sync(|_state, nums: Vec<f64>, _| { op_sync(|_state, nums: Vec<f64>, _| {
// Sum inputs // Sum inputs
let sum = nums.iter().fold(0.0, |a, v| a + v); let sum = nums.iter().fold(0.0, |a, v| a + v);
// return as a Result<f64, AnyError> // return as a Result<f64, AnyError>
@ -91,11 +91,11 @@ const arr = [1, 2, 3];
print("The sum of"); print("The sum of");
print(arr); print(arr);
print("is"); print("is");
print(Deno.core.jsonOpSync('op_sum', arr)); print(Deno.core.opSync('op_sum', arr));
// And incorrect usage // And incorrect usage
try { try {
print(Deno.core.jsonOpSync('op_sum', 0)); print(Deno.core.opSync('op_sum', 0));
} catch(e) { } catch(e) {
print('Exception:'); print('Exception:');
print(e); print(e);

View file

@ -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();

View file

@ -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<Self>) -> Result<TcpStream, Error> {
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>) {
self.cancel.cancel();
}
}
impl TryFrom<std::net::TcpListener> for TcpListener {
type Error = Error;
fn try_from(
std_listener: std::net::TcpListener,
) -> Result<Self, Self::Error> {
tokio::net::TcpListener::try_from(std_listener).map(|tokio_listener| Self {
inner: tokio_listener,
cancel: Default::default(),
})
}
}
struct TcpStream {
rd: AsyncRefCell<tokio::net::tcp::OwnedReadHalf>,
wr: AsyncRefCell<tokio::net::tcp::OwnedWriteHalf>,
// 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<Self>, buf: &mut [u8]) -> Result<usize, Error> {
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<Self>, buf: &[u8]) -> Result<usize, Error> {
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>) {
self.cancel.cancel()
}
}
impl From<tokio::net::TcpStream> 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<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
log::debug!("listen");
let addr = "127.0.0.1:4544".parse::<SocketAddr>().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<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
log::debug!("close rid={}", rid);
state
.resource_table
.close(rid)
.map(|_| 0)
.ok_or_else(bad_resource_id)
}
async fn op_accept(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
_bufs: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
log::debug!("accept rid={}", rid);
let listener = state
.borrow()
.resource_table
.get::<TcpListener>(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<RefCell<OpState>>,
rid: ResourceId,
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let mut buf = buf.ok_or_else(null_opbuf)?;
log::debug!("read rid={}", rid);
let stream = state
.borrow()
.resource_table
.get::<TcpStream>(rid)
.ok_or_else(bad_resource_id)?;
let nread = stream.read(&mut buf).await?;
Ok(nread as u32)
}
async fn op_write(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let buf = buf.ok_or_else(null_opbuf)?;
log::debug!("write rid={}", rid);
let stream = state
.borrow()
.resource_table
.get::<TcpStream>(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();
}

View file

@ -11,12 +11,12 @@ const responseBuf = new Uint8Array(
/** Listens on 0.0.0.0:4500, returns rid. */ /** Listens on 0.0.0.0:4500, returns rid. */
function listen() { function listen() {
return Deno.core.jsonOpSync("listen"); return Deno.core.opSync("listen");
} }
/** Accepts a connection, returns rid. */ /** Accepts a connection, returns rid. */
function accept(serverRid) { 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. * Returns bytes read.
*/ */
function read(rid, data) { 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. */ /** Writes a fixed HTTP response to the socket rid. Returns bytes written. */
function write(rid, data) { function write(rid, data) {
return Deno.core.jsonOpAsync("write", rid, data); return Deno.core.opAsync("write", rid, data);
} }
function close(rid) { function close(rid) {
Deno.core.jsonOpSync("close", rid); Deno.core.opSync("close", rid);
} }
async function serve(rid) { async function serve(rid) {
@ -58,7 +58,7 @@ async function main() {
Deno.core.registerErrorClass("Error", Error); Deno.core.registerErrorClass("Error", Error);
const listenerRid = listen(); 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) { while (true) {
const rid = await accept(listenerRid); const rid = await accept(listenerRid);

View file

@ -111,11 +111,11 @@ impl From<tokio::net::TcpStream> for TcpStream {
fn create_js_runtime() -> JsRuntime { fn create_js_runtime() -> JsRuntime {
let mut runtime = JsRuntime::new(Default::default()); let mut runtime = JsRuntime::new(Default::default());
runtime.register_op("listen", deno_core::json_op_sync(op_listen)); runtime.register_op("listen", deno_core::op_sync(op_listen));
runtime.register_op("close", deno_core::json_op_sync(op_close)); runtime.register_op("close", deno_core::op_sync(op_close));
runtime.register_op("accept", deno_core::json_op_async(op_accept)); runtime.register_op("accept", deno_core::op_async(op_accept));
runtime.register_op("read", deno_core::json_op_async(op_read)); runtime.register_op("read", deno_core::op_async(op_read));
runtime.register_op("write", deno_core::json_op_async(op_write)); runtime.register_op("write", deno_core::op_async(op_write));
runtime runtime
} }

View file

@ -7,15 +7,15 @@
declare namespace Deno { declare namespace Deno {
declare namespace core { declare namespace core {
/** Send a JSON op to Rust, and synchronously receive the result. */ /** Call an op in Rust, and synchronously receive the result. */
function jsonOpSync( function opSync(
opName: string, opName: string,
args?: any, args?: any,
zeroCopy?: Uint8Array, zeroCopy?: Uint8Array,
): any; ): any;
/** Send a JSON op to Rust, and asynchronously receive the result. */ /** Call an op in Rust, and asynchronously receive the result. */
function jsonOpAsync( function opAsync(
opName: string, opName: string,
args?: any, args?: any,
zeroCopy?: Uint8Array, zeroCopy?: Uint8Array,

View file

@ -9,7 +9,6 @@ mod module_specifier;
mod modules; mod modules;
mod normalize_path; mod normalize_path;
mod ops; mod ops;
mod ops_bin;
mod ops_json; mod ops_json;
pub mod plugin_api; pub mod plugin_api;
mod resources; mod resources;
@ -65,11 +64,8 @@ pub use crate::ops::OpResponse;
pub use crate::ops::OpState; pub use crate::ops::OpState;
pub use crate::ops::OpTable; pub use crate::ops::OpTable;
pub use crate::ops::PromiseId; pub use crate::ops::PromiseId;
pub use crate::ops_bin::bin_op_async; pub use crate::ops_json::op_async;
pub use crate::ops_bin::bin_op_sync; pub use crate::ops_json::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::resources::Resource; pub use crate::resources::Resource;
pub use crate::resources::ResourceId; pub use crate::resources::ResourceId;
pub use crate::resources::ResourceTable; pub use crate::resources::ResourceTable;

View file

@ -188,7 +188,7 @@ impl Default for OpTable {
/// Return map of resources with id as key /// Return map of resources with id as key
/// and string representation as value. /// 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( pub fn op_resources(
state: &mut OpState, state: &mut OpState,
_args: (), _args: (),
@ -204,7 +204,7 @@ pub fn op_resources(
/// Remove a resource from the resource table. /// 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( pub fn op_close(
state: &mut OpState, state: &mut OpState,
rid: Option<ResourceId>, rid: Option<ResourceId>,

View file

@ -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<Vec<u8>>;
}
impl ValueOrVector for Vec<u8> {
fn value(&self) -> u32 {
self.len() as u32
}
fn vector(self) -> Option<Vec<u8>> {
Some(self)
}
}
impl ValueOrVector for u32 {
fn value(&self) -> u32 {
*self
}
fn vector(self) -> Option<Vec<u8>> {
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<F, R>(op_fn: F) -> Box<OpFn>
where
F:
Fn(&mut OpState, u32, Option<ZeroCopyBuf>) -> Result<R, AnyError> + '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<R>(
result: Result<R, AnyError>,
state: Rc<RefCell<OpState>>,
) -> 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<RefCell<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.
/// * `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<F, R, RV>(op_fn: F) -> Box<OpFn>
where
F: Fn(Rc<RefCell<OpState>>, u32, Option<ZeroCopyBuf>) -> R + 'static,
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: ValueOrVector,
{
Box::new(
move |state: Rc<RefCell<OpState>>,
p: OpPayload,
b: Option<ZeroCopyBuf>|
-> 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))
},
)
}

View file

@ -25,18 +25,18 @@ use std::rc::Rc;
/// When registering an op like this... /// When registering an op like this...
/// ```ignore /// ```ignore
/// let mut runtime = JsRuntime::new(...); /// 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: /// ...it can be invoked from JS using the provided name, for example:
/// ```js /// ```js
/// Deno.core.ops(); /// 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. /// The `Deno.core.ops()` statement is needed once before any op calls, for initialization.
/// A more complete example is available in the examples directory. /// A more complete example is available in the examples directory.
pub fn json_op_sync<F, V, R>(op_fn: F) -> Box<OpFn> pub fn op_sync<F, V, R>(op_fn: F) -> Box<OpFn>
where where
F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static, F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
V: DeserializeOwned, V: DeserializeOwned,
@ -63,18 +63,18 @@ where
/// When registering an op like this... /// When registering an op like this...
/// ```ignore /// ```ignore
/// let mut runtime = JsRuntime::new(...); /// 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: /// ...it can be invoked from JS using the provided name, for example:
/// ```js /// ```js
/// Deno.core.ops(); /// 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. /// The `Deno.core.ops()` statement is needed once before any op calls, for initialization.
/// A more complete example is available in the examples directory. /// A more complete example is available in the examples directory.
pub fn json_op_async<F, V, R, RV>(op_fn: F) -> Box<OpFn> pub fn op_async<F, V, R, RV>(op_fn: F) -> Box<OpFn>
where where
F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static, F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static,
V: DeserializeOwned, V: DeserializeOwned,
@ -115,7 +115,7 @@ mod tests {
use super::*; use super::*;
#[tokio::test] #[tokio::test]
async fn json_op_async_stack_trace() { async fn op_async_stack_trace() {
let mut runtime = crate::JsRuntime::new(Default::default()); let mut runtime = crate::JsRuntime::new(Default::default());
async fn op_throw( async fn op_throw(
@ -128,7 +128,7 @@ mod tests {
Err(crate::error::generic_error("foo")) 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 runtime
.execute( .execute(
"<init>", "<init>",
@ -139,7 +139,7 @@ mod tests {
Deno.core.registerErrorClass('Error', Error); Deno.core.registerErrorClass('Error', Error);
async function f1() { async function f1() {
await Deno.core.jsonOpAsync('op_throw', 'hello'); await Deno.core.opAsync('op_throw', 'hello');
} }
async function f2() { async function f2() {

View file

@ -438,8 +438,8 @@ impl JsRuntime {
/// ///
/// This function provides byte-level bindings. To pass data via JSON, the /// This function provides byte-level bindings. To pass data via JSON, the
/// following functions can be passed as an argument for `op_fn`: /// following functions can be passed as an argument for `op_fn`:
/// * [json_op_sync()](fn.json_op_sync.html) /// * [op_sync()](fn.op_sync.html)
/// * [json_op_async()](fn.json_op_async.html) /// * [op_async()](fn.op_async.html)
pub fn register_op<F>(&mut self, name: &str, op_fn: F) -> OpId pub fn register_op<F>(&mut self, name: &str, op_fn: F) -> OpId
where where
F: Fn(Rc<RefCell<OpState>>, OpPayload, Option<ZeroCopyBuf>) -> Op + 'static, F: Fn(Rc<RefCell<OpState>>, OpPayload, Option<ZeroCopyBuf>) -> Op + 'static,

View file

@ -37,7 +37,7 @@
arrayBufferView.byteOffset, arrayBufferView.byteOffset,
arrayBufferView.byteLength, arrayBufferView.byteLength,
); );
core.jsonOpSync("op_crypto_get_random_values", null, ui8); core.opSync("op_crypto_get_random_values", null, ui8);
return arrayBufferView; return arrayBufferView;
} }

View file

@ -859,7 +859,7 @@
* @returns {HttpClient} * @returns {HttpClient}
*/ */
function createHttpClient(options) { 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 { class HttpClient {
@ -884,7 +884,7 @@
if (body != null) { if (body != null) {
zeroCopy = new Uint8Array(body.buffer, body.byteOffset, body.byteLength); 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<string,string[]>, url: string, responseRid: number}>} * @returns {Promise<{status: number, statusText: string, headers: Record<string,string[]>, url: string, responseRid: number}>}
*/ */
function opFetchSend(rid) { function opFetchSend(rid) {
return core.jsonOpAsync("op_fetch_send", rid); return core.opAsync("op_fetch_send", rid);
} }
/** /**
@ -906,7 +906,7 @@
body.byteOffset, body.byteOffset,
body.byteLength, 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]; const NULL_BODY_STATUS = [101, 204, 205, 304];
@ -1400,7 +1400,7 @@
async pull(controller) { async pull(controller) {
try { try {
const chunk = new Uint8Array(16 * 1024 + 256); const chunk = new Uint8Array(16 * 1024 + 256);
const read = await core.jsonOpAsync( const read = await core.opAsync(
"op_fetch_response_read", "op_fetch_response_read",
rid, rid,
chunk, chunk,

View file

@ -31,7 +31,7 @@
prefix, prefix,
}); });
const url = core.jsonOpSync( const url = core.opSync(
"op_file_create_object_url", "op_file_create_object_url",
blob.type, blob.type,
blob[_byteSequence], blob[_byteSequence],
@ -52,7 +52,7 @@
prefix, prefix,
}); });
core.jsonOpSync( core.opSync(
"op_file_revoke_object_url", "op_file_revoke_object_url",
url, url,
); );

View file

@ -28,7 +28,7 @@
init = init.slice(1); 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 ( } else if (
Array.isArray(init) || Array.isArray(init) ||
typeof init?.[Symbol.iterator] == "function" typeof init?.[Symbol.iterator] == "function"
@ -64,7 +64,7 @@
return; return;
} }
const parseArgs = { href: url.href, setSearch: this.toString() }; 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) { append(name, value) {
@ -189,7 +189,7 @@
} }
toString() { 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 { } else {
base = base !== undefined ? String(base) : base; base = base !== undefined ? String(base) : base;
const parseArgs = { href: String(url), baseHref: 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 = () => { #updateSearchParams = () => {
if (this.#searchParams != null) { if (this.#searchParams != null) {
const params = paramLists.get(this.#searchParams); const params = paramLists.get(this.#searchParams);
const newParams = core.jsonOpSync( const newParams = core.opSync(
"op_url_parse_search_params", "op_url_parse_search_params",
this.search.slice(1), this.search.slice(1),
); );
@ -245,7 +245,7 @@
set hash(value) { set hash(value) {
try { try {
const parseArgs = { href: this.href, setHash: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -258,7 +258,7 @@
set host(value) { set host(value) {
try { try {
const parseArgs = { href: this.href, setHost: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -271,7 +271,7 @@
set hostname(value) { set hostname(value) {
try { try {
const parseArgs = { href: this.href, setHostname: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -284,7 +284,7 @@
set href(value) { set href(value) {
try { try {
const parseArgs = { href: String(value) }; const parseArgs = { href: String(value) };
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs)); parts.set(this, core.opSync("op_url_parse", parseArgs));
} catch { } catch {
throw new TypeError("Invalid URL"); throw new TypeError("Invalid URL");
} }
@ -302,7 +302,7 @@
set password(value) { set password(value) {
try { try {
const parseArgs = { href: this.href, setPassword: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -315,7 +315,7 @@
set pathname(value) { set pathname(value) {
try { try {
const parseArgs = { href: this.href, setPathname: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -328,7 +328,7 @@
set port(value) { set port(value) {
try { try {
const parseArgs = { href: this.href, setPort: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -341,7 +341,7 @@
set protocol(value) { set protocol(value) {
try { try {
const parseArgs = { href: this.href, setProtocol: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }
@ -354,7 +354,7 @@
set search(value) { set search(value) {
try { try {
const parseArgs = { href: this.href, setSearch: String(value) }; 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(); this.#updateSearchParams();
} catch { } catch {
/* pass */ /* pass */
@ -368,7 +368,7 @@
set username(value) { set username(value) {
try { try {
const parseArgs = { href: this.href, setUsername: String(value) }; 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 { } catch {
/* pass */ /* pass */
} }

View file

@ -155,7 +155,7 @@
context: "Argument 1", context: "Argument 1",
}); });
const { err, ...data } = await core.jsonOpAsync( const { err, ...data } = await core.opAsync(
"op_webgpu_request_adapter", "op_webgpu_request_adapter",
{ ...options }, { ...options },
); );
@ -248,7 +248,7 @@
const nonGuaranteedLimits = descriptor.nonGuaranteedLimits ?? []; const nonGuaranteedLimits = descriptor.nonGuaranteedLimits ?? [];
// TODO(lucacasonato): validate nonGuaranteedLimits // TODO(lucacasonato): validate nonGuaranteedLimits
const { rid, features, limits } = await core.jsonOpAsync( const { rid, features, limits } = await core.opAsync(
"op_webgpu_request_device", "op_webgpu_request_device",
{ {
adapterRid: this[_adapter].rid, adapterRid: this[_adapter].rid,
@ -701,7 +701,7 @@
context: "Argument 1", context: "Argument 1",
}); });
const device = assertDevice(this, { prefix, context: "this" }); 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, deviceRid: device.rid,
...descriptor, ...descriptor,
}); });
@ -748,7 +748,7 @@
context: "Argument 1", context: "Argument 1",
}); });
const device = assertDevice(this, { prefix, context: "this" }); 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, deviceRid: device.rid,
...descriptor, ...descriptor,
size: normalizeGPUExtent3D(descriptor.size), size: normalizeGPUExtent3D(descriptor.size),
@ -776,7 +776,7 @@
context: "Argument 1", context: "Argument 1",
}); });
const device = assertDevice(this, { prefix, context: "this" }); 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, deviceRid: device.rid,
...descriptor, ...descriptor,
}); });
@ -816,7 +816,7 @@
} }
} }
const { rid, err } = core.jsonOpSync( const { rid, err } = core.opSync(
"op_webgpu_create_bind_group_layout", "op_webgpu_create_bind_group_layout",
{ {
deviceRid: device.rid, deviceRid: device.rid,
@ -859,7 +859,7 @@
return rid; 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, deviceRid: device.rid,
label: descriptor.label, label: descriptor.label,
bindGroupLayouts, 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, deviceRid: device.rid,
label: descriptor.label, label: descriptor.label,
layout, layout,
@ -980,7 +980,7 @@
context: "Argument 1", context: "Argument 1",
}); });
const device = assertDevice(this, { prefix, context: "this" }); const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.jsonOpSync( const { rid, err } = core.opSync(
"op_webgpu_create_shader_module", "op_webgpu_create_shader_module",
{ {
deviceRid: device.rid, deviceRid: device.rid,
@ -1038,7 +1038,7 @@
selfContext: "this", selfContext: "this",
}); });
const { rid, err } = core.jsonOpSync( const { rid, err } = core.opSync(
"op_webgpu_create_compute_pipeline", "op_webgpu_create_compute_pipeline",
{ {
deviceRid: device.rid, 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, deviceRid: device.rid,
label: descriptor.label, label: descriptor.label,
layout, layout,
@ -1158,7 +1158,7 @@
context: "Argument 1", context: "Argument 1",
}); });
const device = assertDevice(this, { prefix, context: "this" }); 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, deviceRid: device.rid,
...descriptor, ...descriptor,
}); });
@ -1190,7 +1190,7 @@
}, },
); );
const device = assertDevice(this, { prefix, context: "this" }); const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.jsonOpSync( const { rid, err } = core.opSync(
"op_webgpu_create_render_bundle_encoder", "op_webgpu_create_render_bundle_encoder",
{ {
deviceRid: device.rid, deviceRid: device.rid,
@ -1224,7 +1224,7 @@
}, },
); );
const device = assertDevice(this, { prefix, context: "this" }); 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, deviceRid: device.rid,
...descriptor, ...descriptor,
}); });
@ -1347,7 +1347,7 @@
}); });
return rid; return rid;
}); });
const { err } = core.jsonOpSync("op_webgpu_queue_submit", { const { err } = core.opSync("op_webgpu_queue_submit", {
queueRid: device.rid, queueRid: device.rid,
commandBuffers: commandBufferRids, commandBuffers: commandBufferRids,
}); });
@ -1402,7 +1402,7 @@
selfContext: "this", selfContext: "this",
resourceContext: "Argument 1", resourceContext: "Argument 1",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_write_buffer", "op_webgpu_write_buffer",
{ {
queueRid: device.rid, queueRid: device.rid,
@ -1452,7 +1452,7 @@
selfContext: "this", selfContext: "this",
resourceContext: "texture", resourceContext: "texture",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_write_texture", "op_webgpu_write_texture",
{ {
queueRid: device.rid, queueRid: device.rid,
@ -1652,7 +1652,7 @@
this[_mapMode] = mode; this[_mapMode] = mode;
this[_state] = "mapping pending"; this[_state] = "mapping pending";
const { err } = await core.jsonOpAsync( const { err } = await core.opAsync(
"op_webgpu_buffer_get_map_async", "op_webgpu_buffer_get_map_async",
{ {
bufferRid, bufferRid,
@ -1748,7 +1748,7 @@
} }
const buffer = new ArrayBuffer(rangeSize); const buffer = new ArrayBuffer(rangeSize);
const { rid } = core.jsonOpSync( const { rid } = core.opSync(
"op_webgpu_buffer_get_mapped_range", "op_webgpu_buffer_get_mapped_range",
{ {
bufferRid, bufferRid,
@ -1805,7 +1805,7 @@
throw new DOMException(`${prefix}: invalid state.`, "OperationError"); throw new DOMException(`${prefix}: invalid state.`, "OperationError");
} }
for (const [buffer, mappedRid] of mappedRanges) { for (const [buffer, mappedRid] of mappedRanges) {
const { err } = core.jsonOpSync("op_webgpu_buffer_unmap", { const { err } = core.opSync("op_webgpu_buffer_unmap", {
bufferRid, bufferRid,
mappedRid, mappedRid,
}, ...(write ? [new Uint8Array(buffer)] : [])); }, ...(write ? [new Uint8Array(buffer)] : []));
@ -1943,7 +1943,7 @@
}); });
const device = assertDevice(this, { prefix, context: "this" }); const device = assertDevice(this, { prefix, context: "this" });
const textureRid = assertResource(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, textureRid,
...descriptor, ...descriptor,
}); });
@ -2328,7 +2328,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { rid, label, err } = core.jsonOpSync( const { rid, label, err } = core.opSync(
"op_webgpu_compute_pipeline_get_bind_group_layout", "op_webgpu_compute_pipeline_get_bind_group_layout",
{ computePipelineRid, index }, { computePipelineRid, index },
); );
@ -2403,7 +2403,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { rid, label, err } = core.jsonOpSync( const { rid, label, err } = core.opSync(
"op_webgpu_render_pipeline_get_bind_group_layout", "op_webgpu_render_pipeline_get_bind_group_layout",
{ renderPipelineRid, index }, { renderPipelineRid, index },
); );
@ -2628,7 +2628,7 @@
}, },
); );
const { rid } = core.jsonOpSync( const { rid } = core.opSync(
"op_webgpu_command_encoder_begin_render_pass", "op_webgpu_command_encoder_begin_render_pass",
{ {
commandEncoderRid, commandEncoderRid,
@ -2665,7 +2665,7 @@
context: "this", context: "this",
}); });
const { rid } = core.jsonOpSync( const { rid } = core.opSync(
"op_webgpu_command_encoder_begin_compute_pass", "op_webgpu_command_encoder_begin_compute_pass",
{ {
commandEncoderRid, commandEncoderRid,
@ -2744,7 +2744,7 @@
selfContext: "this", selfContext: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_copy_buffer_to_buffer", "op_webgpu_command_encoder_copy_buffer_to_buffer",
{ {
commandEncoderRid, commandEncoderRid,
@ -2804,7 +2804,7 @@
selfContext: "this", selfContext: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_copy_buffer_to_texture", "op_webgpu_command_encoder_copy_buffer_to_texture",
{ {
commandEncoderRid, commandEncoderRid,
@ -2870,7 +2870,7 @@
resourceContext: "buffer in Argument 2", resourceContext: "buffer in Argument 2",
selfContext: "this", selfContext: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_copy_texture_to_buffer", "op_webgpu_command_encoder_copy_texture_to_buffer",
{ {
commandEncoderRid, commandEncoderRid,
@ -2936,7 +2936,7 @@
resourceContext: "texture in Argument 2", resourceContext: "texture in Argument 2",
selfContext: "this", selfContext: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_copy_texture_to_texture", "op_webgpu_command_encoder_copy_texture_to_texture",
{ {
commandEncoderRid, commandEncoderRid,
@ -2977,7 +2977,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_push_debug_group", "op_webgpu_command_encoder_push_debug_group",
{ {
commandEncoderRid, commandEncoderRid,
@ -2995,7 +2995,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_pop_debug_group", "op_webgpu_command_encoder_pop_debug_group",
{ {
commandEncoderRid, commandEncoderRid,
@ -3021,7 +3021,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_insert_debug_marker", "op_webgpu_command_encoder_insert_debug_marker",
{ {
commandEncoderRid, commandEncoderRid,
@ -3062,7 +3062,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_write_timestamp", "op_webgpu_command_encoder_write_timestamp",
{ {
commandEncoderRid, commandEncoderRid,
@ -3134,7 +3134,7 @@
resourceContext: "Argument 3", resourceContext: "Argument 3",
selfContext: "this", selfContext: "this",
}); });
const { err } = core.jsonOpSync( const { err } = core.opSync(
"op_webgpu_command_encoder_resolve_query_set", "op_webgpu_command_encoder_resolve_query_set",
{ {
commandEncoderRid, commandEncoderRid,
@ -3164,7 +3164,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { rid, err } = core.jsonOpSync("op_webgpu_command_encoder_finish", { const { rid, err } = core.opSync("op_webgpu_command_encoder_finish", {
commandEncoderRid, commandEncoderRid,
...descriptor, ...descriptor,
}); });
@ -3264,7 +3264,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
x, x,
y, y,
@ -3312,7 +3312,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
x, x,
y, y,
@ -3342,7 +3342,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
color: normalizeGPUColor(color), color: normalizeGPUColor(color),
}); });
@ -3369,7 +3369,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
reference, reference,
}); });
@ -3418,7 +3418,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_begin_pipeline_statistics_query", { core.opSync("op_webgpu_render_pass_begin_pipeline_statistics_query", {
renderPassRid, renderPassRid,
querySet: querySetRid, querySet: querySetRid,
queryIndex, queryIndex,
@ -3438,7 +3438,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
}); });
} }
@ -3478,7 +3478,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_write_timestamp", { core.opSync("op_webgpu_render_pass_write_timestamp", {
renderPassRid, renderPassRid,
querySet: querySetRid, querySet: querySetRid,
queryIndex, queryIndex,
@ -3516,7 +3516,7 @@
}); });
return rid; return rid;
}); });
core.jsonOpSync("op_webgpu_render_pass_execute_bundles", { core.opSync("op_webgpu_render_pass_execute_bundles", {
renderPassRid, renderPassRid,
bundles: bundleRids, bundles: bundleRids,
}); });
@ -3534,7 +3534,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, commandEncoderRid,
renderPassRid, renderPassRid,
}); });
@ -3572,7 +3572,7 @@
selfContext: "this", selfContext: "this",
}); });
if (dynamicOffsetsData instanceof Uint32Array) { if (dynamicOffsetsData instanceof Uint32Array) {
core.jsonOpSync( core.opSync(
"op_webgpu_render_pass_set_bind_group", "op_webgpu_render_pass_set_bind_group",
{ {
renderPassRid, renderPassRid,
@ -3585,7 +3585,7 @@
); );
} else { } else {
dynamicOffsetsData ??= []; dynamicOffsetsData ??= [];
core.jsonOpSync("op_webgpu_render_pass_set_bind_group", { core.opSync("op_webgpu_render_pass_set_bind_group", {
renderPassRid, renderPassRid,
index, index,
bindGroup: bindGroupRid, bindGroup: bindGroupRid,
@ -3617,7 +3617,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
groupLabel, groupLabel,
}); });
@ -3636,7 +3636,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
}); });
} }
@ -3662,7 +3662,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
markerLabel, markerLabel,
}); });
@ -3698,7 +3698,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_set_pipeline", { core.opSync("op_webgpu_render_pass_set_pipeline", {
renderPassRid, renderPassRid,
pipeline: pipelineRid, pipeline: pipelineRid,
}); });
@ -3749,7 +3749,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_set_index_buffer", { core.opSync("op_webgpu_render_pass_set_index_buffer", {
renderPassRid, renderPassRid,
buffer: bufferRid, buffer: bufferRid,
indexFormat, indexFormat,
@ -3803,7 +3803,7 @@
resourceContext: "Argument 2", resourceContext: "Argument 2",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_set_vertex_buffer", { core.opSync("op_webgpu_render_pass_set_vertex_buffer", {
renderPassRid, renderPassRid,
slot, slot,
buffer: bufferRid, buffer: bufferRid,
@ -3847,7 +3847,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "this" }); const renderPassRid = assertResource(this, { prefix, context: "this" });
core.jsonOpSync("op_webgpu_render_pass_draw", { core.opSync("op_webgpu_render_pass_draw", {
renderPassRid, renderPassRid,
vertexCount, vertexCount,
instanceCount, instanceCount,
@ -3903,7 +3903,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const renderPassRid = assertResource(this, { prefix, context: "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, renderPassRid,
indexCount, indexCount,
instanceCount, instanceCount,
@ -3948,7 +3948,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_draw_indirect", { core.opSync("op_webgpu_render_pass_draw_indirect", {
renderPassRid, renderPassRid,
indirectBuffer: indirectBufferRid, indirectBuffer: indirectBufferRid,
indirectOffset, indirectOffset,
@ -3990,7 +3990,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_pass_draw_indexed_indirect", { core.opSync("op_webgpu_render_pass_draw_indexed_indirect", {
renderPassRid, renderPassRid,
indirectBuffer: indirectBufferRid, indirectBuffer: indirectBufferRid,
indirectOffset, indirectOffset,
@ -4072,7 +4072,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_compute_pass_set_pipeline", { core.opSync("op_webgpu_compute_pass_set_pipeline", {
computePassRid, computePassRid,
pipeline: pipelineRid, pipeline: pipelineRid,
}); });
@ -4099,7 +4099,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const computePassRid = assertResource(this, { prefix, context: "this" }); const computePassRid = assertResource(this, { prefix, context: "this" });
core.jsonOpSync("op_webgpu_compute_pass_dispatch", { core.opSync("op_webgpu_compute_pass_dispatch", {
computePassRid, computePassRid,
x, x,
y, y,
@ -4142,7 +4142,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_compute_pass_dispatch_indirect", { core.opSync("op_webgpu_compute_pass_dispatch_indirect", {
computePassRid: computePassRid, computePassRid: computePassRid,
indirectBuffer: indirectBufferRid, indirectBuffer: indirectBufferRid,
indirectOffset, indirectOffset,
@ -4184,7 +4184,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync( core.opSync(
"op_webgpu_compute_pass_begin_pipeline_statistics_query", "op_webgpu_compute_pass_begin_pipeline_statistics_query",
{ {
computePassRid, computePassRid,
@ -4207,7 +4207,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const computePassRid = assertResource(this, { prefix, context: "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, computePassRid,
}); });
} }
@ -4247,7 +4247,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_compute_pass_write_timestamp", { core.opSync("op_webgpu_compute_pass_write_timestamp", {
computePassRid, computePassRid,
querySet: querySetRid, querySet: querySetRid,
queryIndex, queryIndex,
@ -4266,7 +4266,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const computePassRid = assertResource(this, { prefix, context: "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, commandEncoderRid,
computePassRid, computePassRid,
}); });
@ -4304,7 +4304,7 @@
selfContext: "this", selfContext: "this",
}); });
if (dynamicOffsetsData instanceof Uint32Array) { if (dynamicOffsetsData instanceof Uint32Array) {
core.jsonOpSync( core.opSync(
"op_webgpu_compute_pass_set_bind_group", "op_webgpu_compute_pass_set_bind_group",
{ {
computePassRid, computePassRid,
@ -4317,7 +4317,7 @@
); );
} else { } else {
dynamicOffsetsData ??= []; dynamicOffsetsData ??= [];
core.jsonOpSync("op_webgpu_compute_pass_set_bind_group", { core.opSync("op_webgpu_compute_pass_set_bind_group", {
computePassRid, computePassRid,
index, index,
bindGroup: bindGroupRid, bindGroup: bindGroupRid,
@ -4349,7 +4349,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const computePassRid = assertResource(this, { prefix, context: "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, computePassRid,
groupLabel, groupLabel,
}); });
@ -4368,7 +4368,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const computePassRid = assertResource(this, { prefix, context: "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, computePassRid,
}); });
} }
@ -4394,7 +4394,7 @@
context: "encoder referenced by this", context: "encoder referenced by this",
}); });
const computePassRid = assertResource(this, { prefix, context: "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, computePassRid,
markerLabel, markerLabel,
}); });
@ -4508,7 +4508,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
const { rid, err } = core.jsonOpSync( const { rid, err } = core.opSync(
"op_webgpu_render_bundle_encoder_finish", "op_webgpu_render_bundle_encoder_finish",
{ {
renderBundleEncoderRid, renderBundleEncoderRid,
@ -4553,7 +4553,7 @@
selfContext: "this", selfContext: "this",
}); });
if (dynamicOffsetsData instanceof Uint32Array) { if (dynamicOffsetsData instanceof Uint32Array) {
core.jsonOpSync( core.opSync(
"op_webgpu_render_bundle_encoder_set_bind_group", "op_webgpu_render_bundle_encoder_set_bind_group",
{ {
renderBundleEncoderRid, renderBundleEncoderRid,
@ -4566,7 +4566,7 @@
); );
} else { } else {
dynamicOffsetsData ??= []; dynamicOffsetsData ??= [];
core.jsonOpSync("op_webgpu_render_bundle_encoder_set_bind_group", { core.opSync("op_webgpu_render_bundle_encoder_set_bind_group", {
renderBundleEncoderRid, renderBundleEncoderRid,
index, index,
bindGroup: bindGroupRid, bindGroup: bindGroupRid,
@ -4594,7 +4594,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_push_debug_group", { core.opSync("op_webgpu_render_bundle_encoder_push_debug_group", {
renderBundleEncoderRid, renderBundleEncoderRid,
groupLabel, groupLabel,
}); });
@ -4609,7 +4609,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_pop_debug_group", { core.opSync("op_webgpu_render_bundle_encoder_pop_debug_group", {
renderBundleEncoderRid, renderBundleEncoderRid,
}); });
} }
@ -4631,7 +4631,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_push_debug_group", { core.opSync("op_webgpu_render_bundle_encoder_push_debug_group", {
renderBundleEncoderRid, renderBundleEncoderRid,
markerLabel, markerLabel,
}); });
@ -4663,7 +4663,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_set_pipeline", { core.opSync("op_webgpu_render_bundle_encoder_set_pipeline", {
renderBundleEncoderRid, renderBundleEncoderRid,
pipeline: pipelineRid, pipeline: pipelineRid,
}); });
@ -4710,7 +4710,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_set_index_buffer", { core.opSync("op_webgpu_render_bundle_encoder_set_index_buffer", {
renderBundleEncoderRid, renderBundleEncoderRid,
buffer: bufferRid, buffer: bufferRid,
indexFormat, indexFormat,
@ -4760,7 +4760,7 @@
resourceContext: "Argument 2", resourceContext: "Argument 2",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_set_vertex_buffer", { core.opSync("op_webgpu_render_bundle_encoder_set_vertex_buffer", {
renderBundleEncoderRid, renderBundleEncoderRid,
slot, slot,
buffer: bufferRid, buffer: bufferRid,
@ -4800,7 +4800,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_draw", { core.opSync("op_webgpu_render_bundle_encoder_draw", {
renderBundleEncoderRid, renderBundleEncoderRid,
vertexCount, vertexCount,
instanceCount, instanceCount,
@ -4852,7 +4852,7 @@
prefix, prefix,
context: "this", context: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_draw_indexed", { core.opSync("op_webgpu_render_bundle_encoder_draw_indexed", {
renderBundleEncoderRid, renderBundleEncoderRid,
indexCount, indexCount,
instanceCount, instanceCount,
@ -4893,7 +4893,7 @@
resourceContext: "Argument 1", resourceContext: "Argument 1",
selfContext: "this", selfContext: "this",
}); });
core.jsonOpSync("op_webgpu_render_bundle_encoder_draw_indirect", { core.opSync("op_webgpu_render_bundle_encoder_draw_indirect", {
renderBundleEncoderRid, renderBundleEncoderRid,
indirectBuffer: indirectBufferRid, indirectBuffer: indirectBufferRid,
indirectOffset, indirectOffset,

View file

@ -99,7 +99,7 @@
this.#url = wsURL.href; 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") { if (protocols && typeof protocols === "string") {
protocols = [protocols]; protocols = [protocols];
@ -114,7 +114,7 @@
); );
} }
core.jsonOpAsync("op_ws_create", { core.opAsync("op_ws_create", {
url: wsURL.href, url: wsURL.href,
protocols: protocols.join(", "), protocols: protocols.join(", "),
}).then((create) => { }).then((create) => {
@ -124,7 +124,7 @@
this.#protocol = create.protocol; this.#protocol = create.protocol;
if (this.#readyState === CLOSING) { if (this.#readyState === CLOSING) {
core.jsonOpAsync("op_ws_close", { core.opAsync("op_ws_close", {
rid: this.#rid, rid: this.#rid,
}).then(() => { }).then(() => {
this.#readyState = CLOSED; this.#readyState = CLOSED;
@ -229,7 +229,7 @@
const sendTypedArray = (ta) => { const sendTypedArray = (ta) => {
this.#bufferedAmount += ta.size; this.#bufferedAmount += ta.size;
core.jsonOpAsync("op_ws_send", { core.opAsync("op_ws_send", {
rid: this.#rid, rid: this.#rid,
kind: "binary", kind: "binary",
}, ta).then(() => { }, ta).then(() => {
@ -256,7 +256,7 @@
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const d = encoder.encode(string); const d = encoder.encode(string);
this.#bufferedAmount += d.size; this.#bufferedAmount += d.size;
core.jsonOpAsync("op_ws_send", { core.opAsync("op_ws_send", {
rid: this.#rid, rid: this.#rid,
kind: "text", kind: "text",
text: string, text: string,
@ -287,7 +287,7 @@
} else if (this.#readyState === OPEN) { } else if (this.#readyState === OPEN) {
this.#readyState = CLOSING; this.#readyState = CLOSING;
core.jsonOpAsync("op_ws_close", { core.opAsync("op_ws_close", {
rid: this.#rid, rid: this.#rid,
code, code,
reason, reason,
@ -307,7 +307,7 @@
async #eventLoop() { async #eventLoop() {
while (this.#readyState === OPEN) { while (this.#readyState === OPEN) {
const message = await core.jsonOpAsync( const message = await core.opAsync(
"op_ws_next_event", "op_ws_next_event",
this.#rid, this.#rid,
); );
@ -344,7 +344,7 @@
} }
case "ping": case "ping":
core.jsonOpAsync("op_ws_send", { core.opAsync("op_ws_send", {
rid: this.#rid, rid: this.#rid,
kind: "pong", kind: "pong",
}); });

View file

@ -6,23 +6,23 @@
const core = window.Deno.core; const core = window.Deno.core;
function opStopGlobalTimer() { function opStopGlobalTimer() {
core.jsonOpSync("op_global_timer_stop"); core.opSync("op_global_timer_stop");
} }
function opStartGlobalTimer(timeout) { function opStartGlobalTimer(timeout) {
return core.jsonOpSync("op_global_timer_start", timeout); return core.opSync("op_global_timer_start", timeout);
} }
async function opWaitGlobalTimer() { async function opWaitGlobalTimer() {
await core.jsonOpAsync("op_global_timer"); await core.opAsync("op_global_timer");
} }
function opNow() { function opNow() {
return core.jsonOpSync("op_now"); return core.opSync("op_now");
} }
function sleepSync(millis = 0) { 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. // Derived from https://github.com/vadimg/js_bintrees. MIT Licensed.

View file

@ -17,7 +17,7 @@
permissions, permissions,
name, name,
) { ) {
return core.jsonOpSync("op_create_worker", { return core.opSync("op_create_worker", {
hasSourceCode, hasSourceCode,
name, name,
permissions, permissions,
@ -28,15 +28,15 @@
} }
function hostTerminateWorker(id) { function hostTerminateWorker(id) {
core.jsonOpSync("op_host_terminate_worker", id); core.opSync("op_host_terminate_worker", id);
} }
function hostPostMessage(id, data) { function hostPostMessage(id, data) {
core.jsonOpSync("op_host_post_message", id, data); core.opSync("op_host_post_message", id, data);
} }
function hostGetMessage(id) { function hostGetMessage(id) {
return core.jsonOpAsync("op_host_get_message", id); return core.opAsync("op_host_get_message", id);
} }
const encoder = new TextEncoder(); const encoder = new TextEncoder();
@ -268,7 +268,7 @@
if (globalThis instanceof Window) { if (globalThis instanceof Window) {
throw new Error("Unhandled error event reached main worker."); throw new Error("Unhandled error event reached main worker.");
} else { } else {
core.jsonOpSync( core.opSync(
"op_host_unhandled_error", "op_host_unhandled_error",
event.error.message, event.error.message,
); );
@ -287,7 +287,7 @@
if (globalThis instanceof Window) { if (globalThis instanceof Window) {
throw new Error("Unhandled error event reached main worker."); throw new Error("Unhandled error event reached main worker.");
} else { } else {
core.jsonOpSync( core.opSync(
"op_host_unhandled_error", "op_host_unhandled_error",
event.error.message, event.error.message,
); );

View file

@ -81,7 +81,7 @@
return 0; 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; return nread === 0 ? null : nread;
} }
@ -94,17 +94,17 @@
return 0; 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; return nread === 0 ? null : nread;
} }
function writeSync(rid, data) { 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) { 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; const READ_PER_ITER = 32 * 1024;

View file

@ -7,11 +7,11 @@
const build = window.__bootstrap.build.build; const build = window.__bootstrap.build.build;
function chmodSync(path, mode) { 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) { 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( function chownSync(
@ -19,7 +19,7 @@
uid, uid,
gid, gid,
) { ) {
core.jsonOpSync("op_chown_sync", { path: pathFromURL(path), uid, gid }); core.opSync("op_chown_sync", { path: pathFromURL(path), uid, gid });
} }
async function chown( async function chown(
@ -27,7 +27,7 @@
uid, uid,
gid, gid,
) { ) {
await core.jsonOpAsync( await core.opAsync(
"op_chown_async", "op_chown_async",
{ path: pathFromURL(path), uid, gid }, { path: pathFromURL(path), uid, gid },
); );
@ -37,7 +37,7 @@
fromPath, fromPath,
toPath, toPath,
) { ) {
core.jsonOpSync("op_copy_file_sync", { core.opSync("op_copy_file_sync", {
from: pathFromURL(fromPath), from: pathFromURL(fromPath),
to: pathFromURL(toPath), to: pathFromURL(toPath),
}); });
@ -47,34 +47,34 @@
fromPath, fromPath,
toPath, toPath,
) { ) {
await core.jsonOpAsync("op_copy_file_async", { await core.opAsync("op_copy_file_async", {
from: pathFromURL(fromPath), from: pathFromURL(fromPath),
to: pathFromURL(toPath), to: pathFromURL(toPath),
}); });
} }
function cwd() { function cwd() {
return core.jsonOpSync("op_cwd"); return core.opSync("op_cwd");
} }
function chdir(directory) { function chdir(directory) {
core.jsonOpSync("op_chdir", directory); core.opSync("op_chdir", directory);
} }
function makeTempDirSync(options = {}) { function makeTempDirSync(options = {}) {
return core.jsonOpSync("op_make_temp_dir_sync", options); return core.opSync("op_make_temp_dir_sync", options);
} }
function makeTempDir(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 = {}) { function makeTempFileSync(options = {}) {
return core.jsonOpSync("op_make_temp_file_sync", options); return core.opSync("op_make_temp_file_sync", options);
} }
function makeTempFile(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) { function mkdirArgs(path, options) {
@ -91,24 +91,24 @@
} }
function mkdirSync(path, options) { function mkdirSync(path, options) {
core.jsonOpSync("op_mkdir_sync", mkdirArgs(path, options)); core.opSync("op_mkdir_sync", mkdirArgs(path, options));
} }
async function mkdir( async function mkdir(
path, path,
options, options,
) { ) {
await core.jsonOpAsync("op_mkdir_async", mkdirArgs(path, options)); await core.opAsync("op_mkdir_async", mkdirArgs(path, options));
} }
function readDirSync(path) { function readDirSync(path) {
return core.jsonOpSync("op_read_dir_sync", pathFromURL(path))[ return core.opSync("op_read_dir_sync", pathFromURL(path))[
Symbol.iterator Symbol.iterator
](); ]();
} }
function readDir(path) { function readDir(path) {
const array = core.jsonOpAsync( const array = core.opAsync(
"op_read_dir_async", "op_read_dir_async",
pathFromURL(path), pathFromURL(path),
); );
@ -120,26 +120,26 @@
} }
function readLinkSync(path) { function readLinkSync(path) {
return core.jsonOpSync("op_read_link_sync", pathFromURL(path)); return core.opSync("op_read_link_sync", pathFromURL(path));
} }
function readLink(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) { function realPathSync(path) {
return core.jsonOpSync("op_realpath_sync", path); return core.opSync("op_realpath_sync", path);
} }
function realPath(path) { function realPath(path) {
return core.jsonOpAsync("op_realpath_async", path); return core.opAsync("op_realpath_async", path);
} }
function removeSync( function removeSync(
path, path,
options = {}, options = {},
) { ) {
core.jsonOpSync("op_remove_sync", { core.opSync("op_remove_sync", {
path: pathFromURL(path), path: pathFromURL(path),
recursive: !!options.recursive, recursive: !!options.recursive,
}); });
@ -149,18 +149,18 @@
path, path,
options = {}, options = {},
) { ) {
await core.jsonOpAsync("op_remove_async", { await core.opAsync("op_remove_async", {
path: pathFromURL(path), path: pathFromURL(path),
recursive: !!options.recursive, recursive: !!options.recursive,
}); });
} }
function renameSync(oldpath, newpath) { function renameSync(oldpath, newpath) {
core.jsonOpSync("op_rename_sync", { oldpath, newpath }); core.opSync("op_rename_sync", { oldpath, newpath });
} }
async function rename(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) { function parseFileInfo(response) {
@ -189,15 +189,15 @@
} }
function fstatSync(rid) { function fstatSync(rid) {
return parseFileInfo(core.jsonOpSync("op_fstat_sync", rid)); return parseFileInfo(core.opSync("op_fstat_sync", rid));
} }
async function fstat(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) { async function lstat(path) {
const res = await core.jsonOpAsync("op_stat_async", { const res = await core.opAsync("op_stat_async", {
path: pathFromURL(path), path: pathFromURL(path),
lstat: true, lstat: true,
}); });
@ -205,7 +205,7 @@
} }
function lstatSync(path) { function lstatSync(path) {
const res = core.jsonOpSync("op_stat_sync", { const res = core.opSync("op_stat_sync", {
path: pathFromURL(path), path: pathFromURL(path),
lstat: true, lstat: true,
}); });
@ -213,7 +213,7 @@
} }
async function stat(path) { async function stat(path) {
const res = await core.jsonOpAsync("op_stat_async", { const res = await core.opAsync("op_stat_async", {
path: pathFromURL(path), path: pathFromURL(path),
lstat: false, lstat: false,
}); });
@ -221,7 +221,7 @@
} }
function statSync(path) { function statSync(path) {
const res = core.jsonOpSync("op_stat_sync", { const res = core.opSync("op_stat_sync", {
path: pathFromURL(path), path: pathFromURL(path),
lstat: false, lstat: false,
}); });
@ -237,31 +237,31 @@
} }
function ftruncateSync(rid, len) { 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) { 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) { 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) { 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) { function umask(mask) {
return core.jsonOpSync("op_umask", mask); return core.opSync("op_umask", mask);
} }
function linkSync(oldpath, newpath) { function linkSync(oldpath, newpath) {
core.jsonOpSync("op_link_sync", { oldpath, newpath }); core.opSync("op_link_sync", { oldpath, newpath });
} }
async function link(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) { function toUnixTimeFromEpoch(value) {
@ -290,7 +290,7 @@
atime, atime,
mtime, mtime,
) { ) {
core.jsonOpSync("op_futime_sync", { core.opSync("op_futime_sync", {
rid, rid,
atime: toUnixTimeFromEpoch(atime), atime: toUnixTimeFromEpoch(atime),
mtime: toUnixTimeFromEpoch(mtime), mtime: toUnixTimeFromEpoch(mtime),
@ -302,7 +302,7 @@
atime, atime,
mtime, mtime,
) { ) {
await core.jsonOpAsync("op_futime_async", { await core.opAsync("op_futime_async", {
rid, rid,
atime: toUnixTimeFromEpoch(atime), atime: toUnixTimeFromEpoch(atime),
mtime: toUnixTimeFromEpoch(mtime), mtime: toUnixTimeFromEpoch(mtime),
@ -314,7 +314,7 @@
atime, atime,
mtime, mtime,
) { ) {
core.jsonOpSync("op_utime_sync", { core.opSync("op_utime_sync", {
path, path,
atime: toUnixTimeFromEpoch(atime), atime: toUnixTimeFromEpoch(atime),
mtime: toUnixTimeFromEpoch(mtime), mtime: toUnixTimeFromEpoch(mtime),
@ -326,7 +326,7 @@
atime, atime,
mtime, mtime,
) { ) {
await core.jsonOpAsync("op_utime_async", { await core.opAsync("op_utime_async", {
path, path,
atime: toUnixTimeFromEpoch(atime), atime: toUnixTimeFromEpoch(atime),
mtime: toUnixTimeFromEpoch(mtime), mtime: toUnixTimeFromEpoch(mtime),
@ -338,7 +338,7 @@
newpath, newpath,
options, options,
) { ) {
core.jsonOpSync("op_symlink_sync", { oldpath, newpath, options }); core.opSync("op_symlink_sync", { oldpath, newpath, options });
} }
async function symlink( async function symlink(
@ -346,23 +346,23 @@
newpath, newpath,
options, options,
) { ) {
await core.jsonOpAsync("op_symlink_async", { oldpath, newpath, options }); await core.opAsync("op_symlink_async", { oldpath, newpath, options });
} }
function fdatasyncSync(rid) { function fdatasyncSync(rid) {
core.jsonOpSync("op_fdatasync_sync", rid); core.opSync("op_fdatasync_sync", rid);
} }
async function fdatasync(rid) { async function fdatasync(rid) {
await core.jsonOpAsync("op_fdatasync_async", rid); await core.opAsync("op_fdatasync_async", rid);
} }
function fsyncSync(rid) { function fsyncSync(rid) {
core.jsonOpSync("op_fsync_sync", rid); core.opSync("op_fsync_sync", rid);
} }
async function fsync(rid) { async function fsync(rid) {
await core.jsonOpAsync("op_fsync_async", rid); await core.opAsync("op_fsync_async", rid);
} }
window.__bootstrap.fs = { window.__bootstrap.fs = {

View file

@ -5,7 +5,7 @@
const core = window.Deno.core; const core = window.Deno.core;
function metrics() { function metrics() {
const { combined, ops } = core.jsonOpSync("op_metrics"); const { combined, ops } = core.opSync("op_metrics");
if (ops) { if (ops) {
combined.ops = ops; combined.ops = ops;
} }

View file

@ -7,23 +7,23 @@
const { read, write } = window.__bootstrap.io; const { read, write } = window.__bootstrap.io;
function shutdown(rid) { function shutdown(rid) {
return core.jsonOpAsync("op_shutdown", rid); return core.opAsync("op_shutdown", rid);
} }
function opAccept(rid, transport) { function opAccept(rid, transport) {
return core.jsonOpAsync("op_accept", { rid, transport }); return core.opAsync("op_accept", { rid, transport });
} }
function opListen(args) { function opListen(args) {
return core.jsonOpSync("op_listen", args); return core.opSync("op_listen", args);
} }
function opConnect(args) { function opConnect(args) {
return core.jsonOpAsync("op_connect", args); return core.opAsync("op_connect", args);
} }
function opReceive(rid, transport, zeroCopy) { function opReceive(rid, transport, zeroCopy) {
return core.jsonOpAsync( return core.opAsync(
"op_datagram_receive", "op_datagram_receive",
{ rid, transport }, { rid, transport },
zeroCopy, zeroCopy,
@ -31,11 +31,11 @@
} }
function opSend(args, zeroCopy) { 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) { 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 { class Conn {

View file

@ -5,23 +5,23 @@
const core = window.Deno.core; const core = window.Deno.core;
function loadavg() { function loadavg() {
return core.jsonOpSync("op_loadavg"); return core.opSync("op_loadavg");
} }
function hostname() { function hostname() {
return core.jsonOpSync("op_hostname"); return core.opSync("op_hostname");
} }
function osRelease() { function osRelease() {
return core.jsonOpSync("op_os_release"); return core.opSync("op_os_release");
} }
function systemMemoryInfo() { function systemMemoryInfo() {
return core.jsonOpSync("op_system_memory_info"); return core.opSync("op_system_memory_info");
} }
function systemCpuInfo() { 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 // Map nulls to undefined for compatibility
return { return {
cores: cores ?? undefined, cores: cores ?? undefined,
@ -49,33 +49,33 @@
return; return;
} }
core.jsonOpSync("op_exit", code); core.opSync("op_exit", code);
throw new Error("Code not reachable"); throw new Error("Code not reachable");
} }
function setEnv(key, value) { function setEnv(key, value) {
core.jsonOpSync("op_set_env", { key, value }); core.opSync("op_set_env", { key, value });
} }
function getEnv(key) { function getEnv(key) {
return core.jsonOpSync("op_get_env", key) ?? undefined; return core.opSync("op_get_env", key) ?? undefined;
} }
function deleteEnv(key) { function deleteEnv(key) {
core.jsonOpSync("op_delete_env", key); core.opSync("op_delete_env", key);
} }
const env = { const env = {
get: getEnv, get: getEnv,
toObject() { toObject() {
return core.jsonOpSync("op_env"); return core.opSync("op_env");
}, },
set: setEnv, set: setEnv,
delete: deleteEnv, delete: deleteEnv,
}; };
function execPath() { function execPath() {
return core.jsonOpSync("op_exec_path"); return core.opSync("op_exec_path");
} }
window.__bootstrap.os = { window.__bootstrap.os = {

View file

@ -39,7 +39,7 @@
* @returns {Promise<OpEmitResponse>} * @returns {Promise<OpEmitResponse>}
*/ */
function opEmit(request) { function opEmit(request) {
return core.jsonOpAsync("op_emit", request); return core.opAsync("op_emit", request);
} }
/** /**

View file

@ -5,11 +5,11 @@
const core = window.Deno.core; const core = window.Deno.core;
function opFormatDiagnostics(diagnostics) { function opFormatDiagnostics(diagnostics) {
return core.jsonOpSync("op_format_diagnostic", diagnostics); return core.opSync("op_format_diagnostic", diagnostics);
} }
function opApplySourceMap(location) { function opApplySourceMap(location) {
const res = core.jsonOpSync("op_apply_source_map", location); const res = core.opSync("op_apply_source_map", location);
return { return {
fileName: res.fileName, fileName: res.fileName,
lineNumber: res.lineNumber, lineNumber: res.lineNumber,

View file

@ -12,7 +12,7 @@
offset, offset,
whence, whence,
) { ) {
return core.jsonOpSync("op_seek_sync", { rid, offset, whence }); return core.opSync("op_seek_sync", { rid, offset, whence });
} }
function seek( function seek(
@ -20,7 +20,7 @@
offset, offset,
whence, whence,
) { ) {
return core.jsonOpAsync("op_seek_async", { rid, offset, whence }); return core.opAsync("op_seek_async", { rid, offset, whence });
} }
function openSync( function openSync(
@ -29,7 +29,7 @@
) { ) {
checkOpenOptions(options); checkOpenOptions(options);
const mode = options?.mode; const mode = options?.mode;
const rid = core.jsonOpSync( const rid = core.opSync(
"op_open_sync", "op_open_sync",
{ path: pathFromURL(path), options, mode }, { path: pathFromURL(path), options, mode },
); );
@ -43,7 +43,7 @@
) { ) {
checkOpenOptions(options); checkOpenOptions(options);
const mode = options?.mode; const mode = options?.mode;
const rid = await core.jsonOpAsync( const rid = await core.opAsync(
"op_open_async", "op_open_async",
{ path: pathFromURL(path), options, mode }, { path: pathFromURL(path), options, mode },
); );

View file

@ -10,7 +10,7 @@
constructor(paths, options) { constructor(paths, options) {
const { recursive } = 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() { get rid() {
@ -19,7 +19,7 @@
async next() { async next() {
try { 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 return value
? { value, done: false } ? { value, done: false }
: { value: undefined, done: true }; : { value: undefined, done: true };

View file

@ -10,7 +10,7 @@
const { ReadableStream } = window.__bootstrap.streams; const { ReadableStream } = window.__bootstrap.streams;
function serveHttp(conn) { 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); return new HttpConn(rid);
} }
@ -30,7 +30,7 @@
async nextRequest() { async nextRequest() {
let nextRequest; let nextRequest;
try { try {
nextRequest = await Deno.core.jsonOpAsync( nextRequest = await Deno.core.opAsync(
"op_http_request_next", "op_http_request_next",
this.#rid, this.#rid,
); );
@ -88,7 +88,7 @@
} }
function readRequest(requestRid, zeroCopyBuf) { function readRequest(requestRid, zeroCopyBuf) {
return Deno.core.jsonOpAsync( return Deno.core.opAsync(
"op_http_request_read", "op_http_request_read",
requestRid, requestRid,
zeroCopyBuf, zeroCopyBuf,
@ -129,7 +129,7 @@
zeroCopyBuf = null; zeroCopyBuf = null;
} }
const responseBodyRid = Deno.core.jsonOpSync("op_http_response", [ const responseBodyRid = Deno.core.opSync("op_http_response", [
responseSenderRid, responseSenderRid,
resp.status ?? 200, resp.status ?? 200,
flattenHeaders(resp.headers), flattenHeaders(resp.headers),
@ -149,7 +149,7 @@
chunk.byteOffset, chunk.byteOffset,
chunk.byteLength, chunk.byteLength,
); );
await Deno.core.jsonOpAsync( await Deno.core.opAsync(
"op_http_response_write", "op_http_response_write",
responseBodyRid, responseBodyRid,
data, data,
@ -158,7 +158,7 @@
// Once all chunks are sent, and the request body is closed, we can close // Once all chunks are sent, and the request body is closed, we can close
// the response body. // the response body.
await Deno.core.jsonOpAsync("op_http_response_close", responseBodyRid); await Deno.core.opAsync("op_http_response_close", responseBodyRid);
} }
}; };
} }

View file

@ -31,7 +31,7 @@
* @returns {Deno.PermissionState} * @returns {Deno.PermissionState}
*/ */
function opQuery(desc) { function opQuery(desc) {
return core.jsonOpSync("op_query_permission", desc); return core.opSync("op_query_permission", desc);
} }
/** /**
@ -39,7 +39,7 @@
* @returns {Deno.PermissionState} * @returns {Deno.PermissionState}
*/ */
function opRevoke(desc) { function opRevoke(desc) {
return core.jsonOpSync("op_revoke_permission", desc); return core.opSync("op_revoke_permission", desc);
} }
/** /**
@ -47,7 +47,7 @@
* @returns {Deno.PermissionState} * @returns {Deno.PermissionState}
*/ */
function opRequest(desc) { function opRequest(desc) {
return core.jsonOpSync("op_request_permission", desc); return core.opSync("op_request_permission", desc);
} }
class PermissionStatus extends EventTarget { class PermissionStatus extends EventTarget {

View file

@ -5,7 +5,7 @@
const core = window.Deno.core; const core = window.Deno.core;
function openPlugin(filename) { function openPlugin(filename) {
return core.jsonOpSync("op_open_plugin", filename); return core.opSync("op_open_plugin", filename);
} }
window.__bootstrap.plugins = { window.__bootstrap.plugins = {

View file

@ -8,16 +8,16 @@
const { assert, pathFromURL } = window.__bootstrap.util; const { assert, pathFromURL } = window.__bootstrap.util;
function opKill(pid, signo) { function opKill(pid, signo) {
core.jsonOpSync("op_kill", { pid, signo }); core.opSync("op_kill", { pid, signo });
} }
function opRunStatus(rid) { function opRunStatus(rid) {
return core.jsonOpAsync("op_run_status", rid); return core.opAsync("op_run_status", rid);
} }
function opRun(request) { function opRun(request) {
assert(request.cmd.length > 0); assert(request.cmd.length > 0);
return core.jsonOpSync("op_run", request); return core.opSync("op_run", request);
} }
async function runStatus(rid) { async function runStatus(rid) {

View file

@ -7,15 +7,15 @@
const { errors } = window.__bootstrap.errors; const { errors } = window.__bootstrap.errors;
function bindSignal(signo) { function bindSignal(signo) {
return core.jsonOpSync("op_signal_bind", signo); return core.opSync("op_signal_bind", signo);
} }
function pollSignal(rid) { function pollSignal(rid) {
return core.jsonOpAsync("op_signal_poll", rid); return core.opAsync("op_signal_poll", rid);
} }
function unbindSignal(rid) { function unbindSignal(rid) {
core.jsonOpSync("op_signal_unbind", rid); core.opSync("op_signal_unbind", rid);
} }
// From `kill -l` // From `kill -l`

View file

@ -8,19 +8,19 @@
function opConnectTls( function opConnectTls(
args, args,
) { ) {
return core.jsonOpAsync("op_connect_tls", args); return core.opAsync("op_connect_tls", args);
} }
function opAcceptTLS(rid) { function opAcceptTLS(rid) {
return core.jsonOpAsync("op_accept_tls", rid); return core.opAsync("op_accept_tls", rid);
} }
function opListenTls(args) { function opListenTls(args) {
return core.jsonOpSync("op_listen_tls", args); return core.opSync("op_listen_tls", args);
} }
function opStartTls(args) { function opStartTls(args) {
return core.jsonOpAsync("op_start_tls", args); return core.opAsync("op_start_tls", args);
} }
async function connectTls({ async function connectTls({

View file

@ -5,11 +5,11 @@
const core = window.Deno.core; const core = window.Deno.core;
function consoleSize(rid) { function consoleSize(rid) {
return core.jsonOpSync("op_console_size", rid); return core.opSync("op_console_size", rid);
} }
function isatty(rid) { function isatty(rid) {
return core.jsonOpSync("op_isatty", rid); return core.opSync("op_isatty", rid);
} }
const DEFAULT_SET_RAW_OPTIONS = { const DEFAULT_SET_RAW_OPTIONS = {
@ -18,7 +18,7 @@
function setRaw(rid, mode, options = {}) { function setRaw(rid, mode, options = {}) {
const rOptions = { ...DEFAULT_SET_RAW_OPTIONS, ...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 = { window.__bootstrap.tty = {

View file

@ -129,15 +129,15 @@ delete Object.prototype.__proto__;
} }
function opPostMessage(data) { function opPostMessage(data) {
core.jsonOpSync("op_worker_post_message", null, data); core.opSync("op_worker_post_message", null, data);
} }
function opCloseWorker() { function opCloseWorker() {
core.jsonOpSync("op_worker_close"); core.opSync("op_worker_close");
} }
function opMainModule() { function opMainModule() {
return core.jsonOpSync("op_main_module"); return core.opSync("op_main_module");
} }
function runtimeStart(runtimeOptions, source) { function runtimeStart(runtimeOptions, source) {

View file

@ -10,7 +10,7 @@ pub fn init(rt: &mut deno_core::JsRuntime, maybe_seed: Option<u64>) {
let mut state = op_state.borrow_mut(); let mut state = op_state.borrow_mut();
state.put::<StdRng>(rng); state.put::<StdRng>(rng);
} }
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_crypto_get_random_values", "op_crypto_get_random_values",
op_crypto_get_random_values, op_crypto_get_random_values,

View file

@ -20,19 +20,19 @@ pub fn init(
ca_data, ca_data,
}); });
} }
super::reg_json_sync(rt, "op_fetch", deno_fetch::op_fetch::<Permissions>); super::reg_sync(rt, "op_fetch", deno_fetch::op_fetch::<Permissions>);
super::reg_json_async(rt, "op_fetch_send", deno_fetch::op_fetch_send); super::reg_async(rt, "op_fetch_send", deno_fetch::op_fetch_send);
super::reg_json_async( super::reg_async(
rt, rt,
"op_fetch_request_write", "op_fetch_request_write",
deno_fetch::op_fetch_request_write, deno_fetch::op_fetch_request_write,
); );
super::reg_json_async( super::reg_async(
rt, rt,
"op_fetch_response_read", "op_fetch_response_read",
deno_fetch::op_fetch_response_read, deno_fetch::op_fetch_response_read,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_create_http_client", "op_create_http_client",
deno_fetch::op_create_http_client::<Permissions>, deno_fetch::op_create_http_client::<Permissions>,

View file

@ -18,14 +18,6 @@ pub fn init(
op_state.put(Location(location)); op_state.put(Location(location));
} }
} }
super::reg_json_sync( super::reg_sync(rt, "op_file_create_object_url", op_file_create_object_url);
rt, super::reg_sync(rt, "op_file_revoke_object_url", op_file_revoke_object_url);
"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,
);
} }

View file

@ -34,79 +34,79 @@ use deno_core::error::generic_error;
use deno_core::error::not_supported; use deno_core::error::not_supported;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_open_sync", op_open_sync); super::reg_sync(rt, "op_open_sync", op_open_sync);
super::reg_json_async(rt, "op_open_async", op_open_async); super::reg_async(rt, "op_open_async", op_open_async);
super::reg_json_sync(rt, "op_seek_sync", op_seek_sync); super::reg_sync(rt, "op_seek_sync", op_seek_sync);
super::reg_json_async(rt, "op_seek_async", op_seek_async); super::reg_async(rt, "op_seek_async", op_seek_async);
super::reg_json_sync(rt, "op_fdatasync_sync", op_fdatasync_sync); super::reg_sync(rt, "op_fdatasync_sync", op_fdatasync_sync);
super::reg_json_async(rt, "op_fdatasync_async", op_fdatasync_async); super::reg_async(rt, "op_fdatasync_async", op_fdatasync_async);
super::reg_json_sync(rt, "op_fsync_sync", op_fsync_sync); super::reg_sync(rt, "op_fsync_sync", op_fsync_sync);
super::reg_json_async(rt, "op_fsync_async", op_fsync_async); super::reg_async(rt, "op_fsync_async", op_fsync_async);
super::reg_json_sync(rt, "op_fstat_sync", op_fstat_sync); super::reg_sync(rt, "op_fstat_sync", op_fstat_sync);
super::reg_json_async(rt, "op_fstat_async", op_fstat_async); super::reg_async(rt, "op_fstat_async", op_fstat_async);
super::reg_json_sync(rt, "op_umask", op_umask); super::reg_sync(rt, "op_umask", op_umask);
super::reg_json_sync(rt, "op_chdir", op_chdir); super::reg_sync(rt, "op_chdir", op_chdir);
super::reg_json_sync(rt, "op_mkdir_sync", op_mkdir_sync); super::reg_sync(rt, "op_mkdir_sync", op_mkdir_sync);
super::reg_json_async(rt, "op_mkdir_async", op_mkdir_async); super::reg_async(rt, "op_mkdir_async", op_mkdir_async);
super::reg_json_sync(rt, "op_chmod_sync", op_chmod_sync); super::reg_sync(rt, "op_chmod_sync", op_chmod_sync);
super::reg_json_async(rt, "op_chmod_async", op_chmod_async); super::reg_async(rt, "op_chmod_async", op_chmod_async);
super::reg_json_sync(rt, "op_chown_sync", op_chown_sync); super::reg_sync(rt, "op_chown_sync", op_chown_sync);
super::reg_json_async(rt, "op_chown_async", op_chown_async); super::reg_async(rt, "op_chown_async", op_chown_async);
super::reg_json_sync(rt, "op_remove_sync", op_remove_sync); super::reg_sync(rt, "op_remove_sync", op_remove_sync);
super::reg_json_async(rt, "op_remove_async", op_remove_async); 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_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_async(rt, "op_copy_file_async", op_copy_file_async);
super::reg_json_sync(rt, "op_stat_sync", op_stat_sync); super::reg_sync(rt, "op_stat_sync", op_stat_sync);
super::reg_json_async(rt, "op_stat_async", op_stat_async); super::reg_async(rt, "op_stat_async", op_stat_async);
super::reg_json_sync(rt, "op_realpath_sync", op_realpath_sync); super::reg_sync(rt, "op_realpath_sync", op_realpath_sync);
super::reg_json_async(rt, "op_realpath_async", op_realpath_async); 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_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_async(rt, "op_read_dir_async", op_read_dir_async);
super::reg_json_sync(rt, "op_rename_sync", op_rename_sync); super::reg_sync(rt, "op_rename_sync", op_rename_sync);
super::reg_json_async(rt, "op_rename_async", op_rename_async); super::reg_async(rt, "op_rename_async", op_rename_async);
super::reg_json_sync(rt, "op_link_sync", op_link_sync); super::reg_sync(rt, "op_link_sync", op_link_sync);
super::reg_json_async(rt, "op_link_async", op_link_async); super::reg_async(rt, "op_link_async", op_link_async);
super::reg_json_sync(rt, "op_symlink_sync", op_symlink_sync); super::reg_sync(rt, "op_symlink_sync", op_symlink_sync);
super::reg_json_async(rt, "op_symlink_async", op_symlink_async); 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_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_async(rt, "op_read_link_async", op_read_link_async);
super::reg_json_sync(rt, "op_ftruncate_sync", op_ftruncate_sync); super::reg_sync(rt, "op_ftruncate_sync", op_ftruncate_sync);
super::reg_json_async(rt, "op_ftruncate_async", op_ftruncate_async); super::reg_async(rt, "op_ftruncate_async", op_ftruncate_async);
super::reg_json_sync(rt, "op_truncate_sync", op_truncate_sync); super::reg_sync(rt, "op_truncate_sync", op_truncate_sync);
super::reg_json_async(rt, "op_truncate_async", op_truncate_async); 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_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_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_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_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_sync(rt, "op_futime_sync", op_futime_sync);
super::reg_json_async(rt, "op_futime_async", op_futime_async); super::reg_async(rt, "op_futime_async", op_futime_async);
super::reg_json_sync(rt, "op_utime_sync", op_utime_sync); super::reg_sync(rt, "op_utime_sync", op_utime_sync);
super::reg_json_async(rt, "op_utime_async", op_utime_async); super::reg_async(rt, "op_utime_async", op_utime_async);
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -28,8 +28,8 @@ use std::rc::Rc;
use tokio::sync::mpsc; use tokio::sync::mpsc;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_fs_events_open", op_fs_events_open); super::reg_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_async(rt, "op_fs_events_poll", op_fs_events_poll);
} }
struct FsEventsResource { struct FsEventsResource {

View file

@ -43,14 +43,14 @@ use tokio_rustls::server::TlsStream;
use tokio_util::io::StreamReader; use tokio_util::io::StreamReader;
pub fn init(rt: &mut deno_core::JsRuntime) { 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_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_read", op_http_request_read);
super::reg_json_sync(rt, "op_http_response", op_http_response); super::reg_sync(rt, "op_http_response", op_http_response);
super::reg_json_async(rt, "op_http_response_write", op_http_response_write); super::reg_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_async(rt, "op_http_response_close", op_http_response_close);
} }
struct ServiceInner { struct ServiceInner {

View file

@ -96,13 +96,13 @@ lazy_static::lazy_static! {
} }
pub fn init(rt: &mut JsRuntime) { pub fn init(rt: &mut JsRuntime) {
super::reg_bin_async(rt, "op_read_async", op_read_async); super::reg_async(rt, "op_read_async", op_read_async);
super::reg_bin_async(rt, "op_write_async", op_write_async); super::reg_async(rt, "op_write_async", op_write_async);
super::reg_bin_sync(rt, "op_read_sync", op_read_sync); super::reg_sync(rt, "op_read_sync", op_read_sync);
super::reg_bin_sync(rt, "op_write_sync", op_write_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() -> ( pub fn get_stdio() -> (

View file

@ -27,59 +27,35 @@ pub mod websocket;
pub mod worker_host; pub mod worker_host;
use crate::metrics::metrics_op; 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::error::AnyError;
use deno_core::json_op_async; use deno_core::op_async;
use deno_core::json_op_sync; use deno_core::op_sync;
use deno_core::serde::de::DeserializeOwned; use deno_core::serde::de::DeserializeOwned;
use deno_core::serde::Serialize; use deno_core::serde::Serialize;
use deno_core::JsRuntime; use deno_core::JsRuntime;
use deno_core::OpState; use deno_core::OpState;
use deno_core::ValueOrVector;
use deno_core::ZeroCopyBuf; use deno_core::ZeroCopyBuf;
use std::cell::RefCell; use std::cell::RefCell;
use std::future::Future; use std::future::Future;
use std::rc::Rc; use std::rc::Rc;
pub fn reg_json_async<F, V, R, RV>( pub fn reg_async<F, V, R, RV>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
rt: &mut JsRuntime, where
name: &'static str,
op_fn: F,
) where
F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static, F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static,
V: DeserializeOwned, V: DeserializeOwned,
R: Future<Output = Result<RV, AnyError>> + 'static, R: Future<Output = Result<RV, AnyError>> + 'static,
RV: Serialize + '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<F, V, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) pub fn reg_sync<F, V, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where where
F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static, F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
V: DeserializeOwned, V: DeserializeOwned,
R: Serialize + 'static, R: Serialize + 'static,
{ {
rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); rt.register_op(name, metrics_op(name, op_sync(op_fn)));
}
pub fn reg_bin_async<F, R, RV>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F: Fn(Rc<RefCell<OpState>>, u32, Option<ZeroCopyBuf>) -> R + 'static,
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: ValueOrVector,
{
rt.register_op(name, metrics_op(name, bin_op_async(op_fn)));
}
pub fn reg_bin_sync<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F:
Fn(&mut OpState, u32, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
R: ValueOrVector,
{
rt.register_op(name, metrics_op(name, bin_op_sync(op_fn)));
} }
/// `UnstableChecker` is a struct so it can be placed inside `GothamState`; /// `UnstableChecker` is a struct so it can be placed inside `GothamState`;

View file

@ -43,12 +43,12 @@ use crate::ops::io::UnixStreamResource;
use std::path::Path; use std::path::Path;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_async(rt, "op_accept", op_accept); super::reg_async(rt, "op_accept", op_accept);
super::reg_json_async(rt, "op_connect", op_connect); super::reg_async(rt, "op_connect", op_connect);
super::reg_json_sync(rt, "op_listen", op_listen); super::reg_sync(rt, "op_listen", op_listen);
super::reg_json_async(rt, "op_datagram_receive", op_datagram_receive); super::reg_async(rt, "op_datagram_receive", op_datagram_receive);
super::reg_json_async(rt, "op_datagram_send", op_datagram_send); super::reg_async(rt, "op_datagram_send", op_datagram_send);
super::reg_json_async(rt, "op_dns_resolve", op_dns_resolve); super::reg_async(rt, "op_dns_resolve", op_dns_resolve);
} }
#[derive(Serialize)] #[derive(Serialize)]

View file

@ -12,17 +12,17 @@ use std::collections::HashMap;
use std::env; use std::env;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_exit", op_exit); super::reg_sync(rt, "op_exit", op_exit);
super::reg_json_sync(rt, "op_env", op_env); super::reg_sync(rt, "op_env", op_env);
super::reg_json_sync(rt, "op_exec_path", op_exec_path); super::reg_sync(rt, "op_exec_path", op_exec_path);
super::reg_json_sync(rt, "op_set_env", op_set_env); super::reg_sync(rt, "op_set_env", op_set_env);
super::reg_json_sync(rt, "op_get_env", op_get_env); super::reg_sync(rt, "op_get_env", op_get_env);
super::reg_json_sync(rt, "op_delete_env", op_delete_env); super::reg_sync(rt, "op_delete_env", op_delete_env);
super::reg_json_sync(rt, "op_hostname", op_hostname); super::reg_sync(rt, "op_hostname", op_hostname);
super::reg_json_sync(rt, "op_loadavg", op_loadavg); super::reg_sync(rt, "op_loadavg", op_loadavg);
super::reg_json_sync(rt, "op_os_release", op_os_release); super::reg_sync(rt, "op_os_release", op_os_release);
super::reg_json_sync(rt, "op_system_memory_info", op_system_memory_info); super::reg_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_system_cpu_info", op_system_cpu_info);
} }
fn op_exec_path( fn op_exec_path(

View file

@ -11,9 +11,9 @@ use serde::Deserialize;
use std::path::Path; use std::path::Path;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_query_permission", op_query_permission); super::reg_sync(rt, "op_query_permission", op_query_permission);
super::reg_json_sync(rt, "op_revoke_permission", op_revoke_permission); super::reg_sync(rt, "op_revoke_permission", op_revoke_permission);
super::reg_json_sync(rt, "op_request_permission", op_request_permission); super::reg_sync(rt, "op_request_permission", op_request_permission);
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -23,7 +23,7 @@ use std::task::Context;
use std::task::Poll; use std::task::Poll;
pub fn init(rt: &mut JsRuntime) { 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( pub fn op_open_plugin(

View file

@ -26,9 +26,9 @@ use tokio::process::Command;
use std::os::unix::process::ExitStatusExt; use std::os::unix::process::ExitStatusExt;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_run", op_run); super::reg_sync(rt, "op_run", op_run);
super::reg_json_async(rt, "op_run_status", op_run_status); super::reg_async(rt, "op_run_status", op_run_status);
super::reg_json_sync(rt, "op_kill", op_kill); super::reg_sync(rt, "op_kill", op_kill);
} }
fn clone_file( fn clone_file(

View file

@ -17,8 +17,8 @@ pub fn init(rt: &mut deno_core::JsRuntime, main_module: ModuleSpecifier) {
let mut state = op_state.borrow_mut(); let mut state = op_state.borrow_mut();
state.put::<ModuleSpecifier>(main_module); state.put::<ModuleSpecifier>(main_module);
} }
super::reg_json_sync(rt, "op_main_module", op_main_module); super::reg_sync(rt, "op_main_module", op_main_module);
super::reg_json_sync(rt, "op_metrics", op_metrics); super::reg_sync(rt, "op_metrics", op_metrics);
} }
fn op_main_module( fn op_main_module(

View file

@ -25,9 +25,9 @@ use std::borrow::Cow;
use tokio::signal::unix::{signal, Signal, SignalKind}; use tokio::signal::unix::{signal, Signal, SignalKind};
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_signal_bind", op_signal_bind); super::reg_sync(rt, "op_signal_bind", op_signal_bind);
super::reg_json_sync(rt, "op_signal_unbind", op_signal_unbind); super::reg_sync(rt, "op_signal_unbind", op_signal_unbind);
super::reg_json_async(rt, "op_signal_poll", op_signal_poll); super::reg_async(rt, "op_signal_poll", op_signal_poll);
} }
#[cfg(unix)] #[cfg(unix)]

View file

@ -69,11 +69,11 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
state.put::<GlobalTimer>(GlobalTimer::default()); state.put::<GlobalTimer>(GlobalTimer::default());
state.put::<StartTime>(StartTime::now()); state.put::<StartTime>(StartTime::now());
} }
super::reg_json_sync(rt, "op_global_timer_stop", op_global_timer_stop); super::reg_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_sync(rt, "op_global_timer_start", op_global_timer_start);
super::reg_json_async(rt, "op_global_timer", op_global_timer); super::reg_async(rt, "op_global_timer", op_global_timer);
super::reg_json_sync(rt, "op_now", op_now); super::reg_sync(rt, "op_now", op_now);
super::reg_json_sync(rt, "op_sleep_sync", op_sleep_sync); super::reg_sync(rt, "op_sleep_sync", op_sleep_sync);
} }
#[allow(clippy::unnecessary_wraps)] #[allow(clippy::unnecessary_wraps)]

View file

@ -71,10 +71,10 @@ impl StoresClientSessions for ClientSessionMemoryCache {
} }
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_async(rt, "op_start_tls", op_start_tls); super::reg_async(rt, "op_start_tls", op_start_tls);
super::reg_json_async(rt, "op_connect_tls", op_connect_tls); super::reg_async(rt, "op_connect_tls", op_connect_tls);
super::reg_json_sync(rt, "op_listen_tls", op_listen_tls); super::reg_sync(rt, "op_listen_tls", op_listen_tls);
super::reg_json_async(rt, "op_accept_tls", op_accept_tls); super::reg_async(rt, "op_accept_tls", op_accept_tls);
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -44,9 +44,9 @@ fn get_windows_handle(
} }
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_set_raw", op_set_raw); super::reg_sync(rt, "op_set_raw", op_set_raw);
super::reg_json_sync(rt, "op_isatty", op_isatty); super::reg_sync(rt, "op_isatty", op_isatty);
super::reg_json_sync(rt, "op_console_size", op_console_size); super::reg_sync(rt, "op_console_size", op_console_size);
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -4,13 +4,9 @@ use deno_url::op_url_parse_search_params;
use deno_url::op_url_stringify_search_params; use deno_url::op_url_stringify_search_params;
pub fn init(rt: &mut deno_core::JsRuntime) { pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_url_parse", op_url_parse); super::reg_sync(rt, "op_url_parse", op_url_parse);
super::reg_json_sync( super::reg_sync(rt, "op_url_parse_search_params", op_url_parse_search_params);
rt, super::reg_sync(
"op_url_parse_search_params",
op_url_parse_search_params,
);
super::reg_json_sync(
rt, rt,
"op_url_stringify_search_params", "op_url_stringify_search_params",
op_url_stringify_search_params, op_url_stringify_search_params,

View file

@ -12,7 +12,7 @@ pub fn init(
) { ) {
// Post message to host as guest worker. // Post message to host as guest worker.
let sender_ = sender.clone(); let sender_ = sender.clone();
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_worker_post_message", "op_worker_post_message",
move |_state, _args: (), buf| { move |_state, _args: (), buf| {
@ -27,15 +27,11 @@ pub fn init(
); );
// Notify host that guest worker closes. // Notify host that guest worker closes.
super::reg_json_sync( super::reg_sync(rt, "op_worker_close", move |_state, _args: (), _bufs| {
rt,
"op_worker_close",
move |_state, _args: (), _bufs| {
// Notify parent that we're finished // Notify parent that we're finished
sender.clone().close_channel(); sender.clone().close_channel();
// Terminate execution of current worker // Terminate execution of current worker
handle.terminate(); handle.terminate();
Ok(()) Ok(())
}, });
);
} }

View file

@ -10,40 +10,28 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
state.put(Unstable(unstable)); state.put(Unstable(unstable));
} }
super::reg_json_async( super::reg_async(rt, "op_webgpu_request_adapter", op_webgpu_request_adapter);
rt, super::reg_async(rt, "op_webgpu_request_device", op_webgpu_request_device);
"op_webgpu_request_adapter", super::reg_sync(rt, "op_webgpu_create_query_set", op_webgpu_create_query_set);
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,
);
{ {
// buffer // buffer
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_buffer", "op_webgpu_create_buffer",
buffer::op_webgpu_create_buffer, buffer::op_webgpu_create_buffer,
); );
super::reg_json_async( super::reg_async(
rt, rt,
"op_webgpu_buffer_get_map_async", "op_webgpu_buffer_get_map_async",
buffer::op_webgpu_buffer_get_map_async, buffer::op_webgpu_buffer_get_map_async,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_buffer_get_mapped_range", "op_webgpu_buffer_get_mapped_range",
buffer::op_webgpu_buffer_get_mapped_range, buffer::op_webgpu_buffer_get_mapped_range,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_buffer_unmap", "op_webgpu_buffer_unmap",
buffer::op_webgpu_buffer_unmap, buffer::op_webgpu_buffer_unmap,
@ -51,12 +39,12 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
} }
{ {
// texture // texture
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_texture", "op_webgpu_create_texture",
texture::op_webgpu_create_texture, texture::op_webgpu_create_texture,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_texture_view", "op_webgpu_create_texture_view",
texture::op_webgpu_create_texture_view, texture::op_webgpu_create_texture_view,
@ -64,7 +52,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
} }
{ {
// sampler // sampler
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_sampler", "op_webgpu_create_sampler",
sampler::op_webgpu_create_sampler, sampler::op_webgpu_create_sampler,
@ -72,17 +60,17 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
} }
{ {
// binding // binding
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_bind_group_layout", "op_webgpu_create_bind_group_layout",
binding::op_webgpu_create_bind_group_layout, binding::op_webgpu_create_bind_group_layout,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_pipeline_layout", "op_webgpu_create_pipeline_layout",
binding::op_webgpu_create_pipeline_layout, binding::op_webgpu_create_pipeline_layout,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_bind_group", "op_webgpu_create_bind_group",
binding::op_webgpu_create_bind_group, binding::op_webgpu_create_bind_group,
@ -90,22 +78,22 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
} }
{ {
// pipeline // pipeline
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_compute_pipeline", "op_webgpu_create_compute_pipeline",
pipeline::op_webgpu_create_compute_pipeline, pipeline::op_webgpu_create_compute_pipeline,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pipeline_get_bind_group_layout", "op_webgpu_compute_pipeline_get_bind_group_layout",
pipeline::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, rt,
"op_webgpu_create_render_pipeline", "op_webgpu_create_render_pipeline",
pipeline::op_webgpu_create_render_pipeline, pipeline::op_webgpu_create_render_pipeline,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pipeline_get_bind_group_layout", "op_webgpu_render_pipeline_get_bind_group_layout",
pipeline::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 // command_encoder
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_command_encoder", "op_webgpu_create_command_encoder",
command_encoder::op_webgpu_create_command_encoder, command_encoder::op_webgpu_create_command_encoder,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_begin_render_pass", "op_webgpu_command_encoder_begin_render_pass",
command_encoder::op_webgpu_command_encoder_begin_render_pass, command_encoder::op_webgpu_command_encoder_begin_render_pass,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_begin_compute_pass", "op_webgpu_command_encoder_begin_compute_pass",
command_encoder::op_webgpu_command_encoder_begin_compute_pass, command_encoder::op_webgpu_command_encoder_begin_compute_pass,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_copy_buffer_to_buffer", "op_webgpu_command_encoder_copy_buffer_to_buffer",
command_encoder::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, rt,
"op_webgpu_command_encoder_copy_buffer_to_texture", "op_webgpu_command_encoder_copy_buffer_to_texture",
command_encoder::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, rt,
"op_webgpu_command_encoder_copy_texture_to_buffer", "op_webgpu_command_encoder_copy_texture_to_buffer",
command_encoder::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, rt,
"op_webgpu_command_encoder_copy_texture_to_texture", "op_webgpu_command_encoder_copy_texture_to_texture",
command_encoder::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, rt,
"op_webgpu_command_encoder_push_debug_group", "op_webgpu_command_encoder_push_debug_group",
command_encoder::op_webgpu_command_encoder_push_debug_group, command_encoder::op_webgpu_command_encoder_push_debug_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_pop_debug_group", "op_webgpu_command_encoder_pop_debug_group",
command_encoder::op_webgpu_command_encoder_pop_debug_group, command_encoder::op_webgpu_command_encoder_pop_debug_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_insert_debug_marker", "op_webgpu_command_encoder_insert_debug_marker",
command_encoder::op_webgpu_command_encoder_insert_debug_marker, command_encoder::op_webgpu_command_encoder_insert_debug_marker,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_write_timestamp", "op_webgpu_command_encoder_write_timestamp",
command_encoder::op_webgpu_command_encoder_write_timestamp, command_encoder::op_webgpu_command_encoder_write_timestamp,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_resolve_query_set", "op_webgpu_command_encoder_resolve_query_set",
command_encoder::op_webgpu_command_encoder_resolve_query_set, command_encoder::op_webgpu_command_encoder_resolve_query_set,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_command_encoder_finish", "op_webgpu_command_encoder_finish",
command_encoder::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 // render_pass
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_viewport", "op_webgpu_render_pass_set_viewport",
render_pass::op_webgpu_render_pass_set_viewport, render_pass::op_webgpu_render_pass_set_viewport,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_scissor_rect", "op_webgpu_render_pass_set_scissor_rect",
render_pass::op_webgpu_render_pass_set_scissor_rect, render_pass::op_webgpu_render_pass_set_scissor_rect,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_blend_color", "op_webgpu_render_pass_set_blend_color",
render_pass::op_webgpu_render_pass_set_blend_color, render_pass::op_webgpu_render_pass_set_blend_color,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_stencil_reference", "op_webgpu_render_pass_set_stencil_reference",
render_pass::op_webgpu_render_pass_set_stencil_reference, render_pass::op_webgpu_render_pass_set_stencil_reference,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_begin_pipeline_statistics_query", "op_webgpu_render_pass_begin_pipeline_statistics_query",
render_pass::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, rt,
"op_webgpu_render_pass_end_pipeline_statistics_query", "op_webgpu_render_pass_end_pipeline_statistics_query",
render_pass::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, rt,
"op_webgpu_render_pass_write_timestamp", "op_webgpu_render_pass_write_timestamp",
render_pass::op_webgpu_render_pass_write_timestamp, render_pass::op_webgpu_render_pass_write_timestamp,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_execute_bundles", "op_webgpu_render_pass_execute_bundles",
render_pass::op_webgpu_render_pass_execute_bundles, render_pass::op_webgpu_render_pass_execute_bundles,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_end_pass", "op_webgpu_render_pass_end_pass",
render_pass::op_webgpu_render_pass_end_pass, render_pass::op_webgpu_render_pass_end_pass,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_bind_group", "op_webgpu_render_pass_set_bind_group",
render_pass::op_webgpu_render_pass_set_bind_group, render_pass::op_webgpu_render_pass_set_bind_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_push_debug_group", "op_webgpu_render_pass_push_debug_group",
render_pass::op_webgpu_render_pass_push_debug_group, render_pass::op_webgpu_render_pass_push_debug_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_pop_debug_group", "op_webgpu_render_pass_pop_debug_group",
render_pass::op_webgpu_render_pass_pop_debug_group, render_pass::op_webgpu_render_pass_pop_debug_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_insert_debug_marker", "op_webgpu_render_pass_insert_debug_marker",
render_pass::op_webgpu_render_pass_insert_debug_marker, render_pass::op_webgpu_render_pass_insert_debug_marker,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_pipeline", "op_webgpu_render_pass_set_pipeline",
render_pass::op_webgpu_render_pass_set_pipeline, render_pass::op_webgpu_render_pass_set_pipeline,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_index_buffer", "op_webgpu_render_pass_set_index_buffer",
render_pass::op_webgpu_render_pass_set_index_buffer, render_pass::op_webgpu_render_pass_set_index_buffer,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_set_vertex_buffer", "op_webgpu_render_pass_set_vertex_buffer",
render_pass::op_webgpu_render_pass_set_vertex_buffer, render_pass::op_webgpu_render_pass_set_vertex_buffer,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_draw", "op_webgpu_render_pass_draw",
render_pass::op_webgpu_render_pass_draw, render_pass::op_webgpu_render_pass_draw,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_draw_indexed", "op_webgpu_render_pass_draw_indexed",
render_pass::op_webgpu_render_pass_draw_indexed, render_pass::op_webgpu_render_pass_draw_indexed,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_draw_indirect", "op_webgpu_render_pass_draw_indirect",
render_pass::op_webgpu_render_pass_draw_indirect, render_pass::op_webgpu_render_pass_draw_indirect,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_pass_draw_indexed_indirect", "op_webgpu_render_pass_draw_indexed_indirect",
render_pass::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 // compute_pass
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_set_pipeline", "op_webgpu_compute_pass_set_pipeline",
compute_pass::op_webgpu_compute_pass_set_pipeline, compute_pass::op_webgpu_compute_pass_set_pipeline,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_dispatch", "op_webgpu_compute_pass_dispatch",
compute_pass::op_webgpu_compute_pass_dispatch, compute_pass::op_webgpu_compute_pass_dispatch,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_dispatch_indirect", "op_webgpu_compute_pass_dispatch_indirect",
compute_pass::op_webgpu_compute_pass_dispatch_indirect, compute_pass::op_webgpu_compute_pass_dispatch_indirect,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_end_pass", "op_webgpu_compute_pass_end_pass",
compute_pass::op_webgpu_compute_pass_end_pass, compute_pass::op_webgpu_compute_pass_end_pass,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_set_bind_group", "op_webgpu_compute_pass_set_bind_group",
compute_pass::op_webgpu_compute_pass_set_bind_group, compute_pass::op_webgpu_compute_pass_set_bind_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_push_debug_group", "op_webgpu_compute_pass_push_debug_group",
compute_pass::op_webgpu_compute_pass_push_debug_group, compute_pass::op_webgpu_compute_pass_push_debug_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_pop_debug_group", "op_webgpu_compute_pass_pop_debug_group",
compute_pass::op_webgpu_compute_pass_pop_debug_group, compute_pass::op_webgpu_compute_pass_pop_debug_group,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_compute_pass_insert_debug_marker", "op_webgpu_compute_pass_insert_debug_marker",
compute_pass::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 // bundle
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_render_bundle_encoder", "op_webgpu_create_render_bundle_encoder",
bundle::op_webgpu_create_render_bundle_encoder, bundle::op_webgpu_create_render_bundle_encoder,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_bundle_encoder_finish", "op_webgpu_render_bundle_encoder_finish",
bundle::op_webgpu_render_bundle_encoder_finish, bundle::op_webgpu_render_bundle_encoder_finish,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_bundle_encoder_set_bind_group", "op_webgpu_render_bundle_encoder_set_bind_group",
bundle::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, rt,
"op_webgpu_render_bundle_encoder_push_debug_group", "op_webgpu_render_bundle_encoder_push_debug_group",
bundle::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, rt,
"op_webgpu_render_bundle_encoder_pop_debug_group", "op_webgpu_render_bundle_encoder_pop_debug_group",
bundle::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, rt,
"op_webgpu_render_bundle_encoder_insert_debug_marker", "op_webgpu_render_bundle_encoder_insert_debug_marker",
bundle::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, rt,
"op_webgpu_render_bundle_encoder_set_pipeline", "op_webgpu_render_bundle_encoder_set_pipeline",
bundle::op_webgpu_render_bundle_encoder_set_pipeline, bundle::op_webgpu_render_bundle_encoder_set_pipeline,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_bundle_encoder_set_index_buffer", "op_webgpu_render_bundle_encoder_set_index_buffer",
bundle::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, rt,
"op_webgpu_render_bundle_encoder_set_vertex_buffer", "op_webgpu_render_bundle_encoder_set_vertex_buffer",
bundle::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, rt,
"op_webgpu_render_bundle_encoder_draw", "op_webgpu_render_bundle_encoder_draw",
bundle::op_webgpu_render_bundle_encoder_draw, bundle::op_webgpu_render_bundle_encoder_draw,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_bundle_encoder_draw_indexed", "op_webgpu_render_bundle_encoder_draw_indexed",
bundle::op_webgpu_render_bundle_encoder_draw_indexed, bundle::op_webgpu_render_bundle_encoder_draw_indexed,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_render_bundle_encoder_draw_indirect", "op_webgpu_render_bundle_encoder_draw_indirect",
bundle::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 // queue
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_queue_submit", "op_webgpu_queue_submit",
queue::op_webgpu_queue_submit, queue::op_webgpu_queue_submit,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_write_buffer", "op_webgpu_write_buffer",
queue::op_webgpu_write_buffer, queue::op_webgpu_write_buffer,
); );
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_write_texture", "op_webgpu_write_texture",
queue::op_webgpu_write_texture, queue::op_webgpu_write_texture,
@ -408,7 +396,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
} }
{ {
// shader // shader
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_webgpu_create_shader_module", "op_webgpu_create_shader_module",
shader::op_webgpu_create_shader_module, shader::op_webgpu_create_shader_module,

View file

@ -21,13 +21,13 @@ pub fn init(
state.put::<WsCaData>(WsCaData(ca_data)); state.put::<WsCaData>(WsCaData(ca_data));
} }
} }
super::reg_json_sync( super::reg_sync(
rt, rt,
"op_ws_check_permission", "op_ws_check_permission",
op_ws_check_permission::<Permissions>, op_ws_check_permission::<Permissions>,
); );
super::reg_json_async(rt, "op_ws_create", op_ws_create::<Permissions>); super::reg_async(rt, "op_ws_create", op_ws_create::<Permissions>);
super::reg_json_async(rt, "op_ws_send", op_ws_send); super::reg_async(rt, "op_ws_send", op_ws_send);
super::reg_json_async(rt, "op_ws_close", op_ws_close); super::reg_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_next_event", op_ws_next_event);
} }

View file

@ -80,15 +80,11 @@ pub fn init(
let create_module_loader = CreateWebWorkerCbHolder(create_web_worker_cb); let create_module_loader = CreateWebWorkerCbHolder(create_web_worker_cb);
state.put::<CreateWebWorkerCbHolder>(create_module_loader); state.put::<CreateWebWorkerCbHolder>(create_module_loader);
} }
super::reg_json_sync(rt, "op_create_worker", op_create_worker); super::reg_sync(rt, "op_create_worker", op_create_worker);
super::reg_json_sync( super::reg_sync(rt, "op_host_terminate_worker", op_host_terminate_worker);
rt, super::reg_sync(rt, "op_host_post_message", op_host_post_message);
"op_host_terminate_worker", super::reg_async(rt, "op_host_get_message", op_host_get_message);
op_host_terminate_worker, super::reg_sync(
);
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(
rt, rt,
"op_host_unhandled_error", "op_host_unhandled_error",
move |_state, message: String, _zero_copy| { move |_state, message: String, _zero_copy| {

View file

@ -231,8 +231,8 @@ impl WebWorker {
Some(sender), Some(sender),
options.create_web_worker_cb.clone(), options.create_web_worker_cb.clone(),
); );
ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close); ops::reg_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_resources", deno_core::op_resources);
ops::url::init(js_runtime); ops::url::init(js_runtime);
ops::file::init( ops::file::init(
js_runtime, js_runtime,

View file

@ -128,8 +128,8 @@ impl MainWorker {
options.create_web_worker_cb.clone(), options.create_web_worker_cb.clone(),
); );
ops::crypto::init(js_runtime, options.seed); ops::crypto::init(js_runtime, options.seed);
ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close); ops::reg_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_resources", deno_core::op_resources);
ops::url::init(js_runtime); ops::url::init(js_runtime);
ops::file::init( ops::file::init(
js_runtime, js_runtime,