-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: internal ops are under Deno.core.coreOps #523
base: main
Are you sure you want to change the base?
Changes from 3 commits
d90d9ee
d499c60
082370a
655e362
0ce4e8b
7e8d746
46f072d
f9b3db3
cf9be74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ where | |
.get(scope, key.into()) | ||
.unwrap_or_else(|| panic!("{path} exists")) | ||
.try_into() | ||
.unwrap_or_else(|_| panic!("unable to convert")) | ||
.unwrap_or_else(|_| panic!("Unable to convert {path} to desired type")) | ||
Comment on lines
145
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This funciton should probably be a macro and accept a token tree to print out the desired type nicely |
||
} | ||
|
||
pub mod v8_static_strings { | ||
|
@@ -140,6 +140,7 @@ pub mod v8_static_strings { | |
|
||
pub static DENO: &[u8] = b"Deno"; | ||
pub static CORE: &[u8] = b"core"; | ||
pub static CORE_OPS: &[u8] = b"coreOps"; | ||
pub static OPS: &[u8] = b"ops"; | ||
pub static URL: &[u8] = b"url"; | ||
pub static MAIN: &[u8] = b"main"; | ||
|
@@ -196,6 +197,20 @@ pub(crate) fn initialize_deno_core_namespace<'s>( | |
.set(scope, deno_core_ops_key.into(), deno_core_ops_obj.into()) | ||
.unwrap(); | ||
|
||
// Set up `Deno.core.coreOps` object | ||
let deno_core_core_ops_obj = v8::Object::new(scope); | ||
let deno_core_core_ops_key = | ||
v8::String::new_external_onebyte_static(scope, v8_static_strings::CORE_OPS) | ||
.unwrap(); | ||
|
||
deno_core_obj | ||
.set( | ||
scope, | ||
deno_core_core_ops_key.into(), | ||
deno_core_core_ops_obj.into(), | ||
) | ||
.unwrap(); | ||
|
||
// If we're initializing fresh context set up the console | ||
if init_mode == InitMode::New { | ||
// Bind `call_console` to Deno.core.callConsole | ||
|
@@ -241,10 +256,13 @@ pub(crate) fn initialize_primordials_and_infra( | |
} | ||
|
||
/// Set up JavaScript bindings for ops. | ||
pub(crate) fn initialize_deno_core_ops_bindings<'s>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function needs to be split into two separate functions - one for "core" ops and one for "ext" ops. |
||
pub(crate) fn initialize_ops_bindings<'s>( | ||
scope: &mut v8::HandleScope<'s>, | ||
context: v8::Local<'s, v8::Context>, | ||
op_ctxs: &[OpCtx], | ||
init_mode: InitMode, | ||
// TODO(bartlomieju): this is really hacky solution | ||
last_deno_core_op_id: usize, | ||
) { | ||
let global = context.global(scope); | ||
|
||
|
@@ -260,6 +278,7 @@ pub(crate) fn initialize_deno_core_ops_bindings<'s>( | |
v8_static_strings::OPS, | ||
"Deno.core.ops", | ||
); | ||
|
||
let set_up_async_stub_fn: v8::Local<v8::Function> = get( | ||
scope, | ||
deno_core_obj, | ||
|
@@ -268,7 +287,41 @@ pub(crate) fn initialize_deno_core_ops_bindings<'s>( | |
); | ||
|
||
let undefined = v8::undefined(scope); | ||
for op_ctx in op_ctxs { | ||
|
||
let deno_core_op_ctxs = &op_ctxs[..last_deno_core_op_id]; | ||
let ext_op_ctxs = &op_ctxs[last_deno_core_op_id..]; | ||
littledivy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// TODO(bartlomieju): hoist this to a separate function | ||
if init_mode == InitMode::New { | ||
let deno_core_core_ops_obj: v8::Local<v8::Object> = get( | ||
scope, | ||
deno_core_obj, | ||
v8_static_strings::CORE_OPS, | ||
"Deno.core.coreOps", | ||
); | ||
for op_ctx in deno_core_op_ctxs { | ||
let mut op_fn = op_ctx_function(scope, op_ctx); | ||
let key = v8::String::new_external_onebyte_static( | ||
scope, | ||
op_ctx.decl.name.as_bytes(), | ||
) | ||
.unwrap(); | ||
|
||
// For async ops we need to set them up, by calling `Deno.core.setUpAsyncStub` - | ||
// this call will generate an optimized function that binds to the provided | ||
// op, while keeping track of promises and error remapping. | ||
if op_ctx.decl.is_async { | ||
let result = set_up_async_stub_fn | ||
.call(scope, undefined.into(), &[key.into(), op_fn.into()]) | ||
.unwrap(); | ||
op_fn = result.try_into().unwrap() | ||
} | ||
|
||
deno_core_core_ops_obj.set(scope, key.into(), op_fn.into()); | ||
} | ||
} | ||
|
||
for op_ctx in ext_op_ctxs { | ||
let mut op_fn = op_ctx_function(scope, op_ctx); | ||
let key = v8_static_strings::new(scope, op_ctx.decl.name.as_bytes()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,8 +376,8 @@ async fn wasm_streaming_op_invocation_in_import() { | |
runtime.execute_script_static("setup.js", | ||
r#" | ||
Deno.core.setWasmStreamingCallback((source, rid) => { | ||
Deno.core.ops.op_wasm_streaming_set_url(rid, "file:///foo.wasm"); | ||
Deno.core.ops.op_wasm_streaming_feed(rid, source); | ||
Deno.core.wasmStreamingSetUrl(rid, "file:///foo.wasm"); | ||
Deno.core.wasmStreamingFeed(rid, source); | ||
Deno.core.close(rid); | ||
}); | ||
"#).unwrap(); | ||
|
@@ -826,7 +826,7 @@ async fn test_promise_rejection_handler_generic( | |
function throwError() { | ||
throw new Error("boom"); | ||
} | ||
const { op_void_async, op_void_async_deferred } = Deno.core.ensureFastOps(); | ||
const { opVoidAsync, opVoidAsyncDeferred } = Deno.core; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to verify it, but I believe |
||
if (test != "no_handler") { | ||
Deno.core.setUnhandledPromiseRejectionHandler((promise, rejection) => { | ||
if (test.startsWith("exception_")) { | ||
|
@@ -841,9 +841,9 @@ async fn test_promise_rejection_handler_generic( | |
} | ||
if (test != "no_reject") { | ||
if (test.startsWith("async_op_eager_")) { | ||
op_void_async().then(() => { Deno.core.ops.op_breakpoint(); throw new Error("fail") }); | ||
opVoidAsync().then(() => { Deno.core.ops.op_breakpoint(); throw new Error("fail") }); | ||
} else if (test.startsWith("async_op_deferred_")) { | ||
op_void_async_deferred().then(() => { Deno.core.ops.op_breakpoint(); throw new Error("fail") }); | ||
opVoidAsyncDeferred().then(() => { Deno.core.ops.op_breakpoint(); throw new Error("fail") }); | ||
} else if (test.startsWith("throw_")) { | ||
Deno.core.ops.op_breakpoint(); | ||
throw new Error("fail"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should probably be rolled into
01_core.js
to avoid having to expose these APIs toDeno.core