mirror of
https://github.com/denoland/deno.git
synced 2024-12-31 11:34:15 -05:00
refactor(core): rename send() to opcall() (#10307)
I think it's a better fit since recv() was killed and opcall <> syscall (send/recv was too reminiscent of request/response and custom payloads)
This commit is contained in:
parent
8074d8bcf3
commit
dd156e886b
7 changed files with 24 additions and 25 deletions
|
@ -9,7 +9,7 @@ unitTest(async function sendAsyncStackTrace() {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const s = error.stack.toString();
|
const s = error.stack.toString();
|
||||||
console.log(s);
|
console.log(s);
|
||||||
assertStringIncludes(s, "dispatch_test.ts");
|
assertStringIncludes(s, "opcall_test.ts");
|
||||||
assertStringIncludes(s, "read");
|
assertStringIncludes(s, "read");
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -15,7 +15,7 @@ import "./console_test.ts";
|
||||||
import "./copy_file_test.ts";
|
import "./copy_file_test.ts";
|
||||||
import "./custom_event_test.ts";
|
import "./custom_event_test.ts";
|
||||||
import "./dir_test.ts";
|
import "./dir_test.ts";
|
||||||
import "./dispatch_test.ts";
|
import "./opcall_test.ts";
|
||||||
import "./error_stack_test.ts";
|
import "./error_stack_test.ts";
|
||||||
import "./event_test.ts";
|
import "./event_test.ts";
|
||||||
import "./event_target_test.ts";
|
import "./event_target_test.ts";
|
||||||
|
|
|
@ -81,7 +81,7 @@ fn bench_op_nop(b: &mut Bencher) {
|
||||||
bench_runtime_js(
|
bench_runtime_js(
|
||||||
b,
|
b,
|
||||||
r#"for(let i=0; i < 1e3; i++) {
|
r#"for(let i=0; i < 1e3; i++) {
|
||||||
Deno.core.dispatchByName("nop", null, null, null);
|
Deno.core.opSync("nop", null, null, null);
|
||||||
}"#,
|
}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ lazy_static::lazy_static! {
|
||||||
function: print.map_fn_to()
|
function: print.map_fn_to()
|
||||||
},
|
},
|
||||||
v8::ExternalReference {
|
v8::ExternalReference {
|
||||||
function: send.map_fn_to()
|
function: opcall.map_fn_to()
|
||||||
},
|
},
|
||||||
v8::ExternalReference {
|
v8::ExternalReference {
|
||||||
function: set_macrotask_callback.map_fn_to()
|
function: set_macrotask_callback.map_fn_to()
|
||||||
|
@ -119,7 +119,7 @@ pub fn initialize_context<'s>(
|
||||||
|
|
||||||
// Bind functions to Deno.core.*
|
// Bind functions to Deno.core.*
|
||||||
set_func(scope, core_val, "print", print);
|
set_func(scope, core_val, "print", print);
|
||||||
set_func(scope, core_val, "send", send);
|
set_func(scope, core_val, "opcall", opcall);
|
||||||
set_func(
|
set_func(
|
||||||
scope,
|
scope,
|
||||||
core_val,
|
core_val,
|
||||||
|
@ -317,7 +317,7 @@ fn print(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send<'s>(
|
fn opcall<'s>(
|
||||||
scope: &mut v8::HandleScope<'s>,
|
scope: &mut v8::HandleScope<'s>,
|
||||||
args: v8::FunctionCallbackArguments,
|
args: v8::FunctionCallbackArguments,
|
||||||
mut rv: v8::ReturnValue,
|
mut rv: v8::ReturnValue,
|
||||||
|
@ -336,7 +336,7 @@ fn send<'s>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// send(0) returns obj of all ops, handle as special case
|
// opcall(0) returns obj of all ops, handle as special case
|
||||||
if op_id == 0 {
|
if op_id == 0 {
|
||||||
// TODO: Serialize as HashMap when serde_v8 supports maps ...
|
// TODO: Serialize as HashMap when serde_v8 supports maps ...
|
||||||
let ops = OpTable::op_entries(state.op_state.clone());
|
let ops = OpTable::op_entries(state.op_state.clone());
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
// Available on start due to bindings.
|
// Available on start due to bindings.
|
||||||
const { send } = window.Deno.core;
|
const { opcall } = window.Deno.core;
|
||||||
|
|
||||||
let opsCache = {};
|
let opsCache = {};
|
||||||
const errorMap = {
|
const errorMap = {
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
|
|
||||||
function ops() {
|
function ops() {
|
||||||
// op id 0 is a special value to retrieve the map of registered ops.
|
// op id 0 is a special value to retrieve the map of registered ops.
|
||||||
const newOpsCache = Object.fromEntries(send(0));
|
const newOpsCache = Object.fromEntries(opcall(0));
|
||||||
opsCache = Object.freeze(newOpsCache);
|
opsCache = Object.freeze(newOpsCache);
|
||||||
return opsCache;
|
return opsCache;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatch(opName, promiseId, control, zeroCopy) {
|
function dispatch(opName, promiseId, control, zeroCopy) {
|
||||||
return send(opsCache[opName], promiseId, control, zeroCopy);
|
const opId = typeof opName === "string" ? opsCache[opName] : opName;
|
||||||
|
return opcall(opId, promiseId, control, zeroCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerErrorClass(className, errorClass) {
|
function registerErrorClass(className, errorClass) {
|
||||||
|
@ -124,8 +125,6 @@
|
||||||
Object.assign(window.Deno.core, {
|
Object.assign(window.Deno.core, {
|
||||||
opAsync,
|
opAsync,
|
||||||
opSync,
|
opSync,
|
||||||
dispatch: send,
|
|
||||||
dispatchByName: dispatch,
|
|
||||||
ops,
|
ops,
|
||||||
close,
|
close,
|
||||||
resources,
|
resources,
|
||||||
|
|
|
@ -19,8 +19,8 @@ fn main() {
|
||||||
// The second one just transforms some input and returns it to JavaScript.
|
// The second one just transforms some input and returns it to JavaScript.
|
||||||
|
|
||||||
// Register the op for outputting a string to stdout.
|
// Register the op for outputting a string to stdout.
|
||||||
// It can be invoked with Deno.core.dispatch and the id this method returns
|
// It can be invoked with Deno.core.opcall and the id this method returns
|
||||||
// or Deno.core.dispatchByName and the name provided.
|
// or Deno.core.opSync and the name provided.
|
||||||
runtime.register_op(
|
runtime.register_op(
|
||||||
"op_print",
|
"op_print",
|
||||||
// The op_fn callback takes a state object OpState,
|
// The op_fn callback takes a state object OpState,
|
||||||
|
@ -72,7 +72,7 @@ Deno.core.ops();
|
||||||
// our op_print op to display the stringified argument.
|
// our op_print op to display the stringified argument.
|
||||||
const _newline = new Uint8Array([10]);
|
const _newline = new Uint8Array([10]);
|
||||||
function print(value) {
|
function print(value) {
|
||||||
Deno.core.dispatchByName('op_print', 0, value.toString(), _newline);
|
Deno.core.opSync('op_print', value.toString(), _newline);
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,9 +73,9 @@ struct IsolateAllocations {
|
||||||
/// The JsRuntime future completes when there is an error or when all
|
/// The JsRuntime future completes when there is an error or when all
|
||||||
/// pending ops have completed.
|
/// pending ops have completed.
|
||||||
///
|
///
|
||||||
/// Ops are created in JavaScript by calling Deno.core.dispatch(), and in Rust
|
/// Pending ops are created in JavaScript by calling Deno.core.opAsync(), and in Rust
|
||||||
/// by implementing dispatcher function that takes control buffer and optional zero copy buffer
|
/// by implementing an async function that takes a serde::Deserialize "control argument"
|
||||||
/// as arguments. An async Op corresponds exactly to a Promise in JavaScript.
|
/// and an optional zero copy buffer, each async Op is tied to a Promise in JavaScript.
|
||||||
pub struct JsRuntime {
|
pub struct JsRuntime {
|
||||||
// This is an Option<OwnedIsolate> instead of just OwnedIsolate to workaround
|
// This is an Option<OwnedIsolate> instead of just OwnedIsolate to workaround
|
||||||
// an safety issue with SnapshotCreator. See JsRuntime::drop.
|
// an safety issue with SnapshotCreator. See JsRuntime::drop.
|
||||||
|
@ -1572,9 +1572,9 @@ pub mod tests {
|
||||||
"filename.js",
|
"filename.js",
|
||||||
r#"
|
r#"
|
||||||
let control = 42;
|
let control = 42;
|
||||||
Deno.core.send(1, null, control);
|
Deno.core.opcall(1, null, control);
|
||||||
async function main() {
|
async function main() {
|
||||||
Deno.core.send(1, null, control);
|
Deno.core.opcall(1, null, control);
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
"#,
|
"#,
|
||||||
|
@ -1590,7 +1590,7 @@ pub mod tests {
|
||||||
.execute(
|
.execute(
|
||||||
"filename.js",
|
"filename.js",
|
||||||
r#"
|
r#"
|
||||||
Deno.core.send(1);
|
Deno.core.opcall(1);
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1605,7 +1605,7 @@ pub mod tests {
|
||||||
"filename.js",
|
"filename.js",
|
||||||
r#"
|
r#"
|
||||||
let zero_copy_a = new Uint8Array([0]);
|
let zero_copy_a = new Uint8Array([0]);
|
||||||
Deno.core.send(1, null, null, zero_copy_a);
|
Deno.core.opcall(1, null, null, zero_copy_a);
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1673,7 +1673,7 @@ pub mod tests {
|
||||||
r#"
|
r#"
|
||||||
let thrown;
|
let thrown;
|
||||||
try {
|
try {
|
||||||
Deno.core.dispatch(100);
|
Deno.core.opSync(100);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
thrown = e;
|
thrown = e;
|
||||||
}
|
}
|
||||||
|
@ -1934,7 +1934,7 @@ pub mod tests {
|
||||||
import { b } from './b.js'
|
import { b } from './b.js'
|
||||||
if (b() != 'b') throw Error();
|
if (b() != 'b') throw Error();
|
||||||
let control = 42;
|
let control = 42;
|
||||||
Deno.core.send(1, null, control);
|
Deno.core.opcall(1, null, control);
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -2304,7 +2304,7 @@ main();
|
||||||
let error = runtime
|
let error = runtime
|
||||||
.execute(
|
.execute(
|
||||||
"core_js_stack_frame.js",
|
"core_js_stack_frame.js",
|
||||||
"Deno.core.dispatchByName('non_existent');",
|
"Deno.core.opSync('non_existent');",
|
||||||
)
|
)
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
let error_string = error.to_string();
|
let error_string = error.to_string();
|
||||||
|
|
Loading…
Reference in a new issue