diff --git a/Cargo.lock b/Cargo.lock index dedce6d66..c6aec7b4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3305,9 +3305,9 @@ dependencies = [ [[package]] name = "v8" -version = "145.0.0" +version = "146.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61d9a107e16bae35a0be2bb0096ac1d2318aac352c82edd796ab2b9cac66d8f0" +checksum = "70bb6bcbb6a406fd720dad66d85337bd401d8276c7276f6a86164af6e1c57118" dependencies = [ "bindgen", "bitflags", diff --git a/Cargo.toml b/Cargo.toml index 5447c8ea6..95c054803 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ deno_error = { version = "0.7.0", features = ["serde_json", "serde", "url", "tok deno_ops = { version = "0.262.0", path = "./ops" } deno_unsync = "0.4.2" serde_v8 = { version = "0.295.0", path = "./serde_v8" } -v8 = { version = "145.0.0", default-features = false } +v8 = { version = "146.1.0", default-features = false } anyhow = "1" bencher = "0.1" diff --git a/core/modules/map.rs b/core/modules/map.rs index f5b608436..3c58d579b 100644 --- a/core/modules/map.rs +++ b/core/modules/map.rs @@ -1543,10 +1543,22 @@ impl ModuleMap { let promise = v8::Local::::try_from(value) .expect("Expected to get promise as module evaluation result"); + promise.mark_as_handled(); + match promise.state() { PromiseState::Fulfilled => Ok(()), PromiseState::Rejected => { let err = promise.result(tc_scope); + + let exception_state = JsRealm::exception_state_from_scope(tc_scope); + // TODO: remove after crrev.com/c/7595271 + exception_state.track_promise_rejection( + tc_scope, + promise, + v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject, + None, + ); + Err( CoreErrorKind::Js(JsError::from_v8_exception(tc_scope, err)) .into_box(), diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 2f66aadd2..ca19e91e0 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -232,7 +232,7 @@ pub fn op_print( Ok(()) } -pub struct WasmStreamingResource(pub(crate) RefCell); +pub struct WasmStreamingResource(pub(crate) RefCell>); impl Resource for WasmStreamingResource { fn close(self: Rc) { @@ -623,7 +623,20 @@ fn wrap_module<'s, 'i>( wrapper_module.instantiate_module(scope, resolve_callback)?; - wrapper_module.evaluate(scope)?; + let result = wrapper_module.evaluate(scope)?; + if let Ok(promise) = result.try_cast::() { + promise.mark_as_handled(); + if promise.state() == v8::PromiseState::Rejected { + let exception_state = JsRealm::exception_state_from_scope(scope); + // TODO: remove after crrev.com/c/7595271 + exception_state.track_promise_rejection( + scope, + promise, + v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject, + None, + ); + } + } Some(wrapper_module) } diff --git a/core/runtime/tests/misc.rs b/core/runtime/tests/misc.rs index a7b8b5b15..9ddfe023a 100644 --- a/core/runtime/tests/misc.rs +++ b/core/runtime/tests/misc.rs @@ -1435,7 +1435,7 @@ async fn global_template_middleware() { ) -> v8::Intercepted { CALLS.lock().push("descriptor".to_string()); - v8::Intercepted::No + v8::Intercepted::kNo } pub fn setter<'s>( @@ -1446,7 +1446,7 @@ async fn global_template_middleware() { _rv: v8::ReturnValue<()>, ) -> v8::Intercepted { CALLS.lock().push("setter".to_string()); - v8::Intercepted::No + v8::Intercepted::kNo } fn definer<'s>( @@ -1457,7 +1457,7 @@ async fn global_template_middleware() { _rv: v8::ReturnValue<()>, ) -> v8::Intercepted { CALLS.lock().push("definer".to_string()); - v8::Intercepted::No + v8::Intercepted::kNo } pub fn gt_middleware<'s>( diff --git a/ops/op2/dispatch_fast.rs b/ops/op2/dispatch_fast.rs index a52f58598..e938c59bb 100644 --- a/ops/op2/dispatch_fast.rs +++ b/ops/op2/dispatch_fast.rs @@ -250,11 +250,11 @@ impl V8FastCallType { V8FastCallType::Bool => quote!(CType::Bool.as_info()), V8FastCallType::U32 => quote!(v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp + v8::fast_api::Flags::empty(), )), V8FastCallType::I32 => quote!(v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp + v8::fast_api::Flags::empty(), )), V8FastCallType::U64 => quote!(CType::Uint64.as_info()), V8FastCallType::I64 => quote!(CType::Int64.as_info()), diff --git a/ops/op2/test_cases/async/async_deferred.out b/ops/op2/test_cases/async/async_deferred.out index 7a512ffff..af302407e 100644 --- a/ops/op2/test_cases/async/async_deferred.out +++ b/ops/op2/test_cases/async/async_deferred.out @@ -27,7 +27,7 @@ pub const fn op_async_deferred() -> ::deno_core::_ops::OpDecl { CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], @@ -46,7 +46,7 @@ pub const fn op_async_deferred() -> ::deno_core::_ops::OpDecl { CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], diff --git a/ops/op2/test_cases/async/async_lazy.out b/ops/op2/test_cases/async/async_lazy.out index 29239db86..40ae3f94d 100644 --- a/ops/op2/test_cases/async/async_lazy.out +++ b/ops/op2/test_cases/async/async_lazy.out @@ -27,7 +27,7 @@ pub const fn op_async_lazy() -> ::deno_core::_ops::OpDecl { CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], @@ -46,7 +46,7 @@ pub const fn op_async_lazy() -> ::deno_core::_ops::OpDecl { CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], diff --git a/ops/op2/test_cases/sync/add.out b/ops/op2/test_cases/sync/add.out index 7d25988b0..d8bfc0ba9 100644 --- a/ops/op2/test_cases/sync/add.out +++ b/ops/op2/test_cases/sync/add.out @@ -24,17 +24,17 @@ const fn op_add() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), ], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -49,17 +49,17 @@ const fn op_add() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], diff --git a/ops/op2/test_cases/sync/fast_alternative.out b/ops/op2/test_cases/sync/fast_alternative.out index ce40c98a5..4f853650f 100644 --- a/ops/op2/test_cases/sync/fast_alternative.out +++ b/ops/op2/test_cases/sync/fast_alternative.out @@ -131,17 +131,17 @@ const fn op_fast() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), ], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -156,17 +156,17 @@ const fn op_fast() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], @@ -435,17 +435,17 @@ const fn op_fast_generic() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), ], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -460,17 +460,17 @@ const fn op_fast_generic() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], diff --git a/ops/op2/test_cases/sync/result_primitive.out b/ops/op2/test_cases/sync/result_primitive.out index 909e4f6f7..8c0d39d2d 100644 --- a/ops/op2/test_cases/sync/result_primitive.out +++ b/ops/op2/test_cases/sync/result_primitive.out @@ -24,7 +24,7 @@ pub const fn op_u32_with_result() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[CType::V8Value.as_info(), CType::CallbackOptions.as_info()], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -39,7 +39,7 @@ pub const fn op_u32_with_result() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[CType::V8Value.as_info(), CType::CallbackOptions.as_info()], deno_core::v8::fast_api::Int64Representation::BigInt, diff --git a/ops/op2/test_cases/sync/smi.out b/ops/op2/test_cases/sync/smi.out index 7ad23a80b..2ecd4bc0d 100644 --- a/ops/op2/test_cases/sync/smi.out +++ b/ops/op2/test_cases/sync/smi.out @@ -24,25 +24,25 @@ const fn op_smi_unsigned_return() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), ], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -57,25 +57,25 @@ const fn op_smi_unsigned_return() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], @@ -261,25 +261,25 @@ const fn op_smi_signed_return() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), ], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -294,25 +294,25 @@ const fn op_smi_signed_return() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), v8::fast_api::CTypeInfo::new( CType::Int32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), CType::CallbackOptions.as_info(), ], diff --git a/ops/op2/test_cases/sync/string_cow.out b/ops/op2/test_cases/sync/string_cow.out index 7a563374b..58c854c8c 100644 --- a/ops/op2/test_cases/sync/string_cow.out +++ b/ops/op2/test_cases/sync/string_cow.out @@ -24,7 +24,7 @@ const fn op_string_cow() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[CType::V8Value.as_info(), CType::SeqOneByteString.as_info()], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -39,7 +39,7 @@ const fn op_string_cow() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), diff --git a/ops/op2/test_cases/sync/string_onebyte.out b/ops/op2/test_cases/sync/string_onebyte.out index c006e6a0a..6d98976e1 100644 --- a/ops/op2/test_cases/sync/string_onebyte.out +++ b/ops/op2/test_cases/sync/string_onebyte.out @@ -24,7 +24,7 @@ const fn op_string_onebyte() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[CType::V8Value.as_info(), CType::SeqOneByteString.as_info()], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -39,7 +39,7 @@ const fn op_string_onebyte() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), diff --git a/ops/op2/test_cases/sync/string_owned.out b/ops/op2/test_cases/sync/string_owned.out index 04c5aeafa..6b9f47e50 100644 --- a/ops/op2/test_cases/sync/string_owned.out +++ b/ops/op2/test_cases/sync/string_owned.out @@ -24,7 +24,7 @@ const fn op_string_owned() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[CType::V8Value.as_info(), CType::SeqOneByteString.as_info()], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -39,7 +39,7 @@ const fn op_string_owned() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), diff --git a/ops/op2/test_cases/sync/string_ref.out b/ops/op2/test_cases/sync/string_ref.out index efd905d67..d45b3b5ca 100644 --- a/ops/op2/test_cases/sync/string_ref.out +++ b/ops/op2/test_cases/sync/string_ref.out @@ -24,7 +24,7 @@ const fn op_string_owned() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[CType::V8Value.as_info(), CType::SeqOneByteString.as_info()], deno_core::v8::fast_api::Int64Representation::BigInt, @@ -39,7 +39,7 @@ const fn op_string_owned() -> ::deno_core::_ops::OpDecl { &deno_core::v8::fast_api::CFunctionInfo::new( v8::fast_api::CTypeInfo::new( CType::Uint32, - v8::fast_api::Flags::Clamp, + v8::fast_api::Flags::empty(), ), &[ CType::V8Value.as_info(), diff --git a/testing/integration/import_sync_throw/import_sync_throw.out b/testing/integration/import_sync_throw/import_sync_throw.out new file mode 100644 index 000000000..e69de29bb diff --git a/testing/integration/import_sync_throw/import_sync_throw.ts b/testing/integration/import_sync_throw/import_sync_throw.ts new file mode 100644 index 000000000..42c383e4d --- /dev/null +++ b/testing/integration/import_sync_throw/import_sync_throw.ts @@ -0,0 +1,21 @@ +// Copyright 2018-2025 the Deno authors. MIT license. + +import { assertThrows } from "checkin:testing"; +const { op_import_sync, op_path_to_url } = Deno.core.ops; + +globalThis.onunhandledrejection = (...args) => { + console.error("unexpected call", args); +}; +globalThis.onrejectionhandled = (...args) => { + console.error("unexpected call", args); +}; + +assertThrows( + () => { + op_import_sync( + op_path_to_url("./integration/import_sync_throw/module.mjs"), + ); + }, + Error, + "this is a test", +); diff --git a/testing/integration/import_sync_throw/module.mjs b/testing/integration/import_sync_throw/module.mjs new file mode 100644 index 000000000..b15651360 --- /dev/null +++ b/testing/integration/import_sync_throw/module.mjs @@ -0,0 +1 @@ +throw new Error("this is a test"); diff --git a/testing/lib.rs b/testing/lib.rs index 6673a2113..6e783dd38 100644 --- a/testing/lib.rs +++ b/testing/lib.rs @@ -77,6 +77,7 @@ integration_test!( error_get_script_name_or_source_url, import_sync, import_sync_existing, + import_sync_throw, main_module_handler, module_types, pending_unref_op_tla,