fix(events): align lifecycle event initialization

This commit is contained in:
ldm0
2026-10-11 18:04:09 +08:00
parent 4206b58880
commit 5fce94d2d7
3 changed files with 6 additions and 7 deletions
@@ -115,7 +115,9 @@ fn new_before_unload_event<'s>(
pub(crate) fn construct_original_before_unload_event<'s>(
scope: &mut v8::PinScope<'s, '_>,
) -> Option<v8::Local<'s, v8::Object>> {
new_before_unload_event(scope, "beforeunload", true)
let event = new_before_unload_event(scope, "beforeunload", true)?;
mark_event_trusted(scope, event);
Some(event)
}
pub(in crate::context_bootstrap) fn new_uninitialized_before_unload_event<'s>(
@@ -1,6 +1,6 @@
use super::events::{
construct_original_before_unload_event, construct_original_event,
run_navigate_event_precommit_handlers,
construct_original_page_transition_event, run_navigate_event_precommit_handlers,
};
use super::location_history_storage::{
NAVIGATION_ENTRY_EVENT_LISTENERS_SLOT, NAVIGATION_EVENT_LISTENERS_SLOT,
@@ -654,9 +654,7 @@ pub(crate) fn dispatch_pagehide_for_runtime_owner<'s>(
scope: &mut v8::PinScope<'s, '_>,
owner: v8::Local<'s, v8::Object>,
) {
let Some(event) =
super::events::construct_original_page_transition_event(scope, "pagehide", false)
else {
let Some(event) = construct_original_page_transition_event(scope, "pagehide", false) else {
return;
};
dispatch_unload_lifecycle_event_for_runtime_owner(scope, owner, "pagehide", event);
@@ -10,7 +10,7 @@ use crate::{
content_security_policy::{
ContentSecurityPolicyViolationEventFields, send_content_security_policy_reports,
},
context_bootstrap::{construct_original_event, mark_event_trusted},
context_bootstrap::construct_original_event,
document_response_decoder::decode_document_response,
document_runtime::{
DocumentNavigationEmbeddingContext, DocumentPolicyContainer, DomHandle, EventTargetHandle,
@@ -693,7 +693,6 @@ impl JsContextHost {
if object_fallback_required {
self.enter_object_fallback_state(scope, handle);
if let Some(event) = construct_original_event(scope, "error") {
mark_event_trusted(scope, event);
let host_ptr: *mut JsContextHost = self;
let runtime = unsafe { &mut *self.runtime };
let _ = runtime.dispatch_public_event_best_effort(