Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit 55e89e2

Browse files
committed
fix import_sync unhandled rejection
1 parent 57854c1 commit 55e89e2

10 files changed

Lines changed: 58 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ deno_error = { version = "0.7.0", features = ["serde_json", "serde", "url", "tok
2828
deno_ops = { version = "0.262.0", path = "./ops" }
2929
deno_unsync = "0.4.2"
3030
serde_v8 = { version = "0.295.0", path = "./serde_v8" }
31-
v8 = { version = "145.0.0", default-features = false }
31+
v8 = { version = "146.1.0", default-features = false }
3232

3333
anyhow = "1"
3434
bencher = "0.1"

core/modules/map.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,22 @@ impl ModuleMap {
15431543
let promise = v8::Local::<v8::Promise>::try_from(value)
15441544
.expect("Expected to get promise as module evaluation result");
15451545

1546+
promise.mark_as_handled();
1547+
15461548
match promise.state() {
15471549
PromiseState::Fulfilled => Ok(()),
15481550
PromiseState::Rejected => {
15491551
let err = promise.result(tc_scope);
1552+
1553+
let exception_state = JsRealm::exception_state_from_scope(tc_scope);
1554+
// TODO: remove after crrev.com/c/7595271
1555+
exception_state.track_promise_rejection(
1556+
tc_scope,
1557+
promise,
1558+
v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject,
1559+
None,
1560+
);
1561+
15501562
Err(
15511563
CoreErrorKind::Js(JsError::from_v8_exception(tc_scope, err))
15521564
.into_box(),

core/ops_builtin.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub fn op_print(
232232
Ok(())
233233
}
234234

235-
pub struct WasmStreamingResource(pub(crate) RefCell<v8::WasmStreaming>);
235+
pub struct WasmStreamingResource(pub(crate) RefCell<v8::WasmStreaming<false>>);
236236

237237
impl Resource for WasmStreamingResource {
238238
fn close(self: Rc<Self>) {
@@ -623,7 +623,20 @@ fn wrap_module<'s, 'i>(
623623

624624
wrapper_module.instantiate_module(scope, resolve_callback)?;
625625

626-
wrapper_module.evaluate(scope)?;
626+
let result = wrapper_module.evaluate(scope)?;
627+
if let Ok(promise) = result.try_cast::<v8::Promise>() {
628+
promise.mark_as_handled();
629+
if promise.state() == v8::PromiseState::Rejected {
630+
let exception_state = JsRealm::exception_state_from_scope(scope);
631+
// TODO: remove after crrev.com/c/7595271
632+
exception_state.track_promise_rejection(
633+
scope,
634+
promise,
635+
v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject,
636+
None,
637+
);
638+
}
639+
}
627640

628641
Some(wrapper_module)
629642
}

core/runtime/tests/misc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ async fn global_template_middleware() {
14351435
) -> v8::Intercepted {
14361436
CALLS.lock().push("descriptor".to_string());
14371437

1438-
v8::Intercepted::No
1438+
v8::Intercepted::kNo
14391439
}
14401440

14411441
pub fn setter<'s>(
@@ -1446,7 +1446,7 @@ async fn global_template_middleware() {
14461446
_rv: v8::ReturnValue<()>,
14471447
) -> v8::Intercepted {
14481448
CALLS.lock().push("setter".to_string());
1449-
v8::Intercepted::No
1449+
v8::Intercepted::kNo
14501450
}
14511451

14521452
fn definer<'s>(
@@ -1457,7 +1457,7 @@ async fn global_template_middleware() {
14571457
_rv: v8::ReturnValue<()>,
14581458
) -> v8::Intercepted {
14591459
CALLS.lock().push("definer".to_string());
1460-
v8::Intercepted::No
1460+
v8::Intercepted::kNo
14611461
}
14621462

14631463
pub fn gt_middleware<'s>(

ops/op2/dispatch_fast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ impl V8FastCallType {
250250
V8FastCallType::Bool => quote!(CType::Bool.as_info()),
251251
V8FastCallType::U32 => quote!(v8::fast_api::CTypeInfo::new(
252252
CType::Uint32,
253-
v8::fast_api::Flags::Clamp
253+
v8::fast_api::Flags::empty(),
254254
)),
255255
V8FastCallType::I32 => quote!(v8::fast_api::CTypeInfo::new(
256256
CType::Int32,
257-
v8::fast_api::Flags::Clamp
257+
v8::fast_api::Flags::empty(),
258258
)),
259259
V8FastCallType::U64 => quote!(CType::Uint64.as_info()),
260260
V8FastCallType::I64 => quote!(CType::Int64.as_info()),

testing/integration/import_sync_throw/import_sync_throw.out

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018-2025 the Deno authors. MIT license.
2+
3+
import { assertThrows } from "checkin:testing";
4+
const { op_import_sync, op_path_to_url } = Deno.core.ops;
5+
6+
globalThis.onunhandledrejection = (...args) => {
7+
console.error("unexpected call", args);
8+
};
9+
globalThis.onrejectionhandled = (...args) => {
10+
console.error("unexpected call", args);
11+
};
12+
13+
assertThrows(
14+
() => {
15+
op_import_sync(
16+
op_path_to_url("./integration/import_sync_throw/module.mjs"),
17+
);
18+
},
19+
Error,
20+
"this is a test",
21+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw new Error("this is a test");

testing/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ integration_test!(
7777
error_get_script_name_or_source_url,
7878
import_sync,
7979
import_sync_existing,
80+
import_sync_throw,
8081
main_module_handler,
8182
module_types,
8283
pending_unref_op_tla,

0 commit comments

Comments
 (0)