1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -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:
Aaron O'Mullan 2021-04-23 17:50:45 +02:00 committed by GitHub
parent 8074d8bcf3
commit dd156e886b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 25 deletions

View file

@ -9,7 +9,7 @@ unitTest(async function sendAsyncStackTrace() {
} catch (error) {
const s = error.stack.toString();
console.log(s);
assertStringIncludes(s, "dispatch_test.ts");
assertStringIncludes(s, "opcall_test.ts");
assertStringIncludes(s, "read");
}
});

View file

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

View file

@ -81,7 +81,7 @@ fn bench_op_nop(b: &mut Bencher) {
bench_runtime_js(
b,
r#"for(let i=0; i < 1e3; i++) {
Deno.core.dispatchByName("nop", null, null, null);
Deno.core.opSync("nop", null, null, null);
}"#,
);
}

View file

@ -26,7 +26,7 @@ lazy_static::lazy_static! {
function: print.map_fn_to()
},
v8::ExternalReference {
function: send.map_fn_to()
function: opcall.map_fn_to()
},
v8::ExternalReference {
function: set_macrotask_callback.map_fn_to()
@ -119,7 +119,7 @@ pub fn initialize_context<'s>(
// Bind functions to Deno.core.*
set_func(scope, core_val, "print", print);
set_func(scope, core_val, "send", send);
set_func(scope, core_val, "opcall", opcall);
set_func(
scope,
core_val,
@ -317,7 +317,7 @@ fn print(
}
}
fn send<'s>(
fn opcall<'s>(
scope: &mut v8::HandleScope<'s>,
args: v8::FunctionCallbackArguments,
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 {
// TODO: Serialize as HashMap when serde_v8 supports maps ...
let ops = OpTable::op_entries(state.op_state.clone());

View file

@ -3,7 +3,7 @@
((window) => {
// Available on start due to bindings.
const { send } = window.Deno.core;
const { opcall } = window.Deno.core;
let opsCache = {};
const errorMap = {
@ -61,7 +61,7 @@
function 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);
return opsCache;
}
@ -76,7 +76,8 @@
}
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) {
@ -124,8 +125,6 @@
Object.assign(window.Deno.core, {
opAsync,
opSync,
dispatch: send,
dispatchByName: dispatch,
ops,
close,
resources,

View file

@ -19,8 +19,8 @@ fn main() {
// The second one just transforms some input and returns it to JavaScript.
// Register the op for outputting a string to stdout.
// It can be invoked with Deno.core.dispatch and the id this method returns
// or Deno.core.dispatchByName and the name provided.
// It can be invoked with Deno.core.opcall and the id this method returns
// or Deno.core.opSync and the name provided.
runtime.register_op(
"op_print",
// 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.
const _newline = new Uint8Array([10]);
function print(value) {
Deno.core.dispatchByName('op_print', 0, value.toString(), _newline);
Deno.core.opSync('op_print', value.toString(), _newline);
}
"#,
)

View file

@ -73,9 +73,9 @@ struct IsolateAllocations {
/// The JsRuntime future completes when there is an error or when all
/// pending ops have completed.
///
/// Ops are created in JavaScript by calling Deno.core.dispatch(), and in Rust
/// by implementing dispatcher function that takes control buffer and optional zero copy buffer
/// as arguments. An async Op corresponds exactly to a Promise in JavaScript.
/// Pending ops are created in JavaScript by calling Deno.core.opAsync(), and in Rust
/// by implementing an async function that takes a serde::Deserialize "control argument"
/// and an optional zero copy buffer, each async Op is tied to a Promise in JavaScript.
pub struct JsRuntime {
// This is an Option<OwnedIsolate> instead of just OwnedIsolate to workaround
// an safety issue with SnapshotCreator. See JsRuntime::drop.
@ -1572,9 +1572,9 @@ pub mod tests {
"filename.js",
r#"
let control = 42;
Deno.core.send(1, null, control);
Deno.core.opcall(1, null, control);
async function main() {
Deno.core.send(1, null, control);
Deno.core.opcall(1, null, control);
}
main();
"#,
@ -1590,7 +1590,7 @@ pub mod tests {
.execute(
"filename.js",
r#"
Deno.core.send(1);
Deno.core.opcall(1);
"#,
)
.unwrap();
@ -1605,7 +1605,7 @@ pub mod tests {
"filename.js",
r#"
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();
@ -1673,7 +1673,7 @@ pub mod tests {
r#"
let thrown;
try {
Deno.core.dispatch(100);
Deno.core.opSync(100);
} catch (e) {
thrown = e;
}
@ -1934,7 +1934,7 @@ pub mod tests {
import { b } from './b.js'
if (b() != 'b') throw Error();
let control = 42;
Deno.core.send(1, null, control);
Deno.core.opcall(1, null, control);
"#,
)
.unwrap();
@ -2304,7 +2304,7 @@ main();
let error = runtime
.execute(
"core_js_stack_frame.js",
"Deno.core.dispatchByName('non_existent');",
"Deno.core.opSync('non_existent');",
)
.unwrap_err();
let error_string = error.to_string();