Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(callbacks): remove legacy Window invocation layer

ldm026ab1aa3c363
diff --git a/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer_string.rs b/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer_string.rs
index 5f29c14cc..3988267ae 100644
--- a/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer_string.rs
+++ b/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer_string.rs
@@ -9,14 +9,10 @@
//! existing owners.
use crate::{
- host::report_event_callback_exception,
native_bridge::JsContextHost,
util::{context_host_ptr_from_global_bridge, v8_string},
webidl,
- window_webidl_callback::{
- WindowWebIdlCallbackFunction, WindowWebIdlCallbackFunctionOutcome,
- invoke_window_webidl_callback_function,
- },
+ window_webidl_callback::WindowWebIdlCallbackFunction,
};
use moli_webidl_callback::WebIdlCallbackFunction;
@@ -64,39 +60,23 @@ impl DataTransferStringCallbackTask {
scope: &mut v8::PinScope<'_, '_>,
host_ptr: *mut JsContextHost,
) -> DataTransferStringCallbackTaskEffect {
- let callback = self.callback.prepare(scope);
- let relevant_identity = callback.relevant_identity();
+ let Some(callback) = self.callback.prepare_execution(scope, host_ptr, None) else {
+ return DataTransferStringCallbackTaskEffect::CallbackNotInvoked;
+ };
let Some(value) = v8_string(scope, &self.value) else {
return DataTransferStringCallbackTaskEffect::CallbackNotInvoked;
};
let receiver = v8::undefined(scope);
- match invoke_window_webidl_callback_function(
+ if callback.invoke_and_report(
scope,
- host_ptr,
- "FunctionStringCallback",
- "DataTransferItem.getAsString callback threw",
+ "datatransferitem",
"DataTransferItem.getAsString callback",
- &callback,
receiver.into(),
&[value.into()],
) {
- WindowWebIdlCallbackFunctionOutcome::Returned => {
- DataTransferStringCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Threw(report) => {
- report_event_callback_exception(
- scope,
- host_ptr,
- "datatransferitem",
- relevant_identity,
- None,
- &report,
- );
- DataTransferStringCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Retired => {
- DataTransferStringCallbackTaskEffect::CallbackNotInvoked
- }
+ DataTransferStringCallbackTaskEffect::CallbackInvoked
+ } else {
+ DataTransferStringCallbackTaskEffect::CallbackNotInvoked
}
}
}
diff --git a/moli-renderer-v8/src/context_bootstrap/file_api/directory_reader.rs b/moli-renderer-v8/src/context_bootstrap/file_api/directory_reader.rs
index 79e9db692..a7d4fe955 100644
--- a/moli-renderer-v8/src/context_bootstrap/file_api/directory_reader.rs
+++ b/moli-renderer-v8/src/context_bootstrap/file_api/directory_reader.rs
@@ -6,15 +6,11 @@
//! execution, not while the binding merely queues work.
use crate::{
- host::report_event_callback_exception,
native_bridge::JsContextHost,
page_task_queue::{RendererPageFileReadingTaskId, RendererPageFileReadingTaskKind},
util::{context_host_ptr_from_global_bridge, get_private_value, set_private_value},
webidl,
- window_webidl_callback::{
- WindowWebIdlCallbackFunction, WindowWebIdlCallbackFunctionOutcome,
- invoke_window_webidl_callback_function,
- },
+ window_webidl_callback::WindowWebIdlCallbackFunction,
};
use moli_webidl_callback::WebIdlCallbackFunction;
@@ -222,16 +218,19 @@ impl DirectoryReaderCallbackTask {
DirectoryReaderCallback::Success(callback)
| DirectoryReaderCallback::Error(callback) => callback,
};
- let prepared = callback.prepare(scope);
- let relevant_identity = prepared.relevant_identity();
- let host = unsafe { &*host_ptr };
- if !prepared.is_current(host) {
+ let Some(identity) = callback.relevant_identity() else {
+ return DirectoryReaderCallbackTaskEffect::CallbackNotInvoked;
+ };
+ if !unsafe { &*host_ptr }.window_execution_context_identity_is_current(identity) {
return DirectoryReaderCallbackTaskEffect::CallbackNotInvoked;
}
let Some(relevant_context) = callback.relevant_context(scope) else {
return DirectoryReaderCallbackTaskEffect::CallbackNotInvoked;
};
let scope = &mut v8::ContextScope::new(scope, relevant_context);
+ let Some(callback) = callback.prepare_execution(scope, host_ptr, None) else {
+ return DirectoryReaderCallbackTaskEffect::CallbackNotInvoked;
+ };
let argument = match &self.outcome {
DirectoryReaderRequestOutcome::Batch { entries, .. } => {
let array = v8::Array::new(scope, entries.len() as i32);
@@ -252,36 +251,16 @@ impl DirectoryReaderCallbackTask {
DirectoryReaderRequestOutcome::TerminalError(error) => v8::Local::new(scope, error),
};
let receiver = v8::undefined(scope);
- match invoke_window_webidl_callback_function(
+ if callback.invoke_and_report(
scope,
- host_ptr,
- match self.callback {
- DirectoryReaderCallback::Success(_) => "FileSystemEntriesCallback",
- DirectoryReaderCallback::Error(_) => "ErrorCallback",
- },
- "FileSystemDirectoryReader.readEntries callback threw",
+ "filesystemdirectoryreader",
"FileSystemDirectoryReader.readEntries callback",
- &prepared,
receiver.into(),
&[argument],
) {
- WindowWebIdlCallbackFunctionOutcome::Returned => {
- DirectoryReaderCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Threw(report) => {
- report_event_callback_exception(
- scope,
- host_ptr,
- "filesystemdirectoryreader",
- relevant_identity,
- None,
- &report,
- );
- DirectoryReaderCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Retired => {
- DirectoryReaderCallbackTaskEffect::CallbackNotInvoked
- }
+ DirectoryReaderCallbackTaskEffect::CallbackInvoked
+ } else {
+ DirectoryReaderCallbackTaskEffect::CallbackNotInvoked
}
}
}
diff --git a/moli-renderer-v8/src/context_bootstrap/file_api/file_entry_file.rs b/moli-renderer-v8/src/context_bootstrap/file_api/file_entry_file.rs
index 72fde261e..fc9444037 100644
--- a/moli-renderer-v8/src/context_bootstrap/file_api/file_entry_file.rs
+++ b/moli-renderer-v8/src/context_bootstrap/file_api/file_entry_file.rs
@@ -8,14 +8,8 @@
//! the selected Page-task dispatcher owns checkpoint and runtime follow-up.
use crate::{
- host::report_event_callback_exception,
- native_bridge::JsContextHost,
- util::context_host_ptr_from_global_bridge,
- webidl,
- window_webidl_callback::{
- WindowWebIdlCallbackFunction, WindowWebIdlCallbackFunctionOutcome,
- invoke_window_webidl_callback_function,
- },
+ native_bridge::JsContextHost, util::context_host_ptr_from_global_bridge, webidl,
+ window_webidl_callback::WindowWebIdlCallbackFunction,
};
use moli_webidl_callback::WebIdlCallbackFunction;
@@ -66,37 +60,21 @@ impl FileEntryFileCallbackTask {
scope: &mut v8::PinScope<'_, '_>,
host_ptr: *mut JsContextHost,
) -> FileEntryFileCallbackTaskEffect {
- let callback = self.callback.prepare(scope);
- let relevant_identity = callback.relevant_identity();
+ let Some(callback) = self.callback.prepare_execution(scope, host_ptr, None) else {
+ return FileEntryFileCallbackTaskEffect::CallbackNotInvoked;
+ };
let file = v8::Local::new(scope, &self.file);
let receiver = v8::undefined(scope);
- match invoke_window_webidl_callback_function(
+ if callback.invoke_and_report(
scope,
- host_ptr,
- "FileCallback",
- "FileSystemFileEntry.file callback threw",
+ "filesystemfileentry",
"FileSystemFileEntry.file callback",
- &callback,
receiver.into(),
&[file.into()],
) {
- WindowWebIdlCallbackFunctionOutcome::Returned => {
- FileEntryFileCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Threw(report) => {
- report_event_callback_exception(
- scope,
- host_ptr,
- "filesystemfileentry",
- relevant_identity,
- None,
- &report,
- );
- FileEntryFileCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Retired => {
- FileEntryFileCallbackTaskEffect::CallbackNotInvoked
- }
+ FileEntryFileCallbackTaskEffect::CallbackInvoked
+ } else {
+ FileEntryFileCallbackTaskEffect::CallbackNotInvoked
}
}
}
diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_handler_callbacks.rs b/moli-renderer-v8/src/context_bootstrap/navigation_handler_callbacks.rs
index cfdc198b1..e53bedd3a 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigation_handler_callbacks.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigation_handler_callbacks.rs
@@ -20,9 +20,8 @@
use super::*;
use crate::{
util::{context_host_ptr_from_global_bridge, serialize_v8_iter_array, set_private_value},
- window_webidl_callback::{
- PreparedWindowWebIdlCallbackFunctionOutcome, V8TracedWindowWebIdlCallbackFunction,
- },
+ v8_traced_webidl_callback::V8TracedWebIdlCallbackFunction,
+ webidl_callback_execution::{PreparedWebIdlCallbackExecution, WebIdlCallbackExecutionOutcome},
};
use moli_webidl_callback::WebIdlCallbackFunction;
@@ -51,7 +50,7 @@ pub(in crate::context_bootstrap) fn push_navigation_handler<'s>(
slot: &'static str,
callback: WebIdlCallbackFunction,
) -> Result<(), NavigationHandlerResidenceFailure> {
- let callback = V8TracedWindowWebIdlCallbackFunction::new(scope, callback).into_object();
+ let callback = V8TracedWebIdlCallbackFunction::new(scope, callback).into_object();
set_private_value(scope, callback, HANDLER_EVENT_VIEW_SLOT, event.into());
let handlers = crate::context_bootstrap::event_private_value(scope, event, slot)
.and_then(|value| v8::Local::<v8::Array>::try_from(value).ok())
@@ -125,7 +124,7 @@ pub(in crate::context_bootstrap) fn run_navigation_handler_arrays<'s>(
if handler_arrays.is_empty() {
return (None, None);
}
- let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) else {
+ if context_host_ptr_from_global_bridge(scope).is_none() {
return (
Some(navigation_handler_host_error(
scope,
@@ -133,7 +132,7 @@ pub(in crate::context_bootstrap) fn run_navigation_handler_arrays<'s>(
)),
None,
);
- };
+ }
let capacity = handler_arrays
.iter()
.map(|handlers| handlers.length() as usize)
@@ -145,7 +144,7 @@ pub(in crate::context_bootstrap) fn run_navigation_handler_arrays<'s>(
.get_index(scope, index)
.and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
.expect("a NavigateEvent handler array must contain callback carriers");
- match invoke_navigation_handler(scope, host_ptr, event, carrier, arguments) {
+ match invoke_navigation_handler(scope, event, carrier, arguments) {
Ok(promise) => promises.push(promise),
Err(error) => return (Some(error), None),
}
@@ -177,7 +176,6 @@ enum NavigationHandlerInvocationFailure {
fn invoke_navigation_handler<'s>(
scope: &mut v8::PinScope<'s, '_>,
- host_ptr: *mut crate::native_bridge::JsContextHost,
event: v8::Local<'s, v8::Object>,
carrier: v8::Local<'s, v8::Object>,
arguments: &[v8::Local<'s, v8::Value>],
@@ -190,11 +188,11 @@ fn invoke_navigation_handler<'s>(
super::events::navigation_precommit_controller_for_event(scope, *argument, view)
})
.collect();
- let callback = V8TracedWindowWebIdlCallbackFunction::from_object(carrier)
- .prepare(scope, unsafe { &*host_ptr });
- match callback.invoke(
+ let Some(callback) = PreparedWebIdlCallbackExecution::from_traced(scope, carrier) else {
+ return retired_navigation_handler_result(scope);
+ };
+ match callback.invoke_with(
scope,
- unsafe { &*host_ptr },
view.into(),
&arguments,
|scope, callback, receiver, arguments| {
@@ -243,10 +241,10 @@ fn invoke_navigation_handler<'s>(
}
},
) {
- PreparedWindowWebIdlCallbackFunctionOutcome::Returned(promise) => {
+ WebIdlCallbackExecutionOutcome::Returned(promise) => {
Ok(v8::Local::new(scope, &promise).into())
}
- PreparedWindowWebIdlCallbackFunctionOutcome::Failed(failure) => {
+ WebIdlCallbackExecutionOutcome::Failed(failure) => {
let message = match failure {
NavigationHandlerInvocationFailure::PromiseAllocation => {
"Navigation handler Promise allocation failed"
@@ -257,17 +255,21 @@ fn invoke_navigation_handler<'s>(
};
Err(navigation_handler_host_error(scope, message))
}
- PreparedWindowWebIdlCallbackFunctionOutcome::Retired => {
- resolved_navigation_handler_promise(scope).ok_or_else(|| {
- navigation_handler_host_error(
- scope,
- "Navigation handler retirement Promise allocation failed",
- )
- })
- }
+ WebIdlCallbackExecutionOutcome::Unavailable => retired_navigation_handler_result(scope),
}
}
+fn retired_navigation_handler_result<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+) -> Result<v8::Local<'s, v8::Value>, v8::Local<'s, v8::Value>> {
+ resolved_navigation_handler_promise(scope).ok_or_else(|| {
+ navigation_handler_host_error(
+ scope,
+ "Navigation handler retirement Promise allocation failed",
+ )
+ })
+}
+
fn resolved_navigation_handler_promise<'s>(
scope: &mut v8::PinScope<'s, '_>,
) -> Option<v8::Local<'s, v8::Value>> {
diff --git a/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs b/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs
index f497d719b..2944f2705 100644
--- a/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs
+++ b/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs
@@ -3,9 +3,8 @@ use super::*;
use crate::web_api_interfaces;
use crate::{
util::{get_private_value, set_private_value},
- window_webidl_callback::{
- PreparedWindowWebIdlCallbackFunction, PreparedWindowWebIdlCallbackFunctionOutcome,
- },
+ webidl_callback_execution::WebIdlCallbackExecutionOutcome,
+ window_webidl_callback::WindowWebIdlCallbackFunction,
};
use moli_webapi_declare::WebApiObject;
@@ -278,7 +277,7 @@ pub(crate) fn run_view_transition_update_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
host_ptr: *mut crate::native_bridge::JsContextHost,
transition: v8::Local<'s, v8::Object>,
- callback: Option<&PreparedWindowWebIdlCallbackFunction>,
+ callback: Option<&WindowWebIdlCallbackFunction>,
) {
if callback_state(scope, transition).as_deref() != Some(CALLBACK_PENDING) {
return;
@@ -291,11 +290,17 @@ pub(crate) fn run_view_transition_update_callback<'s>(
);
let installed_reactions = if let Some(callback) = callback {
+ // An absent callback succeeds with undefined; a supplied callback
+ // whose Realm has retired must instead reject the transition.
+ let Some(callback) = callback.prepare_execution(scope, host_ptr, None) else {
+ let error = new_dom_exception_value(scope, "Transition was skipped", "AbortError");
+ reject_view_transition(scope, transition, error);
+ return;
+ };
let receiver = v8::undefined(scope).into();
let arguments = [];
- match callback.invoke(
+ match callback.invoke_with(
scope,
- unsafe { &*host_ptr },
receiver,
&arguments,
|scope, callback, receiver, arguments| {
@@ -313,8 +318,8 @@ pub(crate) fn run_view_transition_update_callback<'s>(
.ok_or(ViewTransitionUpdateInvocationFailure::PromiseNormalizationFailed)
},
) {
- PreparedWindowWebIdlCallbackFunctionOutcome::Returned(()) => true,
- PreparedWindowWebIdlCallbackFunctionOutcome::Failed(
+ WebIdlCallbackExecutionOutcome::Returned(()) => true,
+ WebIdlCallbackExecutionOutcome::Failed(
ViewTransitionUpdateInvocationFailure::CallbackThrew(error),
) => {
let error = error
@@ -324,10 +329,10 @@ pub(crate) fn run_view_transition_update_callback<'s>(
reject_view_transition(scope, transition, error);
return;
}
- PreparedWindowWebIdlCallbackFunctionOutcome::Failed(
+ WebIdlCallbackExecutionOutcome::Failed(
ViewTransitionUpdateInvocationFailure::PromiseNormalizationFailed,
) => false,
- PreparedWindowWebIdlCallbackFunctionOutcome::Retired => {
+ WebIdlCallbackExecutionOutcome::Unavailable => {
let error = new_dom_exception_value(scope, "Transition was skipped", "AbortError");
reject_view_transition(scope, transition, error);
return;
diff --git a/moli-renderer-v8/src/context_bootstrap/web_mcp/execution.rs b/moli-renderer-v8/src/context_bootstrap/web_mcp/execution.rs
index 13ed86459..d1ec87d80 100644
--- a/moli-renderer-v8/src/context_bootstrap/web_mcp/execution.rs
+++ b/moli-renderer-v8/src/context_bootstrap/web_mcp/execution.rs
@@ -15,8 +15,7 @@ use moli_page_types::{
use crate::{
abort_signal_route::ResolvedAbortSignal,
- window_webidl_callback::PreparedWindowWebIdlCallbackFunction,
- window_webidl_callback::PreparedWindowWebIdlCallbackFunctionOutcome,
+ webidl_callback_execution::{PreparedWebIdlCallbackExecution, WebIdlCallbackExecutionOutcome},
};
fn next_invocation_id() -> u64 {
@@ -251,9 +250,9 @@ fn start_callback<'s>(
.and_then(|entry| {
let tool = entry.tools.get(&pending.name)?;
let executor = match &tool.executor {
- ToolExecutor::Callback(callback) => {
- InvocationExecutor::Callback(callback.callback.prepare(scope))
- }
+ ToolExecutor::Callback(callback) => InvocationExecutor::Callback(
+ callback.callback.prepare_execution(scope, host_ptr, None),
+ ),
ToolExecutor::Form {
handle, autosubmit, ..
} => InvocationExecutor::Form(*handle, *autosubmit),
@@ -303,51 +302,55 @@ fn start_callback<'s>(
}
};
let callback_unavailable = "Tool callback is no longer available";
- let result = callback.invoke(
- scope,
- unsafe { &*host_ptr },
- v8::undefined(scope).into(),
- &[],
- |scope, callback, receiver, _arguments| {
- let try_catch = std::pin::pin!(v8::TryCatch::new(scope));
- let mut scope = try_catch.init();
- // Invoke enters the callback's relevant realm before allocating
- // input (including nested objects/arrays) and its options object.
- let input = v8::json::parse(&scope, js_string(&scope, &input))
- .filter(|input| input.is_object())
- .ok_or(CallbackInvocationError::InvalidInput)?;
- let options = v8::Object::new(&scope);
- let _ = options.create_data_property(
- &scope,
- js_string(&scope, "signal").into(),
- signal.into(),
- );
- let resolver = v8::PromiseResolver::new(&scope)
- .ok_or(CallbackInvocationError::CallbackUnavailable)?;
- match callback.call(&scope, receiver, &[input, options.into()]) {
- Some(value) => {
- resolver
- .resolve(&scope, value)
- .ok_or(CallbackInvocationError::CallbackUnavailable)?;
- }
- None => {
- let exception = scope
- .exception()
- .unwrap_or_else(|| v8::undefined(&scope).into());
- scope.reset();
- resolver
- .reject(&scope, exception)
- .ok_or(CallbackInvocationError::CallbackUnavailable)?;
- }
- }
- Ok(v8::Global::new(&scope, resolver.get_promise(&scope)))
- },
- );
+ let result =
+ callback
+ .as_ref()
+ .map_or(WebIdlCallbackExecutionOutcome::Unavailable, |callback| {
+ callback.invoke_with(
+ scope,
+ v8::undefined(scope).into(),
+ &[],
+ |scope, callback, receiver, _arguments| {
+ let try_catch = std::pin::pin!(v8::TryCatch::new(scope));
+ let mut scope = try_catch.init();
+ // Invoke enters the callback's relevant realm before allocating
+ // input (including nested objects/arrays) and its options object.
+ let input = v8::json::parse(&scope, js_string(&scope, &input))
+ .filter(|input| input.is_object())
+ .ok_or(CallbackInvocationError::InvalidInput)?;
+ let options = v8::Object::new(&scope);
+ let _ = options.create_data_property(
+ &scope,
+ js_string(&scope, "signal").into(),
+ signal.into(),
+ );
+ let resolver = v8::PromiseResolver::new(&scope)
+ .ok_or(CallbackInvocationError::CallbackUnavailable)?;
+ match callback.call(&scope, receiver, &[input, options.into()]) {
+ Some(value) => {
+ resolver
+ .resolve(&scope, value)
+ .ok_or(CallbackInvocationError::CallbackUnavailable)?;
+ }
+ None => {
+ let exception = scope
+ .exception()
+ .unwrap_or_else(|| v8::undefined(&scope).into());
+ scope.reset();
+ resolver
+ .reject(&scope, exception)
+ .ok_or(CallbackInvocationError::CallbackUnavailable)?;
+ }
+ }
+ Ok(v8::Global::new(&scope, resolver.get_promise(&scope)))
+ },
+ )
+ });
// Chromium activates a live tool even when parsing its input fails. Keep
// that failure distinct from a retired or otherwise unavailable callback,
// and retain the owner before finish_error removes the pending invocation.
let activation_owner = match result {
- PreparedWindowWebIdlCallbackFunctionOutcome::Returned(promise) => {
+ WebIdlCallbackExecutionOutcome::Returned(promise) => {
let promise = v8::Local::new(scope, &promise);
await_response(scope, host_ptr, id, promise);
unsafe { &*host_ptr }
@@ -357,9 +360,7 @@ fn start_callback<'s>(
.get(&id)
.map(|pending| pending.owner)
}
- PreparedWindowWebIdlCallbackFunctionOutcome::Failed(
- CallbackInvocationError::InvalidInput,
- ) => {
+ WebIdlCallbackExecutionOutcome::Failed(CallbackInvocationError::InvalidInput) => {
let owner = unsafe { &*host_ptr }
.native_bridge()
.web_mcp
@@ -369,10 +370,8 @@ fn start_callback<'s>(
finish_error(scope, host_ptr, id, "Invalid tool input");
owner
}
- PreparedWindowWebIdlCallbackFunctionOutcome::Failed(
- CallbackInvocationError::CallbackUnavailable,
- )
- | PreparedWindowWebIdlCallbackFunctionOutcome::Retired => {
+ WebIdlCallbackExecutionOutcome::Failed(CallbackInvocationError::CallbackUnavailable)
+ | WebIdlCallbackExecutionOutcome::Unavailable => {
finish_error(scope, host_ptr, id, callback_unavailable);
None
}
@@ -390,7 +389,7 @@ enum CallbackInvocationError {
}
enum InvocationExecutor {
- Callback(PreparedWindowWebIdlCallbackFunction),
+ Callback(Option<PreparedWebIdlCallbackExecution>),
Form(DomHandle, bool),
}
diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs
index 9e430c461..d4e2d1fdb 100644
--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs
+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator/legacy_storage_quota.rs
@@ -12,15 +12,9 @@ use moli_webapi_declare::WebApiObject;
use moli_webidl_callback::WebIdlCallbackFunction;
use crate::{
- host::report_event_callback_exception,
- native_bridge::JsContextHost,
- page_task_queue::RendererPageMiscPlatformApiTaskKind,
- util::context_host_ptr_from_global_bridge,
- webidl,
- window_webidl_callback::{
- WindowWebIdlCallbackFunction, WindowWebIdlCallbackFunctionOutcome,
- invoke_window_webidl_callback_function,
- },
+ native_bridge::JsContextHost, page_task_queue::RendererPageMiscPlatformApiTaskKind,
+ util::context_host_ptr_from_global_bridge, webidl,
+ window_webidl_callback::WindowWebIdlCallbackFunction,
};
use super::super::super::navigation_window::navigation_document_has_opaque_origin;
@@ -185,16 +179,19 @@ impl LegacyStorageQuotaCallbackTask {
scope: &mut v8::PinScope<'_, '_>,
host_ptr: *mut JsContextHost,
) -> LegacyStorageQuotaCallbackTaskEffect {
- let prepared = self.callback.prepare(scope);
- let relevant_identity = prepared.relevant_identity();
- let host = unsafe { &*host_ptr };
- if !prepared.is_current(host) {
+ let Some(identity) = self.callback.relevant_identity() else {
+ return LegacyStorageQuotaCallbackTaskEffect::CallbackNotInvoked;
+ };
+ if !unsafe { &*host_ptr }.window_execution_context_identity_is_current(identity) {
return LegacyStorageQuotaCallbackTaskEffect::CallbackNotInvoked;
}
let Some(relevant_context) = self.callback.relevant_context(scope) else {
return LegacyStorageQuotaCallbackTaskEffect::CallbackNotInvoked;
};
let scope = &mut v8::ContextScope::new(scope, relevant_context);
+ let Some(callback) = self.callback.prepare_execution(scope, host_ptr, None) else {
+ return LegacyStorageQuotaCallbackTaskEffect::CallbackNotInvoked;
+ };
let arguments: Vec<v8::Local<'_, v8::Value>> = match self.outcome {
LegacyStorageQuotaCallbackOutcome::UsageAndQuota { usage, quota } => vec![
v8::Number::new(scope, usage).into(),
@@ -210,37 +207,16 @@ impl LegacyStorageQuotaCallbackTask {
}
};
let receiver = v8::undefined(scope);
- match invoke_window_webidl_callback_function(
+ if callback.invoke_and_report(
scope,
- host_ptr,
- match self.outcome {
- LegacyStorageQuotaCallbackOutcome::UsageAndQuota { .. } => "StorageUsageCallback",
- LegacyStorageQuotaCallbackOutcome::GrantedQuota { .. } => "StorageQuotaCallback",
- LegacyStorageQuotaCallbackOutcome::Error { .. } => "StorageErrorCallback",
- },
- "deprecated storage quota callback threw",
+ "deprecatedstoragequota",
"deprecated storage quota callback",
- &prepared,
receiver.into(),
&arguments,
) {
- WindowWebIdlCallbackFunctionOutcome::Returned => {
- LegacyStorageQuotaCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Threw(report) => {
- report_event_callback_exception(
- scope,
- host_ptr,
- "deprecatedstoragequota",
- relevant_identity,
- None,
- &report,
- );
- LegacyStorageQuotaCallbackTaskEffect::CallbackInvoked
- }
- WindowWebIdlCallbackFunctionOutcome::Retired => {
- LegacyStorageQuotaCallbackTaskEffect::CallbackNotInvoked
- }
+ LegacyStorageQuotaCallbackTaskEffect::CallbackInvoked
+ } else {
+ LegacyStorageQuotaCallbackTaskEffect::CallbackNotInvoked
}
}
}
diff --git a/moli-renderer-v8/src/host/timers.rs b/moli-renderer-v8/src/host/timers.rs
index 47e423c03..7fa875ef2 100644
--- a/moli-renderer-v8/src/host/timers.rs
+++ b/moli-renderer-v8/src/host/timers.rs
@@ -1187,11 +1187,11 @@ fn run_window_timer_callback(
)));
}
match result {
- crate::window_webidl_callback::WindowWebIdlCallbackFunctionOutcome::Returned
- | crate::window_webidl_callback::WindowWebIdlCallbackFunctionOutcome::Retired => {
+ crate::webidl_callback_execution::WebIdlCallbackExecutionOutcome::Returned(_)
+ | crate::webidl_callback_execution::WebIdlCallbackExecutionOutcome::Unavailable => {
Ok(HostTimeoutRunResult::Consumed)
}
- crate::window_webidl_callback::WindowWebIdlCallbackFunctionOutcome::Threw(
+ crate::webidl_callback_execution::WebIdlCallbackExecutionOutcome::Failed(
report,
) => {
let message = report.formatted_error("callback", "Window Web IDL callback");
diff --git a/moli-renderer-v8/src/host/window_callbacks.rs b/moli-renderer-v8/src/host/window_callbacks.rs
index 6d256597a..a101d2f06 100644
--- a/moli-renderer-v8/src/host/window_callbacks.rs
+++ b/moli-renderer-v8/src/host/window_callbacks.rs
@@ -9,11 +9,10 @@
use moli_webidl_callback::WebIdlCallbackFunction;
use crate::{
+ exception_reporting::V8ExceptionReport,
native_bridge::{JsContextHost, RuntimeObservableContextToken, WindowExecutionContextIdentity},
- window_webidl_callback::{
- WindowWebIdlCallbackFunction, WindowWebIdlCallbackFunctionOutcome,
- invoke_window_webidl_callback_function,
- },
+ webidl_callback_execution::WebIdlCallbackExecutionOutcome,
+ window_webidl_callback::WindowWebIdlCallbackFunction,
};
/// API-specific body data for one Window Web IDL callback scheduled on the
@@ -101,8 +100,10 @@ impl ScheduledWindowWebIdlCallback {
scope: &mut v8::PinScope<'s, '_>,
host_ptr: *mut JsContextHost,
extra_args: &[v8::Global<v8::Value>],
- ) -> WindowWebIdlCallbackFunctionOutcome {
- let prepared = self.callback.prepare(scope);
+ ) -> WebIdlCallbackExecutionOutcome<v8::Global<v8::Value>, Box<V8ExceptionReport>> {
+ let Some(prepared) = self.callback.prepare_execution(scope, host_ptr, None) else {
+ return WebIdlCallbackExecutionOutcome::Unavailable;
+ };
let mut arguments = Vec::new();
let receiver = match self.kind {
WindowWebIdlCallbackTaskKind::Timer => {
@@ -126,7 +127,7 @@ impl ScheduledWindowWebIdlCallback {
let Some(deadline) =
crate::window_host::build_window_idle_deadline(scope, did_timeout)
else {
- return WindowWebIdlCallbackFunctionOutcome::Retired;
+ return WebIdlCallbackExecutionOutcome::Unavailable;
};
arguments.push(deadline.into());
v8::undefined(scope).into()
@@ -161,13 +162,11 @@ impl ScheduledWindowWebIdlCallback {
"Geolocation callback",
),
};
- invoke_window_webidl_callback_function(
+ prepared.invoke_with_report(
scope,
- host_ptr,
callback_kind,
log_label,
callback_name,
- &prepared,
receiver,
&arguments,
)
diff --git a/moli-renderer-v8/src/native_bridge/context_host/view_transition_updates.rs b/moli-renderer-v8/src/native_bridge/context_host/view_transition_updates.rs
index e148630e5..d21d782ab 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/view_transition_updates.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/view_transition_updates.rs
@@ -94,15 +94,11 @@ impl JsContextHost {
let dispatch_scope = target.dispatch_scope();
let previous_scope = dispatch_scope.enter(scope);
let transition = v8::Local::new(scope, &pending.transition);
- let callback = pending
- .callback
- .as_ref()
- .map(|callback| callback.prepare(scope));
run_view_transition_update_callback(
scope,
self as *mut JsContextHost,
transition,
- callback.as_ref(),
+ pending.callback.as_ref(),
);
dispatch_scope.restore(scope, previous_scope);
true
diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/view_transition.rs b/moli-renderer-v8/src/runtime/page_vm/tests/view_transition.rs
index 5e1a64abe..411a46e59 100644
--- a/moli-renderer-v8/src/runtime/page_vm/tests/view_transition.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/tests/view_transition.rs
@@ -1040,3 +1040,96 @@ __waitingViewTransition.finished.then(
.await
.expect("view-transition promise semantics test should run");
}
+
+#[tokio::test(flavor = "current_thread")]
+async fn view_transition_distinguishes_absent_and_already_retired_callbacks() {
+ run_page_vm_async_test(async move {
+ let loader = crate::network::ResourceRequestClient::new(&FetchConfig::default())
+ .expect("resource request client");
+ let document_url =
+ Url::parse("https://example.com/view-transition-callback-availability").unwrap();
+ let (mut page_vm, _resource_source, _owner_wake_rx) =
+ page_vm_with_bound_task_sources_and_owner_wake(&loader, document_url);
+ page_vm.vm_mut().eval(
+ r#"
+globalThis.__callbackAvailabilityEvents = [];
+globalThis.__recordTransition = transition => {
+ for (const [label, promise] of [
+ ["update", transition.updateCallbackDone],
+ ["ready", transition.ready],
+ ["finished", transition.finished]
+ ]) {
+ promise.then(
+ () => __callbackAvailabilityEvents.push(`${label}:fulfilled`),
+ error => __callbackAvailabilityEvents.push(
+ `${label}:${error.name}:${error instanceof DOMException}`
+ )
+ );
+ }
+};
+__recordTransition(document.startViewTransition());
+"queued"
+"#,
+ )?;
+ assert!(
+ run_next_view_transition_update_task_through_selected_dispatcher_for_test(
+ &mut page_vm,
+ &loader,
+ )
+ .await?
+ );
+ assert_eq!(
+ page_vm
+ .vm_mut()
+ .eval("JSON.stringify(__callbackAvailabilityEvents)")?,
+ r#"["update:fulfilled","ready:fulfilled","finished:fulfilled"]"#,
+ );
+
+ page_vm.vm_mut().eval(
+ r#"
+const retiredCallbackFrame = document.createElement("iframe");
+retiredCallbackFrame.id = "already-retired-transition-callback";
+document.body.appendChild(retiredCallbackFrame);
+"created"
+"#,
+ )?;
+ materialize_child_realm_through_page_turn_for_test(
+ &mut page_vm,
+ "already-retired-transition-callback",
+ )?;
+ page_vm.vm_mut().eval(
+ r#"
+globalThis.__callbackAvailabilityEvents = [];
+globalThis.__retiredAvailabilityCalls = 0;
+const alreadyRetiredCallback = retiredCallbackFrame.contentWindow.Function(
+ "parent.__retiredAvailabilityCalls++;"
+);
+retiredCallbackFrame.remove();
+__recordTransition(document.startViewTransition(alreadyRetiredCallback));
+"queued"
+"#,
+ )?;
+ assert!(
+ run_next_view_transition_update_task_through_selected_dispatcher_for_test(
+ &mut page_vm,
+ &loader,
+ )
+ .await?
+ );
+ assert_eq!(
+ page_vm
+ .vm_mut()
+ .eval("JSON.stringify(__callbackAvailabilityEvents)")?,
+ r#"["update:AbortError:true","ready:AbortError:true","finished:AbortError:true"]"#,
+ );
+ assert_eq!(
+ page_vm.vm_mut().eval(
+ "String(__retiredAvailabilityCalls === 0 && document.activeViewTransition === null)"
+ )?,
+ "true",
+ );
+ Ok::<_, anyhow::Error>(())
+ })
+ .await
+ .expect("callback absence and retirement must retain distinct transition outcomes");
+}
diff --git a/moli-renderer-v8/src/webidl_callback_execution.rs b/moli-renderer-v8/src/webidl_callback_execution.rs
index 4fd33d6cf..65a21b72b 100644
--- a/moli-renderer-v8/src/webidl_callback_execution.rs
+++ b/moli-renderer-v8/src/webidl_callback_execution.rs
@@ -157,25 +157,27 @@ impl PreparedWebIdlCallbackExecution {
}
}
- pub(crate) fn invoke_and_report<'s>(
+ /// Capture a notification callback result without selecting its reporting
+ /// policy. Timer owners, for example, must disarm their watchdog before
+ /// routing a captured exception.
+ pub(crate) fn invoke_with_report<'s>(
&self,
scope: &mut v8::PinScope<'s, '_>,
- event_type: &str,
+ callback_kind: &str,
+ log_label: &str,
callback_name: &str,
receiver: v8::Local<'s, v8::Value>,
arguments: &[v8::Local<'s, v8::Value>],
- ) {
- // No registry borrow survives preparation. Author code may reenter
- // the API or register another callback synchronously.
- let result = self.invoke_with(
+ ) -> WebIdlCallbackExecutionOutcome<v8::Global<v8::Value>, Box<V8ExceptionReport>> {
+ self.invoke_with(
scope,
receiver,
arguments,
|scope, callback, receiver, arguments| {
invoke_callback_with_report(
scope,
- "callback",
- "Web IDL callback threw",
+ callback_kind,
+ log_label,
CallbackExceptionLogLevel::Debug,
callback_name,
callback,
@@ -183,10 +185,36 @@ impl PreparedWebIdlCallbackExecution {
arguments,
)
},
- );
- if let WebIdlCallbackExecutionOutcome::Failed(report) = result {
- self.environment
- .report_exception(scope, &self.binding, event_type, report);
+ )
+ }
+
+ /// Return whether delivery was attempted. A reported exception still
+ /// counts as delivery; an unavailable execution binding does not.
+ pub(crate) fn invoke_and_report<'s>(
+ &self,
+ scope: &mut v8::PinScope<'s, '_>,
+ event_type: &str,
+ callback_name: &str,
+ receiver: v8::Local<'s, v8::Value>,
+ arguments: &[v8::Local<'s, v8::Value>],
+ ) -> bool {
+ // No registry borrow survives preparation. Author code may reenter
+ // the API or register another callback synchronously.
+ match self.invoke_with_report(
+ scope,
+ "callback",
+ "Web IDL callback threw",
+ callback_name,
+ receiver,
+ arguments,
+ ) {
+ WebIdlCallbackExecutionOutcome::Returned(_) => true,
+ WebIdlCallbackExecutionOutcome::Failed(report) => {
+ self.environment
+ .report_exception(scope, &self.binding, event_type, report);
+ true
+ }
+ WebIdlCallbackExecutionOutcome::Unavailable => false,
}
}
}
diff --git a/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs b/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs
index 65bf63947..fb64bae1d 100644
--- a/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs
+++ b/moli-renderer-v8/src/webidl_callback_source_boundary_tests.rs
@@ -74,7 +74,7 @@ const DIRECT_V8_CALL_ALLOWLIST: &[AllowedDirectCallFile] = &[
1,
DirectCallOwner::TypedWebIdlAdapter,
),
- // The typed Window callback adapter checks exact Realm currentness and
+ // The shared callback executor checks exact Realm currentness and
// enters the Web IDL relevant/incumbent contexts before normalizing the
// Promise-returning execute callback. It owns no raw author-function root.
allowed(
diff --git a/moli-renderer-v8/src/window_webidl_callback.rs b/moli-renderer-v8/src/window_webidl_callback.rs
index f51e1f78e..ea6097d19 100644
--- a/moli-renderer-v8/src/window_webidl_callback.rs
+++ b/moli-renderer-v8/src/window_webidl_callback.rs
@@ -1,79 +1,23 @@
-//! Renderer ownership for a Window-realm Web IDL callback function.
+//! Long-lived residence and exact Window identity for Web IDL callbacks.
//!
//! `moli-webidl-callback` owns the callback object and the relevant and
//! incumbent contexts required by Web IDL. The renderer must additionally
//! bind an asynchronous callback to the exact Window execution context that
//! supplied it. Keeping that identity here prevents the renderer-neutral
//! crate from learning about Page, Document, popup, or child-frame lifetime.
+//! Single-invocation snapshots, Realm entry, and execution policy belong to
+//! `webidl_callback_execution`; this module does not invoke JavaScript.
-use moli_webidl_callback::{
- PreparedWebIdlCallbackFunction, WebIdlCallbackFunction, invoke_webidl_callback_function,
-};
+use moli_webidl_callback::WebIdlCallbackFunction;
use crate::{
- exception_reporting::{
- CallbackExceptionLogLevel, V8ExceptionReport, invoke_callback_with_report,
- },
native_bridge::{
JsContextHost, RuntimeObservableContextToken, WindowExecutionContextIdentity,
WindowExecutionContextOwner,
},
- v8_traced_webidl_callback::V8TracedWebIdlCallbackFunction,
webidl_callback_execution::PreparedWebIdlCallbackExecution,
};
-/// A callback-function residence traced through an owning V8 object.
-///
-/// Some Web APIs already keep their pending algorithm state on a JavaScript
-/// object. Rooting the callback independently in Rust would keep
-/// callback-to-owner cycles alive after that object becomes unreachable. This
-/// carrier instead stores the callback and both Web IDL context anchors in
-/// private V8 slots. It acquires a temporary Rust root only while one
-/// invocation is prepared.
-///
-/// Page, Document, task, and Promise ownership deliberately remain outside
-/// this type. The API owner must retain this carrier in its existing
-/// residence and decide what a retired callback Realm means.
-pub(crate) struct V8TracedWindowWebIdlCallbackFunction<'s> {
- callback: V8TracedWebIdlCallbackFunction<'s>,
-}
-
-impl<'s> V8TracedWindowWebIdlCallbackFunction<'s> {
- pub(crate) fn new(scope: &mut v8::PinScope<'s, '_>, callback: WebIdlCallbackFunction) -> Self {
- Self {
- callback: V8TracedWebIdlCallbackFunction::new(scope, callback),
- }
- }
-
- pub(crate) const fn from_object(carrier: v8::Local<'s, v8::Object>) -> Self {
- Self {
- callback: V8TracedWebIdlCallbackFunction::from_object(carrier),
- }
- }
-
- pub(crate) const fn into_object(self) -> v8::Local<'s, v8::Object> {
- self.callback.into_object()
- }
-
- pub(crate) fn prepare(
- &self,
- scope: &mut v8::PinScope<'s, '_>,
- host: &JsContextHost,
- ) -> PreparedWindowWebIdlCallbackFunction {
- let callback = self.callback.prepare(scope);
- let relevant_context = callback.relevant_context(scope);
- let Some(relevant_identity) =
- host.window_execution_context_identity_for_v8_context(scope, relevant_context)
- else {
- return PreparedWindowWebIdlCallbackFunction::Retired;
- };
- PreparedWindowWebIdlCallbackFunction::Live {
- callback,
- relevant_identity,
- }
- }
-}
-
pub(crate) enum WindowWebIdlCallbackFunction {
Live {
callback: WebIdlCallbackFunction,
@@ -100,22 +44,6 @@ impl WindowWebIdlCallbackFunction {
}
}
- pub(crate) fn prepare(
- &self,
- scope: &mut v8::PinScope<'_, '_>,
- ) -> PreparedWindowWebIdlCallbackFunction {
- match self {
- Self::Live {
- callback,
- relevant_identity,
- } => PreparedWindowWebIdlCallbackFunction::Live {
- callback: callback.prepare(scope),
- relevant_identity: *relevant_identity,
- },
- Self::Retired => PreparedWindowWebIdlCallbackFunction::Retired,
- }
- }
-
/// Prepare a single invocation while keeping the captured callback Realm
/// and any API-specific owner identity authoritative.
pub(crate) fn prepare_execution(
@@ -183,120 +111,3 @@ impl WindowWebIdlCallbackFunction {
)
}
}
-
-pub(crate) enum PreparedWindowWebIdlCallbackFunction {
- Live {
- callback: PreparedWebIdlCallbackFunction,
- relevant_identity: WindowExecutionContextIdentity,
- },
- Retired,
-}
-
-/// Result of invoking one prepared callback after exact Window currentness is
-/// checked.
-///
-/// The error type remains owned by the API-specific invocation policy. Most
-/// callback families use `V8ExceptionReport`; Promise-returning callbacks such
-/// as ViewTransition additionally need to distinguish JavaScript throws from
-/// host-side return-value normalization failure.
-pub(crate) enum PreparedWindowWebIdlCallbackFunctionOutcome<R, E> {
- Returned(R),
- Failed(E),
- Retired,
-}
-
-impl PreparedWindowWebIdlCallbackFunction {
- pub(crate) const fn relevant_identity(&self) -> Option<WindowExecutionContextIdentity> {
- match self {
- Self::Live {
- relevant_identity, ..
- } => Some(*relevant_identity),
- Self::Retired => None,
- }
- }
-
- pub(crate) fn is_current(&self, host: &JsContextHost) -> bool {
- matches!(
- self,
- Self::Live {
- relevant_identity,
- ..
- } if host.window_execution_context_identity_is_current(*relevant_identity)
- )
- }
-
- pub(crate) fn invoke<'s, 'a, R, E>(
- &self,
- scope: &mut v8::PinScope<'s, '_>,
- host: &JsContextHost,
- receiver: v8::Local<'s, v8::Value>,
- arguments: &'a [v8::Local<'s, v8::Value>],
- invoke_function: impl FnOnce(
- &mut v8::PinScope<'s, '_>,
- v8::Local<'s, v8::Function>,
- v8::Local<'s, v8::Value>,
- &'a [v8::Local<'s, v8::Value>],
- ) -> Result<R, E>,
- ) -> PreparedWindowWebIdlCallbackFunctionOutcome<R, E> {
- host.debug_assert_not_in_structural_mutation("callback-function invocation");
- if !self.is_current(host) {
- return PreparedWindowWebIdlCallbackFunctionOutcome::Retired;
- }
- let Self::Live { callback, .. } = self else {
- return PreparedWindowWebIdlCallbackFunctionOutcome::Retired;
- };
- match invoke_webidl_callback_function(scope, callback, receiver, arguments, invoke_function)
- {
- Ok(returned) => PreparedWindowWebIdlCallbackFunctionOutcome::Returned(returned),
- Err(error) => PreparedWindowWebIdlCallbackFunctionOutcome::Failed(error),
- }
- }
-}
-
-pub(crate) enum WindowWebIdlCallbackFunctionOutcome {
- Returned,
- Threw(Box<V8ExceptionReport>),
- Retired,
-}
-
-#[allow(clippy::too_many_arguments)]
-pub(crate) fn invoke_window_webidl_callback_function<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- host_ptr: *mut JsContextHost,
- callback_kind: &str,
- log_label: &str,
- callback_name: &str,
- callback: &PreparedWindowWebIdlCallbackFunction,
- receiver: v8::Local<'s, v8::Value>,
- arguments: &[v8::Local<'s, v8::Value>],
-) -> WindowWebIdlCallbackFunctionOutcome {
- let host = unsafe { &*host_ptr };
- match callback.invoke(
- scope,
- host,
- receiver,
- arguments,
- |scope, callback, receiver, arguments| {
- invoke_callback_with_report(
- scope,
- callback_kind,
- log_label,
- CallbackExceptionLogLevel::Debug,
- callback_name,
- callback,
- receiver,
- arguments,
- )
- },
- ) {
- PreparedWindowWebIdlCallbackFunctionOutcome::Returned(_) => {
- WindowWebIdlCallbackFunctionOutcome::Returned
- }
- PreparedWindowWebIdlCallbackFunctionOutcome::Failed(report) => {
- WindowWebIdlCallbackFunctionOutcome::Threw(report)
- }
- PreparedWindowWebIdlCallbackFunctionOutcome::Retired => {
- WindowWebIdlCallbackFunctionOutcome::Retired
- }
- }
-}
diff --git a/moli-renderer-v8/src/worker/timer_callback.rs b/moli-renderer-v8/src/worker/timer_callback.rs
index d306127b7..a35e330f3 100644
--- a/moli-renderer-v8/src/worker/timer_callback.rs
+++ b/moli-renderer-v8/src/worker/timer_callback.rs
@@ -2,16 +2,17 @@
//!
//! A worker timer queue, its active timers, V8 context, and isolate all retire
//! together when that worker run stops. The queue therefore is already the
-//! exact run residence: no cross-run generation lookup is needed here.
+//! exact run residence. The shared executor validates its Context binding
+//! and the existing termination flag immediately before invoking author code.
//!
//! Page-supplied Web IDL callbacks remain distinct from browser-created
//! functions used by AbortSignal, XHR, and compiled string-timer algorithms.
-use moli_webidl_callback::{WebIdlCallbackFunction, invoke_webidl_callback_function};
+use moli_webidl_callback::WebIdlCallbackFunction;
-use crate::exception_reporting::{
- CallbackExceptionLogLevel, V8ExceptionReport, build_event_handler_exception_report,
- invoke_callback_with_report,
+use crate::{
+ exception_reporting::{V8ExceptionReport, build_event_handler_exception_report},
+ webidl_callback_execution::{PreparedWebIdlCallbackExecution, WebIdlCallbackExecutionOutcome},
};
pub(super) struct WorkerTimerCallback {
@@ -126,8 +127,18 @@ impl WorkerTimerCallback {
))
}
}
- WorkerTimerCallbackStorage::WebIdl { callback, kind, .. } => {
- let prepared = callback.prepare(scope);
+ WorkerTimerCallbackStorage::WebIdl {
+ callback,
+ target_context,
+ kind,
+ } => {
+ let callback = callback.prepare(scope);
+ let context = v8::Local::new(scope, target_context);
+ let Some(prepared) =
+ PreparedWebIdlCallbackExecution::worker(scope, callback, context)
+ else {
+ return WorkerTimerCallbackOutcome::Returned;
+ };
let mut arguments = Vec::new();
let receiver = match kind {
WorkerWebIdlCallbackKind::Timer => {
@@ -149,26 +160,21 @@ impl WorkerTimerCallback {
"worker requestAnimationFrame callback"
}
};
- match invoke_webidl_callback_function(
+ match prepared.invoke_with_report(
scope,
- &prepared,
+ "callback",
+ "worker callback threw",
+ callback_name,
receiver,
&arguments,
- |scope, callback, receiver, arguments| {
- invoke_callback_with_report(
- scope,
- "callback",
- "worker callback threw",
- CallbackExceptionLogLevel::Debug,
- callback_name,
- callback,
- receiver,
- arguments,
- )
- },
) {
- Ok(_) => WorkerTimerCallbackOutcome::Returned,
- Err(report) => WorkerTimerCallbackOutcome::Threw(report),
+ WebIdlCallbackExecutionOutcome::Returned(_)
+ | WebIdlCallbackExecutionOutcome::Unavailable => {
+ WorkerTimerCallbackOutcome::Returned
+ }
+ WebIdlCallbackExecutionOutcome::Failed(report) => {
+ WorkerTimerCallbackOutcome::Threw(report)
+ }
}
}
}