diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/01_core.js | 80 | ||||
-rw-r--r-- | core/02_error.js | 5 | ||||
-rw-r--r-- | core/encode_decode_test.js | 14 | ||||
-rw-r--r-- | core/error_builder_test.js | 3 | ||||
-rw-r--r-- | core/examples/hello_world.rs | 4 | ||||
-rw-r--r-- | core/examples/http_bench_json_ops.js | 2 | ||||
-rw-r--r-- | core/examples/schedule_task.rs | 10 | ||||
-rw-r--r-- | core/lib.deno_core.d.ts | 10 | ||||
-rw-r--r-- | core/modules.rs | 2 | ||||
-rw-r--r-- | core/runtime.rs | 78 | ||||
-rw-r--r-- | core/serialize_deserialize_test.js | 15 |
11 files changed, 112 insertions, 111 deletions
diff --git a/core/01_core.js b/core/01_core.js index 1dfb88c99..aaff59148 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -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 }); diff --git a/core/02_error.js b/core/02_error.js index d061164e7..edb9c4843 100644 --- a/core/02_error.js +++ b/core/02_error.js @@ -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; } diff --git a/core/encode_decode_test.js b/core/encode_decode_test.js index 5165b196c..663bc1af6 100644 --- a/core/encode_decode_test.js +++ b/core/encode_decode_test.js @@ -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 �� 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); diff --git a/core/error_builder_test.js b/core/error_builder_test.js index 8a3ca0383..7f8965127 100644 --- a/core/error_builder_test.js +++ b/core/error_builder_test.js @@ -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)) { diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs index 13a47221d..9260cfe56 100644 --- a/core/examples/hello_world.rs +++ b/core/examples/hello_world.rs @@ -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); diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js index 5b16776f4..cea344987 100644 --- a/core/examples/http_bench_json_ops.js +++ b/core/examples/http_bench_json_ops.js @@ -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. */ diff --git a/core/examples/schedule_task.rs b/core/examples/schedule_task.rs index bd4bcb028..475c2d9ad 100644 --- a/core/examples/schedule_task.rs +++ b/core/examples/schedule_task.rs @@ -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(); diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts index bd3729ed9..c5662794a 100644 --- a/core/lib.deno_core.d.ts +++ b/core/lib.deno_core.d.ts @@ -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 diff --git a/core/modules.rs b/core/modules.rs index aec8c498f..c4fa53b51 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -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(); diff --git a/core/runtime.rs b/core/runtime.rs index 3f3caac5e..541aa7c02 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -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(); diff --git a/core/serialize_deserialize_test.js b/core/serialize_deserialize_test.js index cd7aa69b1..724239fcb 100644 --- a/core/serialize_deserialize_test.js +++ b/core/serialize_deserialize_test.js @@ -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); |