diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2022-06-07 10:25:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-07 11:25:10 +0200 |
commit | 9385a913125df07f5216322e0b18aec1c6883957 (patch) | |
tree | 88705e174bf9ba5626a3c9a80911a56e77294682 /core/runtime.rs | |
parent | cfb6067f9bc0900a7d7fc6c75f19930542ed679c (diff) |
refactor(core): Move Deno.core bindings to ops (#14793)
Diffstat (limited to 'core/runtime.rs')
-rw-r--r-- | core/runtime.rs | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/core/runtime.rs b/core/runtime.rs index 66d28226e..6cc638122 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -1990,6 +1990,9 @@ pub mod tests { .build(); let mut runtime = JsRuntime::new(RuntimeOptions { extensions: vec![ext], + get_error_class_fn: Some(&|error| { + crate::error::get_custom_error_class(error).unwrap() + }), ..Default::default() }); @@ -2068,8 +2071,8 @@ pub mod tests { .execute_script( "filename.js", r#" - Deno.core.unrefOp(p1[promiseIdSymbol]); - Deno.core.unrefOp(p2[promiseIdSymbol]); + Deno.core.opSync("op_unref_op", p1[promiseIdSymbol]); + Deno.core.opSync("op_unref_op", p2[promiseIdSymbol]); "#, ) .unwrap(); @@ -2084,8 +2087,8 @@ pub mod tests { .execute_script( "filename.js", r#" - Deno.core.refOp(p1[promiseIdSymbol]); - Deno.core.refOp(p2[promiseIdSymbol]); + Deno.core.opSync("op_ref_op", p1[promiseIdSymbol]); + Deno.core.opSync("op_ref_op", p2[promiseIdSymbol]); "#, ) .unwrap(); @@ -2790,10 +2793,9 @@ assertEquals(1, notify_return_value); "is_proxy.js", r#" (function () { - const { isProxy } = Deno.core; const o = { a: 1, b: 2}; const p = new Proxy(o, {}); - return isProxy(p) && !isProxy(o) && !isProxy(42); + return Deno.core.opSync("op_is_proxy", p) && !Deno.core.opSync("op_is_proxy", o) && !Deno.core.opSync("op_is_proxy", 42); })() "#, ) @@ -2803,20 +2805,6 @@ assertEquals(1, notify_return_value); assert!(all_true.is_true()); } - #[test] - fn test_binding_names() { - let mut runtime = JsRuntime::new(RuntimeOptions::default()); - let all_true: v8::Global<v8::Value> = runtime - .execute_script( - "binding_names.js", - "Deno.core.encode.toString() === 'function encode() { [native code] }'", - ) - .unwrap(); - let mut scope = runtime.handle_scope(); - let all_true = v8::Local::<v8::Value>::new(&mut scope, &all_true); - assert!(all_true.is_true()); - } - #[tokio::test] async fn test_async_opstate_borrow() { struct InnerState(u64); @@ -2884,16 +2872,16 @@ assertEquals(1, notify_return_value); r#" (async function () { const results = []; - Deno.core.setMacrotaskCallback(() => { + Deno.core.opSync("op_set_macrotask_callback", () => { results.push("macrotask"); return true; }); - Deno.core.setNextTickCallback(() => { + Deno.core.opSync("op_set_next_tick_callback", () => { results.push("nextTick"); - Deno.core.setHasTickScheduled(false); + Deno.core.opSync("op_set_has_tick_scheduled", false); }); - Deno.core.setHasTickScheduled(true); + Deno.core.opSync("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]}`); @@ -2916,10 +2904,10 @@ assertEquals(1, notify_return_value); .execute_script( "multiple_macrotasks_and_nextticks.js", r#" - Deno.core.setMacrotaskCallback(() => { return true; }); - Deno.core.setMacrotaskCallback(() => { return true; }); - Deno.core.setNextTickCallback(() => {}); - Deno.core.setNextTickCallback(() => {}); + 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", () => {}); "#, ) .unwrap(); @@ -2962,12 +2950,12 @@ assertEquals(1, notify_return_value); .execute_script( "has_tick_scheduled.js", r#" - Deno.core.setMacrotaskCallback(() => { + Deno.core.opSync("op_set_macrotask_callback", () => { Deno.core.opSync("op_macrotask"); return true; // We're done. }); - Deno.core.setNextTickCallback(() => Deno.core.opSync("op_next_tick")); - Deno.core.setHasTickScheduled(true); + Deno.core.opSync("op_set_next_tick_callback", () => Deno.core.opSync("op_next_tick")); + Deno.core.opSync("op_set_has_tick_scheduled", true); "#, ) .unwrap(); @@ -3103,7 +3091,7 @@ assertEquals(1, notify_return_value); "promise_reject_callback.js", r#" // Note: |promise| is not the promise created below, it's a child. - Deno.core.setPromiseRejectCallback((type, promise, reason) => { + Deno.core.opSync("op_set_promise_reject_callback", (type, promise, reason) => { if (type !== /* PromiseRejectWithNoHandler */ 0) { throw Error("unexpected type: " + type); } @@ -3114,7 +3102,7 @@ assertEquals(1, notify_return_value); throw Error("promiseReject"); // Triggers uncaughtException handler. }); - Deno.core.setUncaughtExceptionCallback((err) => { + Deno.core.opSync("op_set_uncaught_exception_callback", (err) => { if (err.message !== "promiseReject") throw err; Deno.core.opSync("op_uncaught_exception"); }); @@ -3133,13 +3121,13 @@ assertEquals(1, notify_return_value); "promise_reject_callback.js", r#" { - const prev = Deno.core.setPromiseRejectCallback((...args) => { + const prev = Deno.core.opSync("op_set_promise_reject_callback", (...args) => { prev(...args); }); } { - const prev = Deno.core.setUncaughtExceptionCallback((...args) => { + const prev = Deno.core.opSync("op_set_uncaught_exception_callback", (...args) => { prev(...args); throw Error("fail"); }); |