1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 09:10:40 -05:00

perf(ops): Monomorphic sync op calls (#15337)

Welcome to better optimised op calls! Currently opSync is called with parameters of every type and count. This most definitely makes the call megamorphic. Additionally, it seems that spread params leads to V8 not being able to optimise the calls quite as well (apparently Fast Calls cannot be used with spread params).

Monomorphising op calls should lead to some improved performance. Now that unwrapping of sync ops results is done on Rust side, this is pretty simple:

```
opSync("op_foo", param1, param2);
// -> turns to
ops.op_foo(param1, param2);
```

This means sync op calls are now just directly calling the native binding function. When V8 Fast API Calls are enabled, this will enable those to be called on the optimised path.

Monomorphising async ops likely requires using callbacks and is left as an exercise to the reader.
This commit is contained in:
Aapo Alasuutari 2022-08-11 16:56:56 +03:00 committed by GitHub
parent 883269f1f1
commit 2164f6b1eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
80 changed files with 552 additions and 616 deletions

View file

@ -30,7 +30,7 @@ fn setup() -> Vec<Extension> {
}
fn bench_op_nop(b: &mut Bencher) {
bench_js_sync(b, r#"Deno.core.opSync("op_nop", null, null);"#, setup);
bench_js_sync(b, r#"Deno.core.ops.op_nop();"#, setup);
}
benchmark_group!(benches, bench_op_nop);

View file

@ -30,15 +30,15 @@ async fn op_pi_async() -> i64 {
}
fn bench_op_pi_json(b: &mut Bencher) {
bench_js_sync(b, r#"Deno.core.opSync("op_pi_json", null);"#, setup);
bench_js_sync(b, r#"Deno.core.ops.op_pi_json();"#, setup);
}
fn bench_op_nop(b: &mut Bencher) {
bench_js_sync(b, r#"Deno.core.opSync("op_nop", null, null, null);"#, setup);
bench_js_sync(b, r#"Deno.core.ops.op_nop();"#, setup);
}
fn bench_op_async(b: &mut Bencher) {
bench_js_async(b, r#"Deno.core.opAsync("op_pi_async", null);"#, setup);
bench_js_async(b, r#"Deno.core.opAsync("op_pi_async");"#, setup);
}
fn bench_is_proxy(b: &mut Bencher) {

View file

@ -6,7 +6,11 @@ Deno.bench("date_now", { n: 5e5 }, () => {
});
// Void ops measure op-overhead
Deno.bench("op_void_sync", { n: 1e7 }, () => Deno.core.opSync("op_void_sync"));
Deno.bench(
"op_void_sync",
{ n: 1e7 },
() => Deno.core.ops.op_void_sync(),
);
Deno.bench(
"op_void_async",

View file

@ -19,7 +19,7 @@ class Http {
}
for await (const conn of tcp) {
const id = Deno.core.opSync("op_http_start", conn.rid);
const id = Deno.core.ops.op_http_start(conn.rid);
const http = new Http(id);
(async () => {
for await (const req of http) {

View file

@ -1,8 +1,6 @@
Deno.core.opSync(
"op_pledge_test_permissions",
Deno.core.ops.op_pledge_test_permissions(
"none",
);
Deno.core.opSync(
"op_pledge_test_permissions",
Deno.core.ops.op_pledge_test_permissions(
"inherit",
);

View file

@ -3,7 +3,7 @@
// `self.close()`.
// @ts-ignore Deno.core doesn't have type-defs
Deno.core.opSync("op_set_exit_code", 21);
Deno.core.ops.op_set_exit_code(21);
const worker = new Worker(
import.meta.resolve("./op_exit_op_set_exit_code_worker.js"),

View file

@ -1,4 +1,4 @@
self.onmessage = () => {
Deno.core.opSync("op_set_exit_code", 42);
Deno.core.ops.op_set_exit_code(42);
Deno.exit();
};

View file

@ -1,2 +1,2 @@
Deno.core.opSync("op_set_exit_code", 42);
Deno.core.ops.op_set_exit_code(42);
Deno.exit(0); // Takes precedence.

View file

@ -1,2 +1,2 @@
Deno.core.opSync("op_set_exit_code", 42);
Deno.core.ops.op_set_exit_code(42);
Deno.exit();

View file

@ -1,2 +1,2 @@
Deno.core.opSync("op_set_exit_code", 42);
Deno.core.ops.op_set_exit_code(42);
// Exits naturally.

View file

@ -1,8 +1,6 @@
Deno.core.opSync(
"op_pledge_test_permissions",
Deno.core.ops.op_pledge_test_permissions(
"none",
);
Deno.core.opSync(
"op_pledge_test_permissions",
Deno.core.ops.op_pledge_test_permissions(
"inherit",
);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_load", { path: "", symbols: {} });
Deno.core.ops.op_ffi_load({ path: "", symbols: {} });

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_i16", 0n);
Deno.core.ops.op_ffi_read_i16(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_u32", 0n);
Deno.core.ops.op_ffi_read_u32(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_i32", 0n);
Deno.core.ops.op_ffi_read_i32(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_u64", 0n);
Deno.core.ops.op_ffi_read_u64(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_f32", 0n);
Deno.core.ops.op_ffi_read_f32(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_f64", 0n);
Deno.core.ops.op_ffi_read_f64(0n);

View file

@ -1,4 +1,4 @@
Deno.core.opSync("op_ffi_call_ptr", 0n, {
Deno.core.ops.op_ffi_call_ptr(0n, {
name: null,
parameters: [],
result: "void",

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_ptr_of", new Uint8Array(0));
Deno.core.ops.op_ffi_ptr_of(new Uint8Array(0));

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_buf_copy_into", 0n, new Uint8Array(0), 0);
Deno.core.ops.op_ffi_buf_copy_into(0n, new Uint8Array(0), 0);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_cstr_read", 0n);
Deno.core.ops.op_ffi_cstr_read(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_u8", 0n);
Deno.core.ops.op_ffi_read_u8(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_i8", 0n);
Deno.core.ops.op_ffi_read_i8(0n);

View file

@ -1 +1 @@
Deno.core.opSync("op_ffi_read_u16", 0n);
Deno.core.ops.op_ffi_read_u16(0n);

View file

@ -44,7 +44,7 @@ Deno.test(async function opsAsyncBadResource() {
Deno.test(function opsSyncBadResource() {
try {
const nonExistingRid = 9999;
Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0));
Deno.core.ops.op_read_sync(nonExistingRid, new Uint8Array(0));
} catch (e) {
if (!(e instanceof Deno.errors.BadResource)) {
throw e;

View file

@ -15,6 +15,7 @@ delete Object.prototype.__proto__;
((window) => {
/** @type {DenoCore} */
const core = window.Deno.core;
const ops = core.ops;
let logDebug = false;
let logSource = "JS";
@ -250,7 +251,7 @@ delete Object.prototype.__proto__;
}
this.#lastCheckTimeMs = timeMs;
return core.opSync("op_is_cancelled", {});
return ops.op_is_cancelled();
}
throwIfCancellationRequested() {
@ -274,11 +275,11 @@ delete Object.prototype.__proto__;
fileExists(specifier) {
debug(`host.fileExists("${specifier}")`);
specifier = normalizedToOriginalMap.get(specifier) ?? specifier;
return core.opSync("op_exists", { specifier });
return ops.op_exists({ specifier });
},
readFile(specifier) {
debug(`host.readFile("${specifier}")`);
return core.opSync("op_load", { specifier }).data;
return ops.op_load({ specifier }).data;
},
getCancellationToken() {
// createLanguageService will call this immediately and cache it
@ -309,8 +310,7 @@ delete Object.prototype.__proto__;
}
/** @type {{ data: string; scriptKind: ts.ScriptKind; version: string; }} */
const { data, scriptKind, version } = core.opSync(
"op_load",
const { data, scriptKind, version } = ops.op_load(
{ specifier },
);
assert(
@ -338,14 +338,13 @@ delete Object.prototype.__proto__;
},
writeFile(fileName, data, _writeByteOrderMark, _onError, _sourceFiles) {
debug(`host.writeFile("${fileName}")`);
return core.opSync(
"op_emit",
return ops.op_emit(
{ fileName, data },
);
},
getCurrentDirectory() {
debug(`host.getCurrentDirectory()`);
return cwd ?? core.opSync("op_cwd", null);
return cwd ?? ops.op_cwd();
},
getCanonicalFileName(fileName) {
return fileName;
@ -361,7 +360,7 @@ delete Object.prototype.__proto__;
debug(` base: ${base}`);
debug(` specifiers: ${specifiers.join(", ")}`);
/** @type {Array<[string, ts.Extension] | undefined>} */
const resolved = core.opSync("op_resolve", {
const resolved = ops.op_resolve({
specifiers,
base,
});
@ -384,7 +383,7 @@ delete Object.prototype.__proto__;
}
},
createHash(data) {
return core.opSync("op_create_hash", { data }).hash;
return ops.op_create_hash({ data }).hash;
},
// LanguageServiceHost
@ -399,7 +398,7 @@ delete Object.prototype.__proto__;
if (scriptFileNamesCache) {
return scriptFileNamesCache;
}
return scriptFileNamesCache = core.opSync("op_script_names", undefined);
return scriptFileNamesCache = ops.op_script_names();
},
getScriptVersion(specifier) {
debug(`host.getScriptVersion("${specifier}")`);
@ -412,7 +411,7 @@ delete Object.prototype.__proto__;
if (scriptVersionCache.has(specifier)) {
return scriptVersionCache.get(specifier);
}
const scriptVersion = core.opSync("op_script_version", { specifier });
const scriptVersion = ops.op_script_version({ specifier });
scriptVersionCache.set(specifier, scriptVersion);
return scriptVersion;
},
@ -433,8 +432,7 @@ delete Object.prototype.__proto__;
};
}
const fileInfo = core.opSync(
"op_load",
const fileInfo = ops.op_load(
{ specifier },
);
if (fileInfo) {
@ -567,7 +565,7 @@ delete Object.prototype.__proto__;
performanceProgram({ program });
core.opSync("op_respond", {
ops.op_respond({
diagnostics: fromTypeScriptDiagnostic(diagnostics),
stats: performanceEnd(),
});
@ -579,7 +577,7 @@ delete Object.prototype.__proto__;
* @param {any} data
*/
function respond(id, data = null) {
core.opSync("op_respond", { id, data });
ops.op_respond({ id, data });
}
/**
@ -942,7 +940,7 @@ delete Object.prototype.__proto__;
// ensure the snapshot is setup properly.
/** @type {{ buildSpecifier: string; libs: string[] }} */
const { buildSpecifier, libs } = core.opSync("op_build_info", {});
const { buildSpecifier, libs } = ops.op_build_info();
for (const lib of libs) {
const specifier = `lib.${lib}.d.ts`;
// we are using internal APIs here to "inject" our custom libraries into

View file

@ -39,8 +39,9 @@ declare global {
encode(value: string): Uint8Array;
// deno-lint-ignore no-explicit-any
opSync<T>(name: string, params: T): any;
ops(): void;
print(msg: string, stderr: bool): void;
// deno-lint-ignore no-explicit-any
ops: Record<string, (...args: unknown[]) => any>;
print(msg: string, stderr: boolean): void;
registerErrorClass(
name: string,
Ctor: typeof Error,

View file

@ -187,31 +187,31 @@
if (!hasPromise(promiseId)) {
return;
}
opSync("op_ref_op", promiseId);
ops.op_ref_op(promiseId);
}
function unrefOp(promiseId) {
if (!hasPromise(promiseId)) {
return;
}
opSync("op_unref_op", promiseId);
ops.op_unref_op(promiseId);
}
function resources() {
return ObjectFromEntries(opSync("op_resources"));
return ObjectFromEntries(ops.op_resources());
}
function metrics() {
const [aggregate, perOps] = opSync("op_metrics");
const [aggregate, perOps] = ops.op_metrics();
aggregate.ops = ObjectFromEntries(ArrayPrototypeMap(
core.opSync("op_op_names"),
ops.op_op_names(),
(opName, opId) => [opName, perOps[opId]],
));
return aggregate;
}
function queueMicrotask(...args) {
return opSync("op_queue_microtask", ...args);
function queueMicrotask(cb) {
return ops.op_queue_microtask(cb);
}
// Some "extensions" rely on "BadResource" and "Interrupted" errors in the
@ -252,40 +252,44 @@
opCallTraces,
refOp,
unrefOp,
close: opSync.bind(null, "op_close"),
tryClose: opSync.bind(null, "op_try_close"),
close: (rid) => ops.op_close(rid),
tryClose: (rid) => ops.op_try_close(rid),
read: opAsync.bind(null, "op_read"),
write: opAsync.bind(null, "op_write"),
shutdown: opAsync.bind(null, "op_shutdown"),
print: opSync.bind(null, "op_print"),
setMacrotaskCallback: opSync.bind(null, "op_set_macrotask_callback"),
setNextTickCallback: opSync.bind(null, "op_set_next_tick_callback"),
runMicrotasks: opSync.bind(null, "op_run_microtasks"),
hasTickScheduled: opSync.bind(null, "op_has_tick_scheduled"),
setHasTickScheduled: opSync.bind(null, "op_set_has_tick_scheduled"),
evalContext: opSync.bind(null, "op_eval_context"),
createHostObject: opSync.bind(null, "op_create_host_object"),
encode: opSync.bind(null, "op_encode"),
decode: opSync.bind(null, "op_decode"),
serialize: opSync.bind(null, "op_serialize"),
deserialize: opSync.bind(null, "op_deserialize"),
getPromiseDetails: opSync.bind(null, "op_get_promise_details"),
getProxyDetails: opSync.bind(null, "op_get_proxy_details"),
isProxy: opSync.bind(null, "op_is_proxy"),
memoryUsage: opSync.bind(null, "op_memory_usage"),
setWasmStreamingCallback: opSync.bind(
null,
"op_set_wasm_streaming_callback",
),
abortWasmStreaming: opSync.bind(null, "op_abort_wasm_streaming"),
destructureError: opSync.bind(null, "op_destructure_error"),
terminate: opSync.bind(null, "op_terminate"),
opNames: opSync.bind(null, "op_op_names"),
eventLoopHasMoreWork: opSync.bind(null, "op_event_loop_has_more_work"),
setPromiseRejectCallback: opSync.bind(
null,
"op_set_promise_reject_callback",
),
print: (msg, isErr) => ops.op_print(msg, isErr),
setMacrotaskCallback: (fn) => ops.op_set_macrotask_callback(fn),
setNextTickCallback: (fn) => ops.op_set_next_tick_callback(fn),
runMicrotasks: () => ops.op_run_microtasks(),
hasTickScheduled: () => ops.op_has_tick_scheduled(),
setHasTickScheduled: (bool) => ops.op_set_has_tick_scheduled(bool),
evalContext: (
source,
specifier,
) => ops.op_eval_context(source, specifier),
createHostObject: () => ops.op_create_host_object(),
encode: (text) => ops.op_encode(text),
decode: (buffer) => ops.op_decode(buffer),
serialize: (
value,
options,
errorCallback,
) => ops.op_serialize(value, options, errorCallback),
deserialize: (buffer, options) => ops.op_deserialize(buffer, options),
getPromiseDetails: (promise) => ops.op_get_promise_details(promise),
getProxyDetails: (proxy) => ops.op_get_proxy_details(proxy),
isProxy: (value) => ops.op_is_proxy(value),
memoryUsage: () => ops.op_memory_usage(),
setWasmStreamingCallback: (fn) => ops.op_set_wasm_streaming_callback(fn),
abortWasmStreaming: (
rid,
error,
) => ops.op_abort_wasm_streaming(rid, error),
destructureError: (error) => ops.op_destructure_error(error),
terminate: (exception) => ops.op_terminate(exception),
opNames: () => ops.op_op_names(),
eventLoopHasMoreWork: () => ops.op_event_loop_has_more_work(),
setPromiseRejectCallback: (fn) => ops.op_set_promise_reject_callback(fn),
});
ObjectAssign(globalThis.__bootstrap, { core });

View file

@ -3,6 +3,7 @@
((window) => {
const core = Deno.core;
const ops = core.ops;
const {
Error,
ObjectFreeze,
@ -22,7 +23,7 @@
}
let result = "";
if (cse.fileName) {
result += core.opSync("op_format_file_name", cse.fileName);
result += ops.op_format_file_name(cse.fileName);
} else {
if (cse.isEval) {
if (cse.evalOrigin == null) {
@ -116,7 +117,7 @@
function sourceMapCallSiteEval(cse) {
if (cse.fileName && cse.lineNumber != null && cse.columnNumber != null) {
return { ...cse, ...core.opSync("op_apply_source_map", cse) };
return { ...cse, ...ops.op_apply_source_map(cse) };
}
return cse;
}

View file

@ -33,31 +33,31 @@ function main() {
108, 100
];
const empty = Deno.core.opSync("op_encode", "");
const empty = Deno.core.ops.op_encode("");
if (empty.length !== 0) throw new Error("assert");
assertArrayEquals(
Array.from(Deno.core.opSync("op_encode", "𝓽𝓮𝔁𝓽")),
Array.from(Deno.core.ops.op_encode("𝓽𝓮𝔁𝓽")),
fixture1,
);
assertArrayEquals(
Array.from(Deno.core.opSync("op_encode", "Hello \udc12\ud834 World")),
Array.from(Deno.core.ops.op_encode("Hello \udc12\ud834 World")),
fixture2,
);
const emptyBuf = Deno.core.opSync("op_decode", new Uint8Array(0));
const emptyBuf = Deno.core.ops.op_decode(new Uint8Array(0));
if (emptyBuf !== "") throw new Error("assert");
assert(Deno.core.opSync("op_decode", new Uint8Array(fixture1)) === "𝓽𝓮𝔁𝓽");
assert(Deno.core.ops.op_decode(new Uint8Array(fixture1)) === "𝓽𝓮𝔁𝓽");
assert(
Deno.core.opSync("op_decode", new Uint8Array(fixture2)) ===
Deno.core.ops.op_decode(new Uint8Array(fixture2)) ===
"Hello <20><> World",
);
// See https://github.com/denoland/deno/issues/6649
let thrown = false;
try {
Deno.core.opSync("op_decode", new Uint8Array(2 ** 29));
Deno.core.ops.op_decode(new Uint8Array(2 ** 29));
} catch (e) {
thrown = true;
assert(e instanceof RangeError);

View file

@ -1,5 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
const { core } = Deno;
const { ops } = core;
class DOMException {
constructor(message, code) {
@ -16,7 +17,7 @@ core.registerErrorBuilder(
);
try {
core.opSync("op_err", undefined, null);
ops.op_err();
throw new Error("op_err didn't throw!");
} catch (err) {
if (!(err instanceof DOMException)) {

View file

@ -53,11 +53,11 @@ const arr = [1, 2, 3];
print("The sum of");
print(arr);
print("is");
print(Deno.core.opSync('op_sum', arr));
print(Deno.core.ops.op_sum(arr));
// And incorrect usage
try {
print(Deno.core.opSync('op_sum', 0));
print(Deno.core.ops.op_sum(0));
} catch(e) {
print('Exception:');
print(e);

View file

@ -11,7 +11,7 @@ const responseBuf = new Uint8Array(
/** Listens on 0.0.0.0:4500, returns rid. */
function listen() {
return Deno.core.opSync("op_listen");
return Deno.core.ops.op_listen();
}
/** Accepts a connection, returns rid. */

View file

@ -52,11 +52,11 @@ fn main() {
let future = async move {
// Schedule 10 tasks.
js_runtime
.execute_script(
"<usage>",
r#"for (let i = 1; i <= 10; i++) Deno.core.opSync("op_schedule_task", i);"#
)
.unwrap();
.execute_script(
"<usage>",
r#"for (let i = 1; i <= 10; i++) Deno.core.ops.op_schedule_task(i);"#,
)
.unwrap();
js_runtime.run_event_loop(false).await
};
runtime.block_on(future).unwrap();

View file

@ -10,15 +10,13 @@ declare namespace Deno {
/** Call an op in Rust, and synchronously receive the result. */
function opSync(
opName: string,
a?: any,
b?: any,
...args: any[]
): any;
/** Call an op in Rust, and asynchronously receive the result. */
function opAsync(
opName: string,
a?: any,
b?: any,
...args: any[]
): Promise<any>;
/** Mark following promise as "ref", ie. event loop won't exit
@ -30,10 +28,10 @@ declare namespace Deno {
function unrefOps(promiseId: number): void;
/**
* Retrieve a list of all registered ops, in the form of a map that maps op
* List of all registered ops, in the form of a map that maps op
* name to internal numerical op id.
*/
function ops(): Record<string, number>;
const ops: Record<string, (...args: unknown[]) => any>;
/**
* Retrieve a list of all open resources, in the form of a map that maps

View file

@ -1518,7 +1518,7 @@ import "/a.js";
import { b } from './b.js'
if (b() != 'b') throw Error();
let control = 42;
Deno.core.opSync("op_test", control);
Deno.core.ops.op_test(control);
"#,
)
.unwrap();

View file

@ -2301,8 +2301,8 @@ pub mod tests {
.execute_script(
"filename.js",
r#"
Deno.core.opSync("op_unref_op", p1[promiseIdSymbol]);
Deno.core.opSync("op_unref_op", p2[promiseIdSymbol]);
Deno.core.ops.op_unref_op(p1[promiseIdSymbol]);
Deno.core.ops.op_unref_op(p2[promiseIdSymbol]);
"#,
)
.unwrap();
@ -2317,8 +2317,8 @@ pub mod tests {
.execute_script(
"filename.js",
r#"
Deno.core.opSync("op_ref_op", p1[promiseIdSymbol]);
Deno.core.opSync("op_ref_op", p2[promiseIdSymbol]);
Deno.core.ops.op_ref_op(p1[promiseIdSymbol]);
Deno.core.ops.op_ref_op(p2[promiseIdSymbol]);
"#,
)
.unwrap();
@ -3045,7 +3045,7 @@ assertEquals(1, notify_return_value);
let error = runtime
.execute_script(
"core_js_stack_frame.js",
"Deno.core.opSync('non_existent');",
"Deno.core.opAsync('non_existent');",
)
.unwrap_err();
let error_string = error.to_string();
@ -3073,7 +3073,7 @@ assertEquals(1, notify_return_value);
(function () {
const o = { a: 1, b: 2};
const p = new Proxy(o, {});
return Deno.core.opSync("op_is_proxy", p) && !Deno.core.opSync("op_is_proxy", o) && !Deno.core.opSync("op_is_proxy", 42);
return Deno.core.ops.op_is_proxy(p) && !Deno.core.ops.op_is_proxy(o) && !Deno.core.ops.op_is_proxy(42);
})()
"#,
)
@ -3150,16 +3150,16 @@ assertEquals(1, notify_return_value);
r#"
(async function () {
const results = [];
Deno.core.opSync("op_set_macrotask_callback", () => {
Deno.core.ops.op_set_macrotask_callback(() => {
results.push("macrotask");
return true;
});
Deno.core.opSync("op_set_next_tick_callback", () => {
Deno.core.ops.op_set_next_tick_callback(() => {
results.push("nextTick");
Deno.core.opSync("op_set_has_tick_scheduled", false);
Deno.core.ops.op_set_has_tick_scheduled(false);
});
Deno.core.opSync("op_set_has_tick_scheduled", true);
Deno.core.ops.op_set_has_tick_scheduled(true);
await Deno.core.opAsync('op_async_sleep');
if (results[0] != "nextTick") {
throw new Error(`expected nextTick, got: ${results[0]}`);
@ -3182,10 +3182,10 @@ assertEquals(1, notify_return_value);
.execute_script(
"multiple_macrotasks_and_nextticks.js",
r#"
Deno.core.opSync("op_set_macrotask_callback", () => { return true; });
Deno.core.opSync("op_set_macrotask_callback", () => { return true; });
Deno.core.opSync("op_set_next_tick_callback", () => {});
Deno.core.opSync("op_set_next_tick_callback", () => {});
Deno.core.ops.op_set_macrotask_callback(() => { return true; });
Deno.core.ops.op_set_macrotask_callback(() => { return true; });
Deno.core.ops.op_set_next_tick_callback(() => {});
Deno.core.ops.op_set_next_tick_callback(() => {});
"#,
)
.unwrap();
@ -3228,12 +3228,12 @@ assertEquals(1, notify_return_value);
.execute_script(
"has_tick_scheduled.js",
r#"
Deno.core.opSync("op_set_macrotask_callback", () => {
Deno.core.opSync("op_macrotask");
Deno.core.ops.op_set_macrotask_callback(() => {
Deno.core.ops.op_macrotask();
return true; // We're done.
});
Deno.core.opSync("op_set_next_tick_callback", () => Deno.core.opSync("op_next_tick"));
Deno.core.opSync("op_set_has_tick_scheduled", true);
Deno.core.ops.op_set_next_tick_callback(() => Deno.core.ops.op_next_tick());
Deno.core.ops.op_set_has_tick_scheduled(true);
"#,
)
.unwrap();
@ -3359,15 +3359,15 @@ assertEquals(1, notify_return_value);
"promise_reject_callback.js",
r#"
// Note: |promise| is not the promise created below, it's a child.
Deno.core.opSync("op_set_promise_reject_callback", (type, promise, reason) => {
Deno.core.ops.op_set_promise_reject_callback((type, promise, reason) => {
if (type !== /* PromiseRejectWithNoHandler */ 0) {
throw Error("unexpected type: " + type);
}
if (reason.message !== "reject") {
throw Error("unexpected reason: " + reason);
}
Deno.core.opSync("op_store_pending_promise_exception", promise);
Deno.core.opSync("op_promise_reject");
Deno.core.ops.op_store_pending_promise_exception(promise);
Deno.core.ops.op_promise_reject();
});
new Promise((_, reject) => reject(Error("reject")));
@ -3383,7 +3383,7 @@ assertEquals(1, notify_return_value);
"promise_reject_callback.js",
r#"
{
const prev = Deno.core.opSync("op_set_promise_reject_callback", (...args) => {
const prev = Deno.core.ops.op_set_promise_reject_callback((...args) => {
prev(...args);
});
}
@ -3434,10 +3434,10 @@ assertEquals(1, notify_return_value);
_is_dyn_import: bool,
) -> Pin<Box<ModuleSourceFuture>> {
let source = r#"
Deno.core.opSync("op_set_promise_reject_callback", (type, promise, reason) => {
Deno.core.opSync("op_promise_reject");
Deno.core.ops.op_set_promise_reject_callback((type, promise, reason) => {
Deno.core.ops.op_promise_reject();
});
throw new Error('top level throw');
"#;
@ -3485,7 +3485,7 @@ assertEquals(1, notify_return_value);
assert!(runtime
.execute_script(
"test_op_return_serde_v8_error.js",
"Deno.core.opSync('op_err')"
"Deno.core.ops.op_err()"
)
.is_err());
}
@ -3508,7 +3508,7 @@ assertEquals(1, notify_return_value);
..Default::default()
});
let r = runtime
.execute_script("test.js", "Deno.core.opSync('op_add_4', 1, 2, 3, 4)")
.execute_script("test.js", "Deno.core.ops.op_add_4(1, 2, 3, 4)")
.unwrap();
let scope = &mut runtime.handle_scope();
assert_eq!(r.open(scope).integer_value(scope), Some(10));
@ -3529,7 +3529,7 @@ assertEquals(1, notify_return_value);
..Default::default()
});
let r = runtime
.execute_script("test.js", "Deno.core.opSync('op_foo')")
.execute_script("test.js", "Deno.core.ops.op_foo()")
.unwrap();
let scope = &mut runtime.handle_scope();
assert!(r.open(scope).is_undefined());
@ -3573,7 +3573,7 @@ assertEquals(1, notify_return_value);
if (!(a1.length > 0 && a1b.length > 0)) {
throw new Error("a1 & a1b should have a length");
}
let sum = Deno.core.opSync('op_sum_take', a1b);
let sum = Deno.core.ops.op_sum_take(a1b);
if (sum !== 6) {
throw new Error(`Bad sum: ${sum}`);
}
@ -3581,7 +3581,7 @@ assertEquals(1, notify_return_value);
throw new Error("expecting a1 & a1b to be detached");
}
const a3 = Deno.core.opSync('op_boomerang', a2b);
const a3 = Deno.core.ops.op_boomerang(a2b);
if (a3.byteLength != 3) {
throw new Error(`Expected a3.byteLength === 3, got ${a3.byteLength}`);
}
@ -3597,7 +3597,7 @@ assertEquals(1, notify_return_value);
w32[0] = 1; w32[1] = 2; w32[2] = 3;
const assertWasmThrow = (() => {
try {
let sum = Deno.core.opSync('op_sum_take', w32.subarray(0, 2));
let sum = Deno.core.ops.op_sum_take(w32.subarray(0, 2));
return false;
} catch(e) {
return e.message.includes('ExpectedDetachable');
@ -3635,10 +3635,10 @@ assertEquals(1, notify_return_value);
.execute_script(
"test.js",
r#"
if (Deno.core.opSync('op_foo') !== 42) {
if (Deno.core.ops.op_foo() !== 42) {
throw new Error("Exptected op_foo() === 42");
}
if (Deno.core.opSync('op_bar') !== undefined) {
if (Deno.core.ops.op_bar() !== undefined) {
throw new Error("Expected op_bar to be disabled")
}
"#,
@ -3680,7 +3680,7 @@ assertEquals(1, notify_return_value);
});
let realm = runtime.create_realm().unwrap();
let ret = realm
.execute_script(runtime.v8_isolate(), "", "Deno.core.opSync('op_test')")
.execute_script(runtime.v8_isolate(), "", "Deno.core.ops.op_test()")
.unwrap();
let scope = &mut realm.handle_scope(runtime.v8_isolate());
@ -3710,7 +3710,7 @@ assertEquals(1, notify_return_value);
});
let realm = runtime.create_realm().unwrap();
let ret = realm
.execute_script(runtime.v8_isolate(), "", "Deno.core.opSync('op_test')")
.execute_script(runtime.v8_isolate(), "", "Deno.core.ops.op_test()")
.unwrap();
let scope = &mut realm.handle_scope(runtime.v8_isolate());
@ -3749,10 +3749,10 @@ assertEquals(1, notify_return_value);
runtime.v8_isolate(),
"",
r#"
const buf = Deno.core.opSync("op_test", false);
const buf = Deno.core.ops.op_test(false);
let err;
try {
Deno.core.opSync("op_test", true);
Deno.core.ops.op_test(true);
} catch(e) {
err = e;
}
@ -3870,7 +3870,7 @@ assertEquals(1, notify_return_value);
"",
r#"
let promiseIdSymbol = Symbol.for("Deno.core.internalPromiseId");
Deno.core.opSync("op_unref_op", promise[promiseIdSymbol]);
Deno.core.ops.op_unref_op(promise[promiseIdSymbol]);
"#,
)
.unwrap();
@ -3882,7 +3882,7 @@ assertEquals(1, notify_return_value);
"",
r#"
let promiseIdSymbol = Symbol.for("Deno.core.internalPromiseId");
Deno.core.opSync("op_unref_op", promise[promiseIdSymbol]);
Deno.core.ops.op_unref_op(promise[promiseIdSymbol]);
"#,
)
.unwrap();

View file

@ -21,12 +21,11 @@ function main() {
const emptyString = "";
const emptyStringSerialized = [255, 15, 34, 0];
assertArrayEquals(
Deno.core.opSync("op_serialize", emptyString),
Deno.core.ops.op_serialize(emptyString),
emptyStringSerialized,
);
assert(
Deno.core.opSync(
"op_deserialize",
Deno.core.ops.op_deserialize(
new Uint8Array(emptyStringSerialized),
) ===
emptyString,
@ -39,13 +38,12 @@ function main() {
34, 1, 97, 48, 95, 36, 0, 4,
];
assertArrayEquals(
Deno.core.opSync("op_serialize", primitiveValueArray),
Deno.core.ops.op_serialize(primitiveValueArray),
primitiveValueArraySerialized,
);
assertArrayEquals(
Deno.core.opSync(
"op_deserialize",
Deno.core.ops.op_deserialize(
new Uint8Array(primitiveValueArraySerialized),
),
primitiveValueArray,
@ -63,12 +61,11 @@ function main() {
];
assertArrayEquals(
Deno.core.opSync("op_serialize", circularObject),
Deno.core.ops.op_serialize(circularObject),
circularObjectSerialized,
);
const deserializedCircularObject = Deno.core.opSync(
"op_deserialize",
const deserializedCircularObject = Deno.core.ops.op_deserialize(
new Uint8Array(circularObjectSerialized),
);
assert(deserializedCircularObject.test == deserializedCircularObject);

View file

@ -6,6 +6,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { defineEventHandler, setTarget } = window.__bootstrap.event;
const { DOMException } = window.__bootstrap.domException;
@ -92,7 +93,7 @@
if (rid === null) {
// Create the rid immediately, otherwise there is a time window (and a
// race condition) where messages can get lost, because recv() is async.
rid = core.opSync("op_broadcast_subscribe");
rid = ops.op_broadcast_subscribe();
recv();
}
}
@ -128,7 +129,9 @@
if (index === -1) return;
ArrayPrototypeSplice(channels, index, 1);
if (channels.length === 0) core.opSync("op_broadcast_unsubscribe", rid);
if (channels.length === 0) {
ops.op_broadcast_unsubscribe(rid);
}
}
}

View file

@ -10,6 +10,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { DOMException } = window.__bootstrap.domException;
@ -1374,7 +1375,7 @@
switch (normalizedAlgorithm.name) {
case "AES-KW": {
const cipherText = await core.opSync("op_crypto_wrap_key", {
const cipherText = await ops.op_crypto_wrap_key({
key: keyData,
algorithm: normalizedAlgorithm.name,
}, bytes);
@ -1510,7 +1511,7 @@
switch (normalizedAlgorithm.name) {
case "AES-KW": {
const plainText = await core.opSync("op_crypto_unwrap_key", {
const plainText = await ops.op_crypto_unwrap_key({
key: keyData,
algorithm: normalizedAlgorithm.name,
}, wrappedKey);
@ -1986,7 +1987,7 @@
};
// 3.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
format: "jwksecret",
algorithm: "AES",
}, innerKey);
@ -2080,8 +2081,7 @@
}
// 4.
const { rawData } = core.opSync(
"op_crypto_import_key",
const { rawData } = ops.op_crypto_import_key(
{ algorithm: "AES" },
{ jwkSecret: jwk },
);
@ -2241,8 +2241,7 @@
}
// 4.
const { rawData } = core.opSync(
"op_crypto_import_key",
const { rawData } = ops.op_crypto_import_key(
{ algorithm: "HMAC" },
{ jwkSecret: jwk },
);
@ -2427,7 +2426,7 @@
}
// 3.
const { rawData } = core.opSync("op_crypto_import_key", {
const { rawData } = ops.op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { raw: keyData });
@ -2468,7 +2467,7 @@
}
// 2-9.
const { rawData } = core.opSync("op_crypto_import_key", {
const { rawData } = ops.op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { pkcs8: keyData });
@ -2511,7 +2510,7 @@
}
// 2-12
const { rawData } = core.opSync("op_crypto_import_key", {
const { rawData } = ops.op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { spki: keyData });
@ -2655,7 +2654,7 @@
if (jwk.d !== undefined) {
// it's also a Private key
const { rawData } = core.opSync("op_crypto_import_key", {
const { rawData } = ops.op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { jwkPrivateEc: jwk });
@ -2678,7 +2677,7 @@
return key;
} else {
const { rawData } = core.opSync("op_crypto_import_key", {
const { rawData } = ops.op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { jwkPublicEc: jwk });
@ -2759,15 +2758,15 @@
}
// 2-9.
const { modulusLength, publicExponent, rawData } = core.opSync(
"op_crypto_import_key",
{
algorithm: normalizedAlgorithm.name,
// Needed to perform step 7 without normalization.
hash: normalizedAlgorithm.hash.name,
},
{ pkcs8: keyData },
);
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
// Needed to perform step 7 without normalization.
hash: normalizedAlgorithm.hash.name,
},
{ pkcs8: keyData },
);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, rawData);
@ -2805,15 +2804,15 @@
}
// 2-9.
const { modulusLength, publicExponent, rawData } = core.opSync(
"op_crypto_import_key",
{
algorithm: normalizedAlgorithm.name,
// Needed to perform step 7 without normalization.
hash: normalizedAlgorithm.hash.name,
},
{ spki: keyData },
);
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
// Needed to perform step 7 without normalization.
hash: normalizedAlgorithm.hash.name,
},
{ spki: keyData },
);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, rawData);
@ -3055,14 +3054,14 @@
);
}
const { modulusLength, publicExponent, rawData } = core.opSync(
"op_crypto_import_key",
{
algorithm: normalizedAlgorithm.name,
hash: normalizedAlgorithm.hash.name,
},
{ jwkPrivateRsa: jwk },
);
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
hash: normalizedAlgorithm.hash.name,
},
{ jwkPrivateRsa: jwk },
);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, rawData);
@ -3098,14 +3097,14 @@
);
}
const { modulusLength, publicExponent, rawData } = core.opSync(
"op_crypto_import_key",
{
algorithm: normalizedAlgorithm.name,
hash: normalizedAlgorithm.hash.name,
},
{ jwkPublicRsa: jwk },
);
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
hash: normalizedAlgorithm.hash.name,
},
{ jwkPublicRsa: jwk },
);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, rawData);
@ -3259,7 +3258,7 @@
};
// 3.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
format: "jwksecret",
algorithm: key[_algorithm].name,
}, innerKey);
@ -3313,7 +3312,7 @@
}
// 2.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
algorithm: key[_algorithm].name,
format: "pkcs8",
}, innerKey);
@ -3331,7 +3330,7 @@
}
// 2.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
algorithm: key[_algorithm].name,
format: "spki",
}, innerKey);
@ -3412,7 +3411,7 @@
}
// 5-6.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
format: key[_type] === "private" ? "jwkprivate" : "jwkpublic",
algorithm: key[_algorithm].name,
}, innerKey);
@ -3443,7 +3442,7 @@
}
// 2.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
format: "raw",
@ -3461,7 +3460,7 @@
}
// 2.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
format: "pkcs8",
@ -3479,7 +3478,7 @@
}
// 2.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
format: "spki",
@ -3523,7 +3522,7 @@
jwk.alg = algNamedCurve;
// 3.2 - 3.4.
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
format: key[_type] === "private" ? "jwkprivate" : "jwkpublic",
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
@ -3550,7 +3549,7 @@
jwk.crv = key[_algorithm].namedCurve;
// 3.2 - 3.4
const data = core.opSync("op_crypto_export_key", {
const data = ops.op_crypto_export_key({
format: key[_type] === "private" ? "jwkprivate" : "jwkpublic",
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
@ -3925,13 +3924,13 @@
arrayBufferView.byteOffset,
arrayBufferView.byteLength,
);
core.opSync("op_crypto_get_random_values", ui8);
ops.op_crypto_get_random_values(ui8);
return arrayBufferView;
}
randomUUID() {
webidl.assertBranded(this, CryptoPrototype);
return core.opSync("op_crypto_random_uuid");
return ops.op_crypto_random_uuid();
}
get subtle() {

View file

@ -13,6 +13,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
/**
* @param {Deno.CreateHttpClientOptions} options
@ -21,8 +22,7 @@
function createHttpClient(options) {
options.caCerts ??= [];
return new HttpClient(
core.opSync(
"op_fetch_custom_client",
ops.op_fetch_custom_client(
options,
),
);

View file

@ -13,6 +13,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { byteLowerCase } = window.__bootstrap.infra;
const { BlobPrototype } = window.__bootstrap.file;
@ -68,8 +69,7 @@
* @returns {{ requestRid: number, requestBodyRid: number | null }}
*/
function opFetch(method, url, headers, clientRid, hasBody, bodyLength, body) {
return core.opSync(
"op_fetch",
return ops.op_fetch(
method,
url,
headers,
@ -560,7 +560,7 @@
}
// Pass the resolved URL to v8.
core.opSync("op_wasm_streaming_set_url", rid, res.url);
ops.op_wasm_streaming_set_url(rid, res.url);
if (res.body !== null) {
// 2.6.
@ -571,7 +571,7 @@
while (true) {
const { value: chunk, done } = await reader.read();
if (done) break;
core.opSync("op_wasm_streaming_feed", rid, chunk);
ops.op_wasm_streaming_feed(rid, chunk);
}
})().then(
// 2.7

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const __bootstrap = window.__bootstrap;
const {
BigInt,
@ -45,108 +46,93 @@
}
getUint8(offset = 0) {
return core.opSync(
"op_ffi_read_u8",
return ops.op_ffi_read_u8(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getInt8(offset = 0) {
return core.opSync(
"op_ffi_read_i8",
return ops.op_ffi_read_i8(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getUint16(offset = 0) {
return core.opSync(
"op_ffi_read_u16",
return ops.op_ffi_read_u16(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getInt16(offset = 0) {
return core.opSync(
"op_ffi_read_i16",
return ops.op_ffi_read_i16(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getUint32(offset = 0) {
return core.opSync(
"op_ffi_read_u32",
return ops.op_ffi_read_u32(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getInt32(offset = 0) {
return core.opSync(
"op_ffi_read_i32",
return ops.op_ffi_read_i32(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getBigUint64(offset = 0) {
return core.opSync(
"op_ffi_read_u64",
return ops.op_ffi_read_u64(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getBigInt64(offset = 0) {
return core.opSync(
"op_ffi_read_i64",
return ops.op_ffi_read_i64(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getFloat32(offset = 0) {
return core.opSync(
"op_ffi_read_f32",
return ops.op_ffi_read_f32(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getFloat64(offset = 0) {
return core.opSync(
"op_ffi_read_f64",
return ops.op_ffi_read_f64(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
getCString(offset = 0) {
return core.opSync(
"op_ffi_cstr_read",
return ops.op_ffi_cstr_read(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
);
}
static getCString(pointer, offset = 0) {
return core.opSync(
"op_ffi_cstr_read",
return ops.op_ffi_cstr_read(
offset ? BigInt(pointer) + BigInt(offset) : pointer,
);
}
getArrayBuffer(byteLength, offset = 0) {
return core.opSync(
"op_ffi_get_buf",
return ops.op_ffi_get_buf(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
byteLength,
);
}
static getArrayBuffer(pointer, byteLength, offset = 0) {
return core.opSync(
"op_ffi_get_buf",
return ops.op_ffi_get_buf(
offset ? BigInt(pointer) + BigInt(offset) : pointer,
byteLength,
);
}
copyInto(destination, offset = 0) {
core.opSync(
"op_ffi_buf_copy_into",
ops.op_ffi_buf_copy_into(
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
destination,
destination.byteLength,
@ -154,8 +140,7 @@
}
static copyInto(pointer, destination, offset = 0) {
core.opSync(
"op_ffi_buf_copy_into",
ops.op_ffi_buf_copy_into(
offset ? BigInt(pointer) + BigInt(offset) : pointer,
destination,
destination.byteLength,
@ -168,7 +153,7 @@
if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {
return value.pointer;
}
return core.opSync("op_ffi_ptr_of", value);
return ops.op_ffi_ptr_of(value);
}
}
@ -221,8 +206,7 @@
return promise;
} else {
return core.opSync(
"op_ffi_call_ptr",
return ops.op_ffi_call_ptr(
this.pointer,
this.definition,
parameters,
@ -258,8 +242,7 @@
"Invalid UnsafeCallback, cannot be nonblocking",
);
}
const [rid, pointer] = core.opSync(
"op_ffi_unsafe_callback_create",
const [rid, pointer] = ops.op_ffi_unsafe_callback_create(
definition,
callback,
);
@ -272,7 +255,7 @@
ref() {
if (this.#refcount++ === 0) {
core.opSync("op_ffi_unsafe_callback_ref", true);
ops.op_ffi_unsafe_callback_ref(true);
}
}
@ -280,14 +263,14 @@
// Only decrement refcount if it is positive, and only
// unref the callback if refcount reaches zero.
if (this.#refcount > 0 && --this.#refcount === 0) {
core.opSync("op_ffi_unsafe_callback_ref", false);
ops.op_ffi_unsafe_callback_ref(false);
}
}
close() {
if (this.#refcount) {
this.#refcount = 0;
core.opSync("op_ffi_unsafe_callback_ref", false);
ops.op_ffi_unsafe_callback_ref(false);
}
core.close(this.#rid);
}
@ -300,7 +283,7 @@
symbols = {};
constructor(path, symbols) {
[this.#rid, this.symbols] = core.opSync("op_ffi_load", { path, symbols });
[this.#rid, this.symbols] = ops.op_ffi_load({ path, symbols });
for (const symbol in symbols) {
if ("type" in symbols[symbol]) {
const type = symbols[symbol].type;
@ -311,8 +294,7 @@
}
const name = symbols[symbol].name || symbol;
const value = core.opSync(
"op_ffi_get_static",
const value = ops.op_ffi_get_static(
this.#rid,
name,
type,

View file

@ -15,7 +15,7 @@
fromInnerResponse,
} = window.__bootstrap.fetch;
const core = window.Deno.core;
const { BadResourcePrototype, InterruptedPrototype } = core;
const { BadResourcePrototype, InterruptedPrototype, ops } = core;
const { ReadableStream, ReadableStreamPrototype } =
window.__bootstrap.streams;
const abortSignal = window.__bootstrap.abortSignal;
@ -126,7 +126,7 @@
const innerRequest = newInnerRequest(
method,
url,
() => core.opSync("op_http_headers", streamRid),
() => ops.op_http_headers(streamRid),
body !== null ? new InnerBody(body) : null,
false,
);
@ -438,7 +438,7 @@
);
}
const accept = core.opSync("op_http_websocket_accept_header", websocketKey);
const accept = ops.op_http_websocket_accept_header(websocketKey);
const r = newInnerResponse(101);
r.headerList = [

View file

@ -3,7 +3,7 @@
((window) => {
const core = window.Deno.core;
const { BadResourcePrototype, InterruptedPrototype } = core;
const { BadResourcePrototype, InterruptedPrototype, ops } = core;
const { WritableStream, readableStreamForRid } = window.__bootstrap.streams;
const {
Error,
@ -42,7 +42,7 @@
}
function opListen(args) {
return core.opSync("op_net_listen", args);
return ops.op_net_listen(args);
}
function opConnect(args) {
@ -157,11 +157,11 @@
class TcpConn extends Conn {
setNoDelay(nodelay = true) {
return core.opSync("op_set_nodelay", this.rid, nodelay);
return ops.op_set_nodelay(this.rid, nodelay);
}
setKeepAlive(keepalive = true) {
return core.opSync("op_set_keepalive", this.rid, keepalive);
return ops.op_set_keepalive(this.rid, keepalive);
}
}

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { Listener, Conn } = window.__bootstrap.net;
function opConnectTls(
@ -16,7 +17,7 @@
}
function opListenTls(args) {
return core.opSync("op_tls_listen", args);
return ops.op_tls_listen(args);
}
function opStartTls(args) {

View file

@ -31,16 +31,17 @@
RegExpPrototypeTest,
} = window.__bootstrap.primordials;
const core = window.Deno.core;
const ops = core.ops;
// Map used to store CJS parsing data.
const cjsParseCache = new SafeWeakMap();
function pathDirname(filepath) {
return core.opSync("op_require_path_dirname", filepath);
return ops.op_require_path_dirname(filepath);
}
function pathResolve(...args) {
return core.opSync("op_require_path_resolve", args);
return ops.op_require_path_resolve(args);
}
function assert(cond) {
@ -76,7 +77,7 @@
return result;
}
}
const result = core.opSync("op_require_stat", filename);
const result = ops.op_require_stat(filename);
if (statCache !== null && result >= 0) {
statCache.set(filename, result);
}
@ -162,7 +163,7 @@
if (maybeCached) {
return maybeCached;
}
const rp = core.opSync("op_require_real_path", requestPath);
const rp = ops.op_require_real_path(requestPath);
realpathCache.set(requestPath, rp);
return rp;
}
@ -181,7 +182,7 @@
// Find the longest (possibly multi-dot) extension registered in
// Module._extensions
function findLongestRegisteredExtension(filename) {
const name = core.opSync("op_require_path_basename", filename);
const name = ops.op_require_path_basename(filename);
let currentExtension;
let index;
let startIndex = 0;
@ -269,7 +270,7 @@
const CHAR_FORWARD_SLASH = 47;
const TRAILING_SLASH_REGEX = /(?:^|\/)\.?\.$/;
Module._findPath = function (request, paths, isMain) {
const absoluteRequest = core.opSync("op_require_path_is_absolute", request);
const absoluteRequest = ops.op_require_path_is_absolute(request);
if (absoluteRequest) {
paths = [""];
} else if (!paths || paths.length === 0) {
@ -346,12 +347,11 @@
};
Module._nodeModulePaths = function (from) {
return core.opSync("op_require_node_module_paths", from);
return ops.op_require_node_module_paths(from);
};
Module._resolveLookupPaths = function (request, parent) {
return core.opSync(
"op_require_resolve_lookup_paths",
return ops.op_require_resolve_lookup_paths(
request,
parent?.paths,
parent?.filename ?? "",
@ -475,8 +475,7 @@
if (typeof options === "object" && options !== null) {
if (ArrayIsArray(options.paths)) {
const isRelative = core.opSync(
"op_require_is_request_relative",
const isRelative = ops.op_require_is_request_relative(
request,
);
@ -537,13 +536,12 @@
// Try module self resolution first
// TODO(bartlomieju): make into a single op
const parentPath = core.opSync(
"op_require_try_self_parent_path",
const parentPath = ops.op_require_try_self_parent_path(
!!parent,
parent?.filename,
parent?.id,
);
// const selfResolved = core.opSync("op_require_try_self", parentPath, request);
// const selfResolved = ops.op_require_try_self(parentPath, request);
const selfResolved = false;
if (selfResolved) {
const cacheKey = request + "\x00" +
@ -666,7 +664,7 @@
};
Module._extensions[".js"] = function (module, filename) {
const content = core.opSync("op_require_read_file", filename);
const content = ops.op_require_read_file(filename);
console.log(`TODO: Module._extensions[".js"] is ESM`);
@ -682,7 +680,7 @@
// Native extension for .json
Module._extensions[".json"] = function (module, filename) {
const content = core.opSync("op_require_read_file", filename);
const content = ops.op_require_read_file(filename);
try {
module.exports = JSONParse(stripBOM(content));
@ -698,7 +696,7 @@
};
function createRequireFromPath(filename) {
const proxyPath = core.opSync("op_require_proxy_path", filename);
const proxyPath = ops.op_require_proxy_path(filename);
const mod = new Module(proxyPath);
mod.filename = proxyPath;
mod.paths = Module._nodeModulePaths(mod.path);
@ -737,7 +735,7 @@
Module.createRequire = createRequire;
Module._initPaths = function () {
const paths = core.opSync("op_require_init_paths");
const paths = ops.op_require_init_paths();
modulePaths = paths;
Module.globalPaths = ArrayPrototypeSlice(modulePaths);
};

View file

@ -9,6 +9,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const {
ArrayIsArray,
@ -43,10 +44,12 @@
// Helper functions
function opUrlReparse(href, setter, value) {
return _urlParts(core.opSync("op_url_reparse", href, [setter, value]));
return _urlParts(
ops.op_url_reparse(href, [setter, value]),
);
}
function opUrlParse(href, maybeBase) {
return _urlParts(core.opSync("op_url_parse", href, maybeBase));
return _urlParts(ops.op_url_parse(href, maybeBase));
}
function _urlParts(internalParts) {
// WARNING: must match UrlParts serialization rust's url_result()
@ -101,7 +104,7 @@
if (init[0] == "?") {
init = StringPrototypeSlice(init, 1);
}
this[_list] = core.opSync("op_url_parse_search_params", init);
this[_list] = ops.op_url_parse_search_params(init);
} else if (ArrayIsArray(init)) {
// Overload: sequence<sequence<USVString>>
this[_list] = ArrayPrototypeMap(init, (pair, i) => {
@ -291,7 +294,7 @@
*/
toString() {
webidl.assertBranded(this, URLSearchParamsPrototype);
return core.opSync("op_url_stringify_search_params", this[_list]);
return ops.op_url_stringify_search_params(this[_list]);
}
}
@ -348,8 +351,7 @@
#updateSearchParams() {
if (this.#queryObject !== null) {
const params = this.#queryObject[_list];
const newParams = core.opSync(
"op_url_parse_search_params",
const newParams = ops.op_url_parse_search_params(
StringPrototypeSlice(this.search, 1),
);
ArrayPrototypeSplice(
@ -617,7 +619,7 @@
* @returns {[string, string][]}
*/
function parseUrlEncoded(bytes) {
return core.opSync("op_url_parse_search_params", null, bytes);
return ops.op_url_parse_search_params(null, bytes);
}
webidl

View file

@ -11,6 +11,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const {
ArrayPrototypeMap,
@ -68,7 +69,7 @@
});
}
const components = core.opSync("op_urlpattern_parse", input, baseURL);
const components = ops.op_urlpattern_parse(input, baseURL);
for (const key of ObjectKeys(components)) {
try {
@ -144,8 +145,7 @@
});
}
const res = core.opSync(
"op_urlpattern_process_match_input",
const res = ops.op_urlpattern_process_match_input(
input,
baseURL,
);
@ -184,8 +184,7 @@
});
}
const res = core.opSync(
"op_urlpattern_process_match_input",
const res = ops.op_urlpattern_process_match_input(
input,
baseURL,
);

View file

@ -10,6 +10,7 @@
((window) => {
const core = Deno.core;
const ops = core.ops;
const {
ArrayPrototypeJoin,
ArrayPrototypeMap,
@ -239,7 +240,7 @@
* @returns {string}
*/
function forgivingBase64Encode(data) {
return core.opSync("op_base64_encode", data);
return ops.op_base64_encode(data);
}
/**
@ -247,7 +248,7 @@
* @returns {Uint8Array}
*/
function forgivingBase64Decode(data) {
return core.opSync("op_base64_decode", data);
return ops.op_base64_decode(data);
}
/**

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const {
ArrayPrototypePush,
ArrayPrototypeShift,
@ -25,7 +26,7 @@
const { assert } = window.__bootstrap.infra;
function opNow() {
return core.opSync("op_now");
return ops.op_now();
}
// ---------------------------------------------------------------------------
@ -103,7 +104,7 @@
// TODO(@andreubotella): Deal with overflow.
// https://github.com/whatwg/html/issues/7358
id = nextId++;
const cancelRid = core.opSync("op_timer_handle");
const cancelRid = ops.op_timer_handle();
timerInfo = { cancelRid, isRef: true, promiseId: -1 };
// Step 4 in "run steps after a timeout".

View file

@ -10,6 +10,7 @@
((window) => {
const core = Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { DOMException } = window.__bootstrap.domException;
const { TypeError } = window.__bootstrap.primordials;
@ -26,7 +27,7 @@
context: "Argument 1",
});
try {
return core.opSync("op_base64_atob", data);
return ops.op_base64_atob(data);
} catch (e) {
if (e instanceof TypeError) {
throw new DOMException(
@ -50,7 +51,7 @@
context: "Argument 1",
});
try {
return core.opSync("op_base64_btoa", data);
return ops.op_base64_btoa(data);
} catch (e) {
if (e instanceof TypeError) {
throw new DOMException(

View file

@ -13,6 +13,7 @@
((window) => {
const core = Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const {
ArrayBufferIsView,
@ -51,7 +52,7 @@
prefix,
context: "Argument 2",
});
const encoding = core.opSync("op_encoding_normalize_label", label);
const encoding = ops.op_encoding_normalize_label(label);
this.#encoding = encoding;
this.#fatal = options.fatal;
this.#ignoreBOM = options.ignoreBOM;
@ -124,7 +125,7 @@
}
if (!options.stream && this.#rid === null) {
return core.opSync("op_encoding_decode_single", input, {
return ops.op_encoding_decode_single(input, {
label: this.#encoding,
fatal: this.#fatal,
ignoreBom: this.#ignoreBOM,
@ -132,13 +133,13 @@
}
if (this.#rid === null) {
this.#rid = core.opSync("op_encoding_new_decoder", {
this.#rid = ops.op_encoding_new_decoder({
label: this.#encoding,
fatal: this.#fatal,
ignoreBom: this.#ignoreBOM,
});
}
return core.opSync("op_encoding_decode", input, {
return ops.op_encoding_decode(input, {
rid: this.#rid,
stream: options.stream,
});
@ -200,7 +201,7 @@
context: "Argument 2",
allowShared: true,
});
return core.opSync("op_encoding_encode_into", source, destination);
return ops.op_encoding_encode_into(source, destination);
}
}

View file

@ -13,6 +13,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const {
ArrayBufferPrototype,
@ -505,7 +506,7 @@
// A finalization registry to deallocate a blob part when its JS reference is
// garbage collected.
const registry = new FinalizationRegistry((uuid) => {
core.opSync("op_blob_remove_part", uuid);
ops.op_blob_remove_part(uuid);
});
// TODO(lucacasonato): get a better stream from Rust in BlobReference#stream
@ -533,7 +534,7 @@
* @returns {BlobReference}
*/
static fromUint8Array(data) {
const id = core.opSync("op_blob_create_part", data);
const id = ops.op_blob_create_part(data);
return new BlobReference(id, data.byteLength);
}
@ -548,7 +549,7 @@
*/
slice(start, end) {
const size = end - start;
const id = core.opSync("op_blob_slice_part", this._id, {
const id = ops.op_blob_slice_part(this._id, {
start,
len: size,
});
@ -588,7 +589,7 @@
* @returns {Blob | null}
*/
function blobFromObjectUrl(url) {
const blobData = core.opSync("op_blob_from_object_url", url);
const blobData = ops.op_blob_from_object_url(url);
if (blobData === null) {
return null;
}

View file

@ -14,6 +14,7 @@
((window) => {
const core = Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { getParts } = window.__bootstrap.file;
const { URL } = window.__bootstrap.url;
@ -30,8 +31,7 @@
prefix,
});
const url = core.opSync(
"op_blob_create_object_url",
const url = ops.op_blob_create_object_url(
blob.type,
getParts(blob),
);
@ -51,7 +51,7 @@
prefix,
});
core.opSync("op_blob_revoke_object_url", url);
ops.op_blob_revoke_object_url(url);
}
URL.createObjectURL = createObjectURL;

View file

@ -10,7 +10,7 @@
((window) => {
const core = window.Deno.core;
const { InterruptedPrototype } = core;
const { InterruptedPrototype, ops } = core;
const webidl = window.__bootstrap.webidl;
const { setEventTargetData } = window.__bootstrap.eventTarget;
const { defineEventHandler } = window.__bootstrap.event;
@ -128,7 +128,7 @@
}
const data = serializeJsMessageData(message, transfer);
if (this[_id] === null) return;
core.opSync("op_message_port_post_message", this[_id], data);
ops.op_message_port_post_message(this[_id], data);
}
start() {
@ -193,7 +193,7 @@
* @returns {[number, number]}
*/
function opCreateEntangledMessagePort() {
return core.opSync("op_message_port_create_entangled");
return ops.op_message_port_create_entangled();
}
/**

View file

@ -9,6 +9,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { TransformStream } = window.__bootstrap.streams;
@ -32,7 +33,7 @@
context: "Argument 1",
});
const rid = core.opSync("op_compression_new", format, false);
const rid = ops.op_compression_new(format, false);
this.#transform = new TransformStream({
transform(chunk, controller) {
@ -40,15 +41,14 @@
prefix,
context: "chunk",
});
const output = core.opSync(
"op_compression_write",
const output = ops.op_compression_write(
rid,
chunk,
);
maybeEnqueue(controller, output);
},
flush(controller) {
const output = core.opSync("op_compression_finish", rid);
const output = ops.op_compression_finish(rid);
maybeEnqueue(controller, output);
},
});
@ -81,7 +81,7 @@
context: "Argument 1",
});
const rid = core.opSync("op_compression_new", format, true);
const rid = ops.op_compression_new(format, true);
this.#transform = new TransformStream({
transform(chunk, controller) {
@ -89,15 +89,14 @@
prefix,
context: "chunk",
});
const output = core.opSync(
"op_compression_write",
const output = ops.op_compression_write(
rid,
chunk,
);
maybeEnqueue(controller, output);
},
flush(controller) {
const output = core.opSync("op_compression_finish", rid);
const output = ops.op_compression_finish(rid);
maybeEnqueue(controller, output);
},
});

View file

@ -10,6 +10,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const eventTarget = window.__bootstrap.eventTarget;
const { DOMException } = window.__bootstrap.domException;
@ -940,8 +941,7 @@
context: "Argument 1",
});
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync(
"op_webgpu_create_buffer",
const { rid, err } = ops.op_webgpu_create_buffer(
device.rid,
descriptor.label,
descriptor.size,
@ -991,7 +991,7 @@
context: "Argument 1",
});
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync("op_webgpu_create_texture", {
const { rid, err } = ops.op_webgpu_create_texture({
deviceRid: device.rid,
...descriptor,
size: normalizeGPUExtent3D(descriptor.size),
@ -1019,7 +1019,7 @@
context: "Argument 1",
});
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync("op_webgpu_create_sampler", {
const { rid, err } = ops.op_webgpu_create_sampler({
deviceRid: device.rid,
...descriptor,
});
@ -1059,8 +1059,7 @@
}
}
const { rid, err } = core.opSync(
"op_webgpu_create_bind_group_layout",
const { rid, err } = ops.op_webgpu_create_bind_group_layout(
device.rid,
descriptor.label,
descriptor.entries,
@ -1102,8 +1101,7 @@
return rid;
},
);
const { rid, err } = core.opSync(
"op_webgpu_create_pipeline_layout",
const { rid, err } = ops.op_webgpu_create_pipeline_layout(
device.rid,
descriptor.label,
bindGroupLayouts,
@ -1197,8 +1195,7 @@
}
});
const { rid, err } = core.opSync(
"op_webgpu_create_bind_group",
const { rid, err } = ops.op_webgpu_create_bind_group(
device.rid,
descriptor.label,
layout,
@ -1227,8 +1224,7 @@
context: "Argument 1",
});
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync(
"op_webgpu_create_shader_module",
const { rid, err } = ops.op_webgpu_create_shader_module(
device.rid,
descriptor.label,
descriptor.code,
@ -1278,8 +1274,7 @@
selfContext: "this",
});
const { rid, err } = core.opSync(
"op_webgpu_create_compute_pipeline",
const { rid, err } = ops.op_webgpu_create_compute_pipeline(
device.rid,
descriptor.label,
layout,
@ -1350,7 +1345,7 @@
};
}
const { rid, err } = core.opSync("op_webgpu_create_render_pipeline", {
const { rid, err } = ops.op_webgpu_create_render_pipeline({
deviceRid: device.rid,
label: descriptor.label,
layout,
@ -1397,8 +1392,7 @@
context: "Argument 1",
});
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync(
"op_webgpu_create_command_encoder",
const { rid, err } = ops.op_webgpu_create_command_encoder(
device.rid,
descriptor.label,
);
@ -1430,8 +1424,7 @@
},
);
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync(
"op_webgpu_create_render_bundle_encoder",
const { rid, err } = ops.op_webgpu_create_render_bundle_encoder(
{
deviceRid: device.rid,
...descriptor,
@ -1464,7 +1457,7 @@
},
);
const device = assertDevice(this, { prefix, context: "this" });
const { rid, err } = core.opSync("op_webgpu_create_query_set", {
const { rid, err } = ops.op_webgpu_create_query_set({
deviceRid: device.rid,
...descriptor,
});
@ -1595,8 +1588,7 @@
return rid;
},
);
const { err } = core.opSync(
"op_webgpu_queue_submit",
const { err } = ops.op_webgpu_queue_submit(
device.rid,
commandBufferRids,
);
@ -1654,8 +1646,7 @@
selfContext: "this",
resourceContext: "Argument 1",
});
const { err } = core.opSync(
"op_webgpu_write_buffer",
const { err } = ops.op_webgpu_write_buffer(
device.rid,
bufferRid,
bufferOffset,
@ -1702,8 +1693,7 @@
selfContext: "this",
resourceContext: "texture",
});
const { err } = core.opSync(
"op_webgpu_write_texture",
const { err } = ops.op_webgpu_write_texture(
device.rid,
{
texture: textureRid,
@ -1960,8 +1950,7 @@
}
const buffer = new ArrayBuffer(rangeSize);
const { rid } = core.opSync(
"op_webgpu_buffer_get_mapped_range",
const { rid } = ops.op_webgpu_buffer_get_mapped_range(
bufferRid,
offset,
size,
@ -2015,8 +2004,7 @@
throw new DOMException(`${prefix}: invalid state.`, "OperationError");
}
for (const [buffer, mappedRid] of mappedRanges) {
const { err } = core.opSync(
"op_webgpu_buffer_unmap",
const { err } = ops.op_webgpu_buffer_unmap(
bufferRid,
mappedRid,
...new SafeArrayIterator(write ? [new Uint8Array(buffer)] : []),
@ -2153,7 +2141,7 @@
});
const device = assertDevice(this, { prefix, context: "this" });
const textureRid = assertResource(this, { prefix, context: "this" });
const { rid, err } = core.opSync("op_webgpu_create_texture_view", {
const { rid, err } = ops.op_webgpu_create_texture_view({
textureRid,
...descriptor,
});
@ -2536,11 +2524,11 @@
prefix,
context: "this",
});
const { rid, label, err } = core.opSync(
"op_webgpu_compute_pipeline_get_bind_group_layout",
computePipelineRid,
index,
);
const { rid, label, err } = ops
.op_webgpu_compute_pipeline_get_bind_group_layout(
computePipelineRid,
index,
);
device.pushError(err);
const bindGroupLayout = createGPUBindGroupLayout(
@ -2613,11 +2601,11 @@
prefix,
context: "this",
});
const { rid, label, err } = core.opSync(
"op_webgpu_render_pipeline_get_bind_group_layout",
renderPipelineRid,
index,
);
const { rid, label, err } = ops
.op_webgpu_render_pipeline_get_bind_group_layout(
renderPipelineRid,
index,
);
device.pushError(err);
const bindGroupLayout = createGPUBindGroupLayout(
@ -2807,8 +2795,7 @@
},
);
const { rid } = core.opSync(
"op_webgpu_command_encoder_begin_render_pass",
const { rid } = ops.op_webgpu_command_encoder_begin_render_pass(
commandEncoderRid,
descriptor.label,
colorAttachments,
@ -2842,8 +2829,7 @@
context: "this",
});
const { rid } = core.opSync(
"op_webgpu_command_encoder_begin_compute_pass",
const { rid } = ops.op_webgpu_command_encoder_begin_compute_pass(
commandEncoderRid,
descriptor.label,
);
@ -2919,8 +2905,7 @@
selfContext: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_copy_buffer_to_buffer",
const { err } = ops.op_webgpu_command_encoder_copy_buffer_to_buffer(
commandEncoderRid,
sourceRid,
sourceOffset,
@ -2977,8 +2962,7 @@
selfContext: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_copy_buffer_to_texture",
const { err } = ops.op_webgpu_command_encoder_copy_buffer_to_texture(
commandEncoderRid,
{
...source,
@ -3042,8 +3026,7 @@
resourceContext: "buffer in Argument 2",
selfContext: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_copy_texture_to_buffer",
const { err } = ops.op_webgpu_command_encoder_copy_texture_to_buffer(
commandEncoderRid,
{
texture: sourceTextureRid,
@ -3107,8 +3090,7 @@
resourceContext: "texture in Argument 2",
selfContext: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_copy_texture_to_texture",
const { err } = ops.op_webgpu_command_encoder_copy_texture_to_texture(
commandEncoderRid,
{
texture: sourceTextureRid,
@ -3161,8 +3143,7 @@
prefix,
context: "Argument 1",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_clear_buffer",
const { err } = ops.op_webgpu_command_encoder_clear_buffer(
commandEncoderRid,
bufferRid,
offset,
@ -3188,8 +3169,7 @@
prefix,
context: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_push_debug_group",
const { err } = ops.op_webgpu_command_encoder_push_debug_group(
commandEncoderRid,
groupLabel,
);
@ -3204,8 +3184,7 @@
prefix,
context: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_pop_debug_group",
const { err } = ops.op_webgpu_command_encoder_pop_debug_group(
commandEncoderRid,
);
device.pushError(err);
@ -3228,8 +3207,7 @@
prefix,
context: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_insert_debug_marker",
const { err } = ops.op_webgpu_command_encoder_insert_debug_marker(
commandEncoderRid,
markerLabel,
);
@ -3267,8 +3245,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_write_timestamp",
const { err } = ops.op_webgpu_command_encoder_write_timestamp(
commandEncoderRid,
querySetRid,
queryIndex,
@ -3337,8 +3314,7 @@
resourceContext: "Argument 3",
selfContext: "this",
});
const { err } = core.opSync(
"op_webgpu_command_encoder_resolve_query_set",
const { err } = ops.op_webgpu_command_encoder_resolve_query_set(
commandEncoderRid,
querySetRid,
firstQuery,
@ -3365,8 +3341,7 @@
prefix,
context: "this",
});
const { rid, err } = core.opSync(
"op_webgpu_command_encoder_finish",
const { rid, err } = ops.op_webgpu_command_encoder_finish(
commandEncoderRid,
descriptor.label,
);
@ -3465,7 +3440,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync("op_webgpu_render_pass_set_viewport", {
ops.op_webgpu_render_pass_set_viewport({
renderPassRid,
x,
y,
@ -3512,8 +3487,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_set_scissor_rect",
ops.op_webgpu_render_pass_set_scissor_rect(
renderPassRid,
x,
y,
@ -3543,8 +3517,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_set_blend_constant",
ops.op_webgpu_render_pass_set_blend_constant(
renderPassRid,
normalizeGPUColor(color),
);
@ -3571,8 +3544,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_set_stencil_reference",
ops.op_webgpu_render_pass_set_stencil_reference(
renderPassRid,
reference,
);
@ -3621,8 +3593,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_begin_pipeline_statistics_query",
ops.op_webgpu_render_pass_begin_pipeline_statistics_query(
renderPassRid,
querySetRid,
queryIndex,
@ -3642,8 +3613,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_end_pipeline_statistics_query",
ops.op_webgpu_render_pass_end_pipeline_statistics_query(
renderPassRid,
);
}
@ -3683,8 +3653,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_write_timestamp",
ops.op_webgpu_render_pass_write_timestamp(
renderPassRid,
querySetRid,
queryIndex,
@ -3722,8 +3691,7 @@
});
return rid;
});
core.opSync(
"op_webgpu_render_pass_execute_bundles",
ops.op_webgpu_render_pass_execute_bundles(
renderPassRid,
bundleRids,
);
@ -3741,8 +3709,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
const { err } = core.opSync(
"op_webgpu_render_pass_end",
const { err } = ops.op_webgpu_render_pass_end(
commandEncoderRid,
renderPassRid,
);
@ -3789,8 +3756,7 @@
dynamicOffsetsDataStart = 0;
dynamicOffsetsDataLength = dynamicOffsetsData.length;
}
core.opSync(
"op_webgpu_render_pass_set_bind_group",
ops.op_webgpu_render_pass_set_bind_group(
renderPassRid,
index,
bindGroupRid,
@ -3821,8 +3787,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_push_debug_group",
ops.op_webgpu_render_pass_push_debug_group(
renderPassRid,
groupLabel,
);
@ -3841,7 +3806,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync("op_webgpu_render_pass_pop_debug_group", renderPassRid);
ops.op_webgpu_render_pass_pop_debug_group(renderPassRid);
}
/**
@ -3865,8 +3830,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_insert_debug_marker",
ops.op_webgpu_render_pass_insert_debug_marker(
renderPassRid,
markerLabel,
);
@ -3902,8 +3866,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_set_pipeline",
ops.op_webgpu_render_pass_set_pipeline(
renderPassRid,
pipelineRid,
);
@ -3956,8 +3919,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_set_index_buffer",
ops.op_webgpu_render_pass_set_index_buffer(
renderPassRid,
bufferRid,
indexFormat,
@ -4013,8 +3975,7 @@
resourceContext: "Argument 2",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_set_vertex_buffer",
ops.op_webgpu_render_pass_set_vertex_buffer(
renderPassRid,
slot,
bufferRid,
@ -4058,8 +4019,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_draw",
ops.op_webgpu_render_pass_draw(
renderPassRid,
vertexCount,
instanceCount,
@ -4115,8 +4075,7 @@
context: "encoder referenced by this",
});
const renderPassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_render_pass_draw_indexed",
ops.op_webgpu_render_pass_draw_indexed(
renderPassRid,
indexCount,
instanceCount,
@ -4161,8 +4120,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_draw_indirect",
ops.op_webgpu_render_pass_draw_indirect(
renderPassRid,
indirectBufferRid,
indirectOffset,
@ -4204,8 +4162,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_pass_draw_indexed_indirect",
ops.op_webgpu_render_pass_draw_indexed_indirect(
renderPassRid,
indirectBufferRid,
indirectOffset,
@ -4288,8 +4245,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_compute_pass_set_pipeline",
ops.op_webgpu_compute_pass_set_pipeline(
computePassRid,
pipelineRid,
);
@ -4330,8 +4286,7 @@
context: "encoder referenced by this",
});
const computePassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_compute_pass_dispatch_workgroups",
ops.op_webgpu_compute_pass_dispatch_workgroups(
computePassRid,
workgroupCountX,
workgroupCountY,
@ -4374,8 +4329,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_compute_pass_dispatch_workgroups_indirect",
ops.op_webgpu_compute_pass_dispatch_workgroups_indirect(
computePassRid,
indirectBufferRid,
indirectOffset,
@ -4417,8 +4371,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_compute_pass_begin_pipeline_statistics_query",
ops.op_webgpu_compute_pass_begin_pipeline_statistics_query(
computePassRid,
querySetRid,
queryIndex,
@ -4438,8 +4391,7 @@
context: "encoder referenced by this",
});
const computePassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_compute_pass_end_pipeline_statistics_query",
ops.op_webgpu_compute_pass_end_pipeline_statistics_query(
computePassRid,
);
}
@ -4479,8 +4431,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_compute_pass_write_timestamp",
ops.op_webgpu_compute_pass_write_timestamp(
computePassRid,
querySetRid,
queryIndex,
@ -4499,8 +4450,7 @@
context: "encoder referenced by this",
});
const computePassRid = assertResource(this, { prefix, context: "this" });
const { err } = core.opSync(
"op_webgpu_compute_pass_end",
const { err } = ops.op_webgpu_compute_pass_end(
commandEncoderRid,
computePassRid,
);
@ -4547,8 +4497,7 @@
dynamicOffsetsDataStart = 0;
dynamicOffsetsDataLength = dynamicOffsetsData.length;
}
core.opSync(
"op_webgpu_compute_pass_set_bind_group",
ops.op_webgpu_compute_pass_set_bind_group(
computePassRid,
index,
bindGroupRid,
@ -4579,8 +4528,7 @@
context: "encoder referenced by this",
});
const computePassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_compute_pass_push_debug_group",
ops.op_webgpu_compute_pass_push_debug_group(
computePassRid,
groupLabel,
);
@ -4599,7 +4547,7 @@
context: "encoder referenced by this",
});
const computePassRid = assertResource(this, { prefix, context: "this" });
core.opSync("op_webgpu_compute_pass_pop_debug_group", computePassRid);
ops.op_webgpu_compute_pass_pop_debug_group(computePassRid);
}
/**
@ -4623,8 +4571,7 @@
context: "encoder referenced by this",
});
const computePassRid = assertResource(this, { prefix, context: "this" });
core.opSync(
"op_webgpu_compute_pass_insert_debug_marker",
ops.op_webgpu_compute_pass_insert_debug_marker(
computePassRid,
markerLabel,
);
@ -4734,8 +4681,7 @@
prefix,
context: "this",
});
const { rid, err } = core.opSync(
"op_webgpu_render_bundle_encoder_finish",
const { rid, err } = ops.op_webgpu_render_bundle_encoder_finish(
renderBundleEncoderRid,
descriptor.label,
);
@ -4786,8 +4732,7 @@
dynamicOffsetsDataStart = 0;
dynamicOffsetsDataLength = dynamicOffsetsData.length;
}
core.opSync(
"op_webgpu_render_bundle_encoder_set_bind_group",
ops.op_webgpu_render_bundle_encoder_set_bind_group(
renderBundleEncoderRid,
index,
bindGroupRid,
@ -4814,8 +4759,7 @@
prefix,
context: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_push_debug_group",
ops.op_webgpu_render_bundle_encoder_push_debug_group(
renderBundleEncoderRid,
groupLabel,
);
@ -4830,8 +4774,7 @@
prefix,
context: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_pop_debug_group",
ops.op_webgpu_render_bundle_encoder_pop_debug_group(
renderBundleEncoderRid,
);
}
@ -4853,8 +4796,7 @@
prefix,
context: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_insert_debug_marker",
ops.op_webgpu_render_bundle_encoder_insert_debug_marker(
renderBundleEncoderRid,
markerLabel,
);
@ -4886,8 +4828,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_set_pipeline",
ops.op_webgpu_render_bundle_encoder_set_pipeline(
renderBundleEncoderRid,
pipelineRid,
);
@ -4934,8 +4875,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_set_index_buffer",
ops.op_webgpu_render_bundle_encoder_set_index_buffer(
renderBundleEncoderRid,
bufferRid,
indexFormat,
@ -4985,8 +4925,7 @@
resourceContext: "Argument 2",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_set_vertex_buffer",
ops.op_webgpu_render_bundle_encoder_set_vertex_buffer(
renderBundleEncoderRid,
slot,
bufferRid,
@ -5026,8 +4965,7 @@
prefix,
context: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_draw",
ops.op_webgpu_render_bundle_encoder_draw(
renderBundleEncoderRid,
vertexCount,
instanceCount,
@ -5079,8 +5017,7 @@
prefix,
context: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_draw_indexed",
ops.op_webgpu_render_bundle_encoder_draw_indexed(
renderBundleEncoderRid,
indexCount,
instanceCount,
@ -5121,8 +5058,7 @@
resourceContext: "Argument 1",
selfContext: "this",
});
core.opSync(
"op_webgpu_render_bundle_encoder_draw_indirect",
ops.op_webgpu_render_bundle_encoder_draw_indirect(
renderBundleEncoderRid,
indirectBufferRid,
indirectOffset,

View file

@ -5,6 +5,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { URL } = window.__bootstrap.url;
const webidl = window.__bootstrap.webidl;
const { HTTP_TOKEN_CODE_POINT_RE } = window.__bootstrap.infra;
@ -189,8 +190,7 @@
this[_url] = wsURL.href;
core.opSync(
"op_ws_check_permission_and_cancel_handle",
ops.op_ws_check_permission_and_cancel_handle(
this[_url],
false,
);

View file

@ -5,6 +5,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const { writableStreamClose, Deferred } = window.__bootstrap.streams;
const { DOMException } = window.__bootstrap.domException;
@ -128,8 +129,7 @@
fillHeaders(headers, options.headers);
}
const cancelRid = core.opSync(
"op_ws_check_permission_and_cancel_handle",
const cancelRid = ops.op_ws_check_permission_and_cancel_handle(
this[_url],
true,
);

View file

@ -4,6 +4,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const webidl = window.__bootstrap.webidl;
const {
SafeArrayIterator,
@ -28,7 +29,7 @@
get length() {
webidl.assertBranded(this, StoragePrototype);
return core.opSync("op_webstorage_length", this[_persistent]);
return ops.op_webstorage_length(this[_persistent]);
}
key(index) {
@ -40,7 +41,7 @@
context: "Argument 1",
});
return core.opSync("op_webstorage_key", index, this[_persistent]);
return ops.op_webstorage_key(index, this[_persistent]);
}
setItem(key, value) {
@ -56,7 +57,7 @@
context: "Argument 2",
});
core.opSync("op_webstorage_set", key, value, this[_persistent]);
ops.op_webstorage_set(key, value, this[_persistent]);
}
getItem(key) {
@ -68,7 +69,7 @@
context: "Argument 1",
});
return core.opSync("op_webstorage_get", key, this[_persistent]);
return ops.op_webstorage_get(key, this[_persistent]);
}
removeItem(key) {
@ -80,12 +81,12 @@
context: "Argument 1",
});
core.opSync("op_webstorage_remove", key, this[_persistent]);
ops.op_webstorage_remove(key, this[_persistent]);
}
clear() {
webidl.assertBranded(this, StoragePrototype);
core.opSync("op_webstorage_clear", this[_persistent]);
ops.op_webstorage_clear(this[_persistent]);
}
}
@ -136,7 +137,7 @@
(typeof target.getItem(p)) === "string";
},
ownKeys() {
return core.opSync("op_webstorage_iterate_keys", persistent);
return ops.op_webstorage_iterate_keys(persistent);
},
getOwnPropertyDescriptor(target, key) {
if (arguments.length === 1) {

View file

@ -5,7 +5,7 @@
const {
Event,
EventTarget,
Deno: { core },
Deno: { core: { ops } },
__bootstrap: { webUtil: { illegalConstructorKey } },
} = window;
const { pathFromURL } = window.__bootstrap.util;
@ -48,7 +48,7 @@
* @returns {Deno.PermissionState}
*/
function opQuery(desc) {
return core.opSync("op_query_permission", desc);
return ops.op_query_permission(desc);
}
/**
@ -56,7 +56,7 @@
* @returns {Deno.PermissionState}
*/
function opRevoke(desc) {
return core.opSync("op_revoke_permission", desc);
return ops.op_revoke_permission(desc);
}
/**
@ -64,7 +64,7 @@
* @returns {Deno.PermissionState}
*/
function opRequest(desc) {
return core.opSync("op_request_permission", desc);
return ops.op_request_permission(desc);
}
class PermissionStatus extends EventTarget {

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const {
Error,
ObjectPrototypeIsPrototypeOf,
@ -31,7 +32,7 @@
name,
workerType,
) {
return core.opSync("op_create_worker", {
return ops.op_create_worker({
hasSourceCode,
name,
permissions: serializePermissions(permissions),
@ -42,11 +43,11 @@
}
function hostTerminateWorker(id) {
core.opSync("op_host_terminate_worker", id);
ops.op_host_terminate_worker(id);
}
function hostPostMessage(id, data) {
core.opSync("op_host_post_message", id, data);
ops.op_host_post_message(id, data);
}
function hostRecvCtrl(id) {

View file

@ -7,6 +7,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const {
Uint8Array,
ArrayPrototypePush,
@ -91,7 +92,7 @@
return 0;
}
const nread = core.opSync("op_read_sync", rid, buffer);
const nread = ops.op_read_sync(rid, buffer);
return nread === 0 ? null : nread;
}
@ -107,7 +108,7 @@
}
function writeSync(rid, data) {
return core.opSync("op_write_sync", rid, data);
return ops.op_write_sync(rid, data);
}
function write(rid, data) {

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const {
Date,
DatePrototype,
@ -15,7 +16,7 @@
const build = window.__bootstrap.build.build;
function chmodSync(path, mode) {
core.opSync("op_chmod_sync", { path: pathFromURL(path), mode });
ops.op_chmod_sync({ path: pathFromURL(path), mode });
}
async function chmod(path, mode) {
@ -27,7 +28,7 @@
uid,
gid,
) {
core.opSync("op_chown_sync", { path: pathFromURL(path), uid, gid });
ops.op_chown_sync({ path: pathFromURL(path), uid, gid });
}
async function chown(
@ -45,7 +46,7 @@
fromPath,
toPath,
) {
core.opSync("op_copy_file_sync", {
ops.op_copy_file_sync({
from: pathFromURL(fromPath),
to: pathFromURL(toPath),
});
@ -62,15 +63,15 @@
}
function cwd() {
return core.opSync("op_cwd");
return ops.op_cwd();
}
function chdir(directory) {
core.opSync("op_chdir", pathFromURL(directory));
ops.op_chdir(pathFromURL(directory));
}
function makeTempDirSync(options = {}) {
return core.opSync("op_make_temp_dir_sync", options);
return ops.op_make_temp_dir_sync(options);
}
function makeTempDir(options = {}) {
@ -78,7 +79,7 @@
}
function makeTempFileSync(options = {}) {
return core.opSync("op_make_temp_file_sync", options);
return ops.op_make_temp_file_sync(options);
}
function makeTempFile(options = {}) {
@ -99,7 +100,7 @@
}
function mkdirSync(path, options) {
core.opSync("op_mkdir_sync", mkdirArgs(path, options));
ops.op_mkdir_sync(mkdirArgs(path, options));
}
async function mkdir(
@ -110,7 +111,7 @@
}
function readDirSync(path) {
return core.opSync("op_read_dir_sync", pathFromURL(path))[
return ops.op_read_dir_sync(pathFromURL(path))[
SymbolIterator
]();
}
@ -128,7 +129,7 @@
}
function readLinkSync(path) {
return core.opSync("op_read_link_sync", pathFromURL(path));
return ops.op_read_link_sync(pathFromURL(path));
}
function readLink(path) {
@ -136,7 +137,7 @@
}
function realPathSync(path) {
return core.opSync("op_realpath_sync", pathFromURL(path));
return ops.op_realpath_sync(pathFromURL(path));
}
function realPath(path) {
@ -147,7 +148,7 @@
path,
options = {},
) {
core.opSync("op_remove_sync", {
ops.op_remove_sync({
path: pathFromURL(path),
recursive: !!options.recursive,
});
@ -164,7 +165,7 @@
}
function renameSync(oldpath, newpath) {
core.opSync("op_rename_sync", {
ops.op_rename_sync({
oldpath: pathFromURL(oldpath),
newpath: pathFromURL(newpath),
});
@ -203,7 +204,7 @@
}
function fstatSync(rid) {
return parseFileInfo(core.opSync("op_fstat_sync", rid));
return parseFileInfo(ops.op_fstat_sync(rid));
}
async function fstat(rid) {
@ -219,7 +220,7 @@
}
function lstatSync(path) {
const res = core.opSync("op_stat_sync", {
const res = ops.op_stat_sync({
path: pathFromURL(path),
lstat: true,
});
@ -235,7 +236,7 @@
}
function statSync(path) {
const res = core.opSync("op_stat_sync", {
const res = ops.op_stat_sync({
path: pathFromURL(path),
lstat: false,
});
@ -251,7 +252,7 @@
}
function ftruncateSync(rid, len) {
core.opSync("op_ftruncate_sync", { rid, len: coerceLen(len) });
ops.op_ftruncate_sync({ rid, len: coerceLen(len) });
}
async function ftruncate(rid, len) {
@ -259,7 +260,7 @@
}
function truncateSync(path, len) {
core.opSync("op_truncate_sync", { path, len: coerceLen(len) });
ops.op_truncate_sync({ path, len: coerceLen(len) });
}
async function truncate(path, len) {
@ -267,11 +268,11 @@
}
function umask(mask) {
return core.opSync("op_umask", mask);
return ops.op_umask(mask);
}
function linkSync(oldpath, newpath) {
core.opSync("op_link_sync", { oldpath, newpath });
ops.op_link_sync({ oldpath, newpath });
}
async function link(oldpath, newpath) {
@ -304,7 +305,7 @@
atime,
mtime,
) {
core.opSync("op_futime_sync", {
ops.op_futime_sync({
rid,
atime: toUnixTimeFromEpoch(atime),
mtime: toUnixTimeFromEpoch(mtime),
@ -328,7 +329,7 @@
atime,
mtime,
) {
core.opSync("op_utime_sync", {
ops.op_utime_sync({
path: pathFromURL(path),
atime: toUnixTimeFromEpoch(atime),
mtime: toUnixTimeFromEpoch(mtime),
@ -352,7 +353,7 @@
newpath,
options,
) {
core.opSync("op_symlink_sync", {
ops.op_symlink_sync({
oldpath: pathFromURL(oldpath),
newpath: pathFromURL(newpath),
options,
@ -372,7 +373,7 @@
}
function fdatasyncSync(rid) {
core.opSync("op_fdatasync_sync", rid);
ops.op_fdatasync_sync(rid);
}
async function fdatasync(rid) {
@ -380,7 +381,7 @@
}
function fsyncSync(rid) {
core.opSync("op_fsync_sync", rid);
ops.op_fsync_sync(rid);
}
async function fsync(rid) {
@ -388,7 +389,7 @@
}
function flockSync(rid, exclusive) {
core.opSync("op_flock_sync", rid, exclusive === true);
ops.op_flock_sync(rid, exclusive === true);
}
async function flock(rid, exclusive) {
@ -396,7 +397,7 @@
}
function funlockSync(rid) {
core.opSync("op_funlock_sync", rid);
ops.op_funlock_sync(rid);
}
async function funlock(rid) {

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const {
Error,
SymbolFor,
@ -11,31 +12,31 @@
const windowDispatchEvent = window.dispatchEvent.bind(window);
function loadavg() {
return core.opSync("op_loadavg");
return ops.op_loadavg();
}
function hostname() {
return core.opSync("op_hostname");
return ops.op_hostname();
}
function osRelease() {
return core.opSync("op_os_release");
return ops.op_os_release();
}
function systemMemoryInfo() {
return core.opSync("op_system_memory_info");
return ops.op_system_memory_info();
}
function networkInterfaces() {
return core.opSync("op_network_interfaces");
return ops.op_network_interfaces();
}
function getGid() {
return core.opSync("op_getgid");
return ops.op_getgid();
}
function getUid() {
return core.opSync("op_getuid");
return ops.op_getuid();
}
// This is an internal only method used by the test harness to override the
@ -48,7 +49,7 @@
function exit(code) {
// Set exit code first so unload event listeners can override it.
if (typeof code === "number") {
core.opSync("op_set_exit_code", code);
ops.op_set_exit_code(code);
} else {
code = 0;
}
@ -65,33 +66,33 @@
return;
}
core.opSync("op_exit");
ops.op_exit();
throw new Error("Code not reachable");
}
function setEnv(key, value) {
core.opSync("op_set_env", key, value);
ops.op_set_env(key, value);
}
function getEnv(key) {
return core.opSync("op_get_env", key) ?? undefined;
return ops.op_get_env(key) ?? undefined;
}
function deleteEnv(key) {
core.opSync("op_delete_env", key);
ops.op_delete_env(key);
}
const env = {
get: getEnv,
toObject() {
return core.opSync("op_env");
return ops.op_env();
},
set: setEnv,
delete: deleteEnv,
};
function execPath() {
return core.opSync("op_exec_path");
return ops.op_exec_path();
}
window.__bootstrap.os = {

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { read, readSync, write, writeSync } = window.__bootstrap.io;
const { ftruncate, ftruncateSync, fstat, fstatSync } = window.__bootstrap.fs;
const { pathFromURL } = window.__bootstrap.util;
@ -19,7 +20,7 @@
offset,
whence,
) {
return core.opSync("op_seek_sync", { rid, offset, whence });
return ops.op_seek_sync({ rid, offset, whence });
}
function seek(
@ -36,8 +37,7 @@
) {
checkOpenOptions(options);
const mode = options?.mode;
const rid = core.opSync(
"op_open_sync",
const rid = ops.op_open_sync(
{ path: pathFromURL(path), options, mode },
);

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { BadResourcePrototype, InterruptedPrototype } = core;
const {
ArrayIsArray,
@ -15,7 +16,7 @@
constructor(paths, options) {
const { recursive } = options;
this.#rid = core.opSync("op_fs_events_open", { recursive, paths });
this.#rid = ops.op_fs_events_open({ recursive, paths });
}
get rid() {

View file

@ -3,10 +3,11 @@
((window) => {
const core = window.__bootstrap.core;
const ops = core.ops;
const { HttpConn } = window.__bootstrap.http;
function serveHttp(conn) {
const rid = core.opSync("op_http_start", conn.rid);
const rid = ops.op_http_start(conn.rid);
return new HttpConn(rid, conn.remoteAddr, conn.localAddr);
}

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { FsFile } = window.__bootstrap.files;
const { readAll } = window.__bootstrap.io;
const { pathFromURL } = window.__bootstrap.util;
@ -16,7 +17,7 @@
} = window.__bootstrap.primordials;
function opKill(pid, signo) {
core.opSync("op_kill", pid, signo);
ops.op_kill(pid, signo);
}
function opRunStatus(rid) {
@ -25,7 +26,7 @@
function opRun(request) {
assert(request.cmd.length > 0);
return core.opSync("op_run", request);
return ops.op_run(request);
}
async function runStatus(rid) {

View file

@ -3,11 +3,12 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { pathFromURL } = window.__bootstrap.util;
const { abortSignal } = window.__bootstrap;
function readFileSync(path) {
return core.opSync("op_readfile_sync", pathFromURL(path));
return ops.op_readfile_sync(pathFromURL(path));
}
async function readFile(path, options) {
@ -15,7 +16,7 @@
let abortHandler;
if (options?.signal) {
options.signal.throwIfAborted();
cancelRid = core.opSync("op_cancel_handle");
cancelRid = ops.op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}
@ -38,7 +39,7 @@
}
function readTextFileSync(path) {
return core.opSync("op_readfile_text_sync", pathFromURL(path));
return ops.op_readfile_text_sync(pathFromURL(path));
}
async function readTextFile(path, options) {
@ -46,7 +47,7 @@
let abortHandler;
if (options?.signal) {
options.signal.throwIfAborted();
cancelRid = core.opSync("op_cancel_handle");
cancelRid = ops.op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const {
Set,
SymbolFor,
@ -10,7 +11,7 @@
} = window.__bootstrap.primordials;
function bindSignal(signo) {
return core.opSync("op_signal_bind", signo);
return ops.op_signal_bind(signo);
}
function pollSignal(rid) {
@ -20,7 +21,7 @@
}
function unbindSignal(rid) {
core.opSync("op_signal_unbind", rid);
ops.op_signal_unbind(rid);
}
// Stores signal listeners and resource data. This has type of

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { pathFromURL } = window.__bootstrap.util;
const { illegalConstructorKey } = window.__bootstrap.webUtil;
const { add, remove } = window.__bootstrap.abortSignal;
@ -32,7 +33,7 @@
stderr = "piped",
signal = undefined,
} = {}) {
const child = core.opSync("op_spawn_child", {
const child = ops.op_spawn_child({
cmd: pathFromURL(command),
args: ArrayPrototypeMap(args, String),
cwd: pathFromURL(cwd),
@ -203,7 +204,7 @@
if (this.#rid === null) {
throw new TypeError("Child process has already terminated.");
}
core.opSync("op_kill", this.#pid, signo);
ops.op_kill(this.#pid, signo);
}
ref() {
@ -246,7 +247,7 @@
"Piped stdin is not supported for this function, use 'Deno.spawnChild()' instead",
);
}
const result = core.opSync("op_spawn_sync", {
const result = ops.op_spawn_sync({
cmd: pathFromURL(command),
args: ArrayPrototypeMap(args, String),
cwd: pathFromURL(cwd),

View file

@ -3,6 +3,7 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
const { setExitHandler } = window.__bootstrap.os;
const { Console } = window.__bootstrap.console;
const { serializePermissions } = window.__bootstrap.permissions;
@ -510,14 +511,13 @@
}
function pledgePermissions(permissions) {
return core.opSync(
"op_pledge_test_permissions",
return ops.op_pledge_test_permissions(
serializePermissions(permissions),
);
}
function restorePermissions(token) {
core.opSync("op_restore_test_permissions", token);
ops.op_restore_test_permissions(token);
}
function withPermissions(fn, permissions) {
@ -709,7 +709,7 @@
columnNumber: jsError.frames[1].columnNumber,
};
const { id, filteredOut } = core.opSync("op_register_test", testDesc);
const { id, filteredOut } = ops.op_register_test(testDesc);
testDesc.id = id;
testDesc.filteredOut = filteredOut;
@ -731,7 +731,7 @@
return;
}
core.opSync("op_bench_check_unstable");
ops.op_bench_check_unstable();
let benchDesc;
const defaults = {
ignore: false,
@ -815,7 +815,7 @@
const AsyncFunction = (async () => {}).constructor;
benchDesc.async = AsyncFunction === benchDesc.fn.constructor;
const { id, filteredOut } = core.opSync("op_register_bench", benchDesc);
const { id, filteredOut } = ops.op_register_bench(benchDesc);
benchDesc.id = id;
benchDesc.filteredOut = filteredOut;
@ -1016,20 +1016,20 @@
function getTestOrigin() {
if (origin == null) {
origin = core.opSync("op_get_test_origin");
origin = ops.op_get_test_origin();
}
return origin;
}
function getBenchOrigin() {
if (origin == null) {
origin = core.opSync("op_get_bench_origin");
origin = ops.op_get_bench_origin();
}
return origin;
}
function benchNow() {
return core.opSync("op_bench_now");
return ops.op_bench_now();
}
// This function is called by Rust side if we're in `deno test` or
@ -1051,7 +1051,7 @@
(desc) => !desc.filteredOut,
);
core.opSync("op_dispatch_test_event", {
ops.op_dispatch_test_event({
plan: {
origin,
total: filtered.length,
@ -1079,11 +1079,11 @@
}
for (const desc of filtered) {
core.opSync("op_dispatch_test_event", { wait: desc.id });
ops.op_dispatch_test_event({ wait: desc.id });
const earlier = DateNow();
const result = await runTest(desc);
const elapsed = DateNow() - earlier;
core.opSync("op_dispatch_test_event", {
ops.op_dispatch_test_event({
result: [desc.id, result, elapsed],
});
}
@ -1096,7 +1096,7 @@
const originalConsole = globalThis.console;
globalThis.console = new Console((s) => {
core.opSync("op_dispatch_bench_event", { output: s });
ops.op_dispatch_bench_event({ output: s });
});
const only = ArrayPrototypeFilter(benchDescs, (bench) => bench.only);
@ -1120,7 +1120,7 @@
(a, b) => groups.indexOf(a.group) - groups.indexOf(b.group),
);
core.opSync("op_dispatch_bench_event", {
ops.op_dispatch_bench_event({
plan: {
origin,
total: filtered.length,
@ -1131,8 +1131,8 @@
for (const desc of filtered) {
desc.baseline = !!desc.baseline;
core.opSync("op_dispatch_bench_event", { wait: desc.id });
core.opSync("op_dispatch_bench_event", {
ops.op_dispatch_bench_event({ wait: desc.id });
ops.op_dispatch_bench_event({
result: [desc.id, await runBench(desc)],
});
}
@ -1173,7 +1173,7 @@
if (state.reportedWait) {
return;
}
core.opSync("op_dispatch_test_event", { stepWait: desc.id });
ops.op_dispatch_test_event({ stepWait: desc.id });
state.reportedWait = true;
}
@ -1194,7 +1194,7 @@
} else {
result = state.status;
}
core.opSync("op_dispatch_test_event", {
ops.op_dispatch_test_event({
stepResult: [desc.id, result, state.elapsed],
});
state.reportedResult = true;
@ -1293,7 +1293,7 @@
stepDesc.parent = desc;
stepDesc.rootId = rootId;
stepDesc.rootName = rootName;
const { id } = core.opSync("op_register_test_step", stepDesc);
const { id } = ops.op_register_test_step(stepDesc);
stepDesc.id = id;
const state = {
context: createTestContext(stepDesc),

View file

@ -3,13 +3,14 @@
((window) => {
const core = window.Deno.core;
const ops = core.ops;
function consoleSize(rid) {
return core.opSync("op_console_size", rid);
return ops.op_console_size(rid);
}
function isatty(rid) {
return core.opSync("op_isatty", rid);
return ops.op_isatty(rid);
}
const DEFAULT_SET_RAW_OPTIONS = {
@ -18,7 +19,7 @@
function setRaw(rid, mode, options = {}) {
const rOptions = { ...DEFAULT_SET_RAW_OPTIONS, ...options };
core.opSync("op_set_raw", { rid, mode, options: rOptions });
ops.op_set_raw({ rid, mode, options: rOptions });
}
window.__bootstrap.tty = {

View file

@ -2,6 +2,7 @@
"use strict";
((window) => {
const core = window.__bootstrap.core;
const ops = core.ops;
const { abortSignal } = window.__bootstrap;
const { pathFromURL } = window.__bootstrap.util;
@ -11,7 +12,7 @@
options = {},
) {
options.signal?.throwIfAborted();
core.opSync("op_write_file_sync", {
ops.op_write_file_sync({
path: pathFromURL(path),
data,
mode: options.mode,
@ -29,7 +30,7 @@
let abortHandler;
if (options.signal) {
options.signal.throwIfAborted();
cancelRid = core.opSync("op_cancel_handle");
cancelRid = ops.op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}

View file

@ -10,6 +10,7 @@ delete Intl.v8BreakIterator;
((window) => {
const core = Deno.core;
const ops = core.ops;
const {
ArrayPrototypeIndexOf,
ArrayPrototypePush,
@ -103,7 +104,7 @@ delete Intl.v8BreakIterator;
}
isClosing = true;
core.opSync("op_worker_close");
ops.op_worker_close();
}
function postMessage(message, transferOrOptions = {}) {
@ -133,7 +134,7 @@ delete Intl.v8BreakIterator;
}
const { transfer } = options;
const data = serializeJsMessageData(message, transfer);
core.opSync("op_worker_post_message", data);
ops.op_worker_post_message(data);
}
let isClosing = false;
@ -184,7 +185,7 @@ delete Intl.v8BreakIterator;
let loadedMainWorkerScript = false;
function importScripts(...urls) {
if (core.opSync("op_worker_get_type") === "module") {
if (ops.op_worker_get_type() === "module") {
throw new TypeError("Can't import scripts in a module worker.");
}
@ -204,8 +205,7 @@ delete Intl.v8BreakIterator;
// imported scripts, so we use `loadedMainWorkerScript` to distinguish them.
// TODO(andreubotella) Refactor worker creation so the main script isn't
// loaded with `importScripts()`.
const scripts = core.opSync(
"op_worker_sync_fetch",
const scripts = ops.op_worker_sync_fetch(
parsedUrls,
!loadedMainWorkerScript,
);
@ -220,7 +220,7 @@ delete Intl.v8BreakIterator;
}
function opMainModule() {
return core.opSync("op_main_module");
return ops.op_main_module();
}
function formatException(error) {
@ -243,7 +243,7 @@ delete Intl.v8BreakIterator;
core.setMacrotaskCallback(timers.handleTimerMacrotask);
core.setMacrotaskCallback(promiseRejectMacrotaskCallback);
core.setWasmStreamingCallback(fetch.handleWasmStreaming);
core.opSync("op_set_format_exception_callback", formatException);
ops.op_set_format_exception_callback(formatException);
version.setVersions(
runtimeOptions.denoVersion,
runtimeOptions.v8Version,
@ -569,13 +569,13 @@ delete Intl.v8BreakIterator;
function promiseRejectCallback(type, promise, reason) {
switch (type) {
case 0: {
core.opSync("op_store_pending_promise_exception", promise, reason);
ops.op_store_pending_promise_exception(promise, reason);
ArrayPrototypePush(pendingRejections, promise);
WeakMapPrototypeSet(pendingRejectionsReasons, promise, reason);
break;
}
case 1: {
core.opSync("op_remove_pending_promise_exception", promise);
ops.op_remove_pending_promise_exception(promise);
const index = ArrayPrototypeIndexOf(pendingRejections, promise);
if (index > -1) {
ArrayPrototypeSplice(pendingRejections, index, 1);
@ -594,8 +594,7 @@ delete Intl.v8BreakIterator;
function promiseRejectMacrotaskCallback() {
while (pendingRejections.length > 0) {
const promise = ArrayPrototypeShift(pendingRejections);
const hasPendingException = core.opSync(
"op_has_pending_promise_exception",
const hasPendingException = ops.op_has_pending_promise_exception(
promise,
);
const reason = WeakMapPrototypeGet(pendingRejectionsReasons, promise);
@ -613,7 +612,7 @@ delete Intl.v8BreakIterator;
const errorEventCb = (event) => {
if (event.error === reason) {
core.opSync("op_remove_pending_promise_exception", promise);
ops.op_remove_pending_promise_exception(promise);
}
};
// Add a callback for "error" event - it will be dispatched
@ -626,7 +625,7 @@ delete Intl.v8BreakIterator;
// If event was not prevented (or "unhandledrejection" listeners didn't
// throw) we will let Rust side handle it.
if (event.defaultPrevented) {
core.opSync("op_remove_pending_promise_exception", promise);
ops.op_remove_pending_promise_exception(promise);
}
}
return true;

View file

@ -337,6 +337,8 @@ Deno.bench("nop_f64()", () => {
const { nop_buffer } = dylib.symbols;
const buffer = new Uint8Array(8).fill(5);
// Make sure the buffer does not get collected
globalThis.buffer = buffer;
Deno.bench("nop_buffer()", () => {
nop_buffer(buffer);
});
@ -539,6 +541,8 @@ Deno.bench("return_buffer_nonblocking()", async () => {
const { nop_many_parameters } = dylib.symbols;
const buffer2 = new Uint8Array(8).fill(25);
// Make sure the buffer does not get collected
globalThis.buffer2 = buffer2;
Deno.bench("nop_many_parameters()", () => {
nop_many_parameters(
135,

View file

@ -18,10 +18,6 @@ const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
const resourcesPre = Deno.resources();
function ptr(v) {
return Deno.UnsafePointer.of(v);
}
// dlopen shouldn't panic
assertThrows(() => {
Deno.dlopen("cli/src/main.rs", {});
@ -420,7 +416,7 @@ const throwCallback = new Deno.UnsafeCallback({
assertThrows(
() => {
dylib.symbols.call_fn_ptr(ptr(throwCallback));
dylib.symbols.call_fn_ptr(throwCallback.pointer);
},
TypeError,
"hi",
@ -428,13 +424,13 @@ assertThrows(
const { call_stored_function } = dylib.symbols;
dylib.symbols.call_fn_ptr(ptr(logCallback));
dylib.symbols.call_fn_ptr_many_parameters(ptr(logManyParametersCallback));
dylib.symbols.call_fn_ptr_return_u8(ptr(returnU8Callback));
dylib.symbols.call_fn_ptr_return_buffer(ptr(returnBufferCallback));
dylib.symbols.store_function(ptr(logCallback));
dylib.symbols.call_fn_ptr(logCallback.pointer);
dylib.symbols.call_fn_ptr_many_parameters(logManyParametersCallback.pointer);
dylib.symbols.call_fn_ptr_return_u8(returnU8Callback.pointer);
dylib.symbols.call_fn_ptr_return_buffer(returnBufferCallback.pointer);
dylib.symbols.store_function(logCallback.pointer);
call_stored_function();
dylib.symbols.store_function_2(ptr(add10Callback));
dylib.symbols.store_function_2(add10Callback.pointer);
dylib.symbols.call_stored_function_2(20);
const nestedCallback = new Deno.UnsafeCallback(
@ -443,7 +439,7 @@ const nestedCallback = new Deno.UnsafeCallback(
dylib.symbols.call_stored_function_2(10);
},
);
dylib.symbols.store_function(ptr(nestedCallback));
dylib.symbols.store_function(nestedCallback.pointer);
dylib.symbols.store_function(null);
dylib.symbols.store_function_2(null);
@ -457,14 +453,14 @@ const addToFooCallback = new Deno.UnsafeCallback({
// Test thread safe callbacks
console.log("Thread safe call counter:", counter);
addToFooCallback.ref();
await dylib.symbols.call_fn_ptr_thread_safe(ptr(addToFooCallback));
await dylib.symbols.call_fn_ptr_thread_safe(addToFooCallback.pointer);
addToFooCallback.unref();
logCallback.ref();
await dylib.symbols.call_fn_ptr_thread_safe(ptr(logCallback));
await dylib.symbols.call_fn_ptr_thread_safe(logCallback.pointer);
logCallback.unref();
console.log("Thread safe call counter:", counter);
returnU8Callback.ref();
await dylib.symbols.call_fn_ptr_return_u8_thread_safe(ptr(returnU8Callback));
await dylib.symbols.call_fn_ptr_return_u8_thread_safe(returnU8Callback.pointer);
// Test statics
console.log("Static u32:", dylib.symbols.static_u32);