diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs b/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs index 9998580b26c..0ea4346f46f 100644 --- a/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs +++ b/moli-renderer-v8/src/context_bootstrap/navigation_activation.rs @@ -10,54 +10,105 @@ use super::navigation_window::{runtime_window_owner, window_history_for_holder}; use super::*; use crate::context_bootstrap::navigation_entry::wrappers as entry_wrappers; use crate::native_bridge::{NavigationActivationSeed, NavigationHistorySerializedEntry}; -use crate::util::{get_private_value, set_private_value}; +use crate::util::{get_private_object, get_private_value, set_private_value}; use crate::web_api_interfaces; -use moli_webapi_declare::WebApiObject; +use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject, web_api_object_target}; pub(super) const NAVIGATE_EVENT_PRECOMMIT_TRANSITION_RESOLVER_SLOT: &str = "__lmNavigateEventPrecommitTransitionResolver"; +const ACTIVATION_ENTRY: &str = "__lmNavigationActivationEntry"; +const ACTIVATION_FROM: &str = "__lmNavigationActivationFrom"; +const ACTIVATION_TYPE: &str = "__lmNavigationActivationType"; +const TRANSITION_FROM: &str = "__lmNavigationTransitionFrom"; +const TRANSITION_TO: &str = "__lmNavigationTransitionTo"; +const TRANSITION_TYPE: &str = "__lmNavigationTransitionType"; +const TRANSITION_COMMITTED: &str = "__lmNavigationTransitionCommitted"; +const TRANSITION_FINISHED: &str = "__lmNavigationTransitionFinished"; + #[derive(WebApiObject)] -#[webapi( - interface = web_api_interfaces::NavigationActivation, - own_to_string_tag = "NavigationActivation", - readonly_to_string_tag -)] -struct NavigationActivationObjectDeclaration<'scope> { - #[webapi(data_property)] - entry: v8::Local<'scope, v8::Object>, - - #[webapi(data_property)] - from: v8::Local<'scope, v8::Value>, - - #[webapi(data_property = "navigationType")] - navigation_type: v8::Local<'scope, v8::Value>, +#[webapi(interface = web_api_interfaces::NavigationActivation, require_prototype)] +struct NavigationActivationObjectDeclaration<'s> { + #[webapi(slot = ACTIVATION_ENTRY)] + entry: v8::Local<'s, v8::Object>, + #[webapi(slot = ACTIVATION_FROM)] + from: v8::Local<'s, v8::Value>, + #[webapi(slot = ACTIVATION_TYPE)] + navigation_type: v8::Local<'s, v8::Value>, } +// These are associated platform-object fields, not an author dictionary. +// World views keep their own projected handles and share settlement authority +// only through the canonical transition retained by Navigation. #[derive(WebApiObject)] -#[webapi( - interface = web_api_interfaces::NavigationTransition, - own_to_string_tag = "NavigationTransition", - readonly_to_string_tag -)] -struct NavigationTransitionObjectDeclaration<'scope> { - #[webapi(data_property)] - from: v8::Local<'scope, v8::Object>, - - #[webapi(data_property)] - to: v8::Local<'scope, v8::Value>, - - #[webapi(data_property = "navigationType")] - navigation_type: &'static str, - - #[webapi(data_property)] - committed: v8::Local<'scope, v8::Promise>, - +#[webapi(interface = web_api_interfaces::NavigationTransition, require_prototype)] +pub(super) struct NavigationTransitionObjectDeclaration<'s> { + #[webapi(slot = TRANSITION_FROM)] + pub(super) from: v8::Local<'s, v8::Object>, + #[webapi(slot = TRANSITION_TO)] + pub(super) to: v8::Local<'s, v8::Value>, + #[webapi(slot = TRANSITION_TYPE)] + navigation_type: v8::Local<'s, v8::Value>, + #[webapi(slot = TRANSITION_COMMITTED)] + pub(super) committed: v8::Local<'s, v8::Promise>, #[webapi(slot = NAVIGATION_TRANSITION_COMMITTED_RESOLVER_SLOT)] - committed_resolver: v8::Local<'scope, v8::PromiseResolver>, + committed_resolver: Option>, + #[webapi(slot = TRANSITION_FINISHED)] + pub(super) finished: v8::Local<'s, v8::Promise>, +} - #[webapi(data_property)] - finished: v8::Local<'scope, v8::Promise>, +impl<'s> NavigationTransitionObjectDeclaration<'s> { + pub(super) fn from_private_state( + scope: &mut v8::PinScope<'s, '_>, + object: v8::Local<'s, v8::Object>, + ) -> Option { + Some(Self { + from: get_private_object(scope, object, TRANSITION_FROM)?, + to: get_private_value(scope, object, TRANSITION_TO)?, + navigation_type: get_private_value(scope, object, TRANSITION_TYPE)?, + committed: get_private_value(scope, object, TRANSITION_COMMITTED) + .and_then(|value| v8::Local::::try_from(value).ok())?, + committed_resolver: None, + finished: get_private_value(scope, object, TRANSITION_FINISHED) + .and_then(|value| v8::Local::::try_from(value).ok())?, + }) + } +} + +#[derive(WebApiFunctionTemplate)] +#[webapi(interface = web_api_interfaces::NavigationActivation, enumerable, receiver)] +struct NavigationActivationPrototypeDeclaration { + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, ACTIVATION_FROM))] + from: (), + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, ACTIVATION_ENTRY))] + entry: (), + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, ACTIVATION_TYPE))] + navigation_type: (), +} + +#[derive(WebApiFunctionTemplate)] +#[webapi(interface = web_api_interfaces::NavigationTransition, enumerable, receiver)] +struct NavigationTransitionPrototypeDeclaration { + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, TRANSITION_TYPE))] + navigation_type: (), + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, TRANSITION_FROM))] + from: (), + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, TRANSITION_TO))] + to: (), + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, TRANSITION_COMMITTED), returns_promise)] + committed: (), + #[webapi(accessor_property, getter = associated_field_getter, data = v8str(scope, TRANSITION_FINISHED), returns_promise)] + finished: (), +} + +fn associated_field_getter<'s>( + scope: &mut v8::PinScope<'s, '_>, + args: v8::FunctionCallbackArguments<'s>, + mut rv: v8::ReturnValue<'_, v8::Value>, +) { + let object = web_api_object_target(scope, args.this()).expect("validated navigation receiver"); + let slot = args.data().to_rust_string_lossy(scope); + rv.set(get_private_value(scope, object, &slot).expect("navigation associated field")); } #[derive(WebApiObject)] @@ -81,14 +132,20 @@ pub(super) fn install_navigation_activation_template_bindings<'s>( template: v8::Local<'s, v8::FunctionTemplate>, interface_name: &str, ) { - if interface_name != "NavigationTransition" { - return; + let prototype = template.prototype_template(scope); + match interface_name { + "NavigationActivation" => { + NavigationActivationPrototypeDeclaration::initialize_prototype_template( + scope, prototype, + ) + } + "NavigationTransition" => { + NavigationTransitionPrototypeDeclaration::initialize_prototype_template( + scope, prototype, + ) + } + _ => {} } - template.prototype_template(scope).set_with_attr( - v8str(scope, "committed").into(), - v8::undefined(scope).into(), - v8::PropertyAttribute::DONT_ENUM, - ); } pub(super) fn current_entry_matches_activation_snapshot<'s>( @@ -228,9 +285,9 @@ pub(super) fn install_navigation_transition<'s>( to: to .map(v8::Local::::from) .unwrap_or_else(|| v8::null(scope).into()), - navigation_type, + navigation_type: v8str(scope, navigation_type).into(), committed, - committed_resolver, + committed_resolver: Some(committed_resolver), finished, } .bind(scope) @@ -373,7 +430,7 @@ pub(super) fn navigation_transition_matches_resolver<'s>( resolver: v8::Local<'s, v8::PromiseResolver>, ) -> bool { let current_finished = navigation_transition_object(scope, navigation) - .and_then(|transition| transition.get(scope, v8str(scope, "finished").into())); + .and_then(|transition| get_private_value(scope, transition, TRANSITION_FINISHED)); current_finished .is_some_and(|finished| finished.strict_equals(resolver.get_promise(scope).into())) } @@ -462,6 +519,17 @@ mod tests { for (owner, caller) in [(first, second), (second, first)] { let (navigation, from) = { let scope = &mut v8::ContextScope::new(scope, owner); + let template = NavigationTransitionPrototypeDeclaration::build(scope); + let constructor = template.get_function(scope).unwrap(); + let global = owner.global(scope); + assert_eq!( + global.create_data_property( + scope, + v8str(scope, "NavigationTransition").into(), + constructor.into() + ), + Some(true) + ); (v8::Object::new(scope), v8::Object::new(scope)) }; let scope = &mut v8::ContextScope::new(scope, caller); diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_transition_worlds.rs b/moli-renderer-v8/src/context_bootstrap/navigation_transition_worlds.rs index 438758ad36d..37e14a5025b 100644 --- a/moli-renderer-v8/src/context_bootstrap/navigation_transition_worlds.rs +++ b/moli-renderer-v8/src/context_bootstrap/navigation_transition_worlds.rs @@ -1,23 +1,6 @@ +use super::navigation_activation::NavigationTransitionObjectDeclaration; use super::world_wrappers; use crate::context_bootstrap::navigation_entry::wrappers as entry_wrappers; -use crate::util::v8str; -use crate::web_api_interfaces; -use moli_webapi_declare::WebApiObject; - -#[derive(WebApiObject)] -#[webapi(interface = web_api_interfaces::NavigationTransition, own_to_string_tag = "NavigationTransition", readonly_to_string_tag)] -struct TransitionView<'scope> { - #[webapi(data_property)] - from: v8::Local<'scope, v8::Value>, - #[webapi(data_property)] - to: v8::Local<'scope, v8::Value>, - #[webapi(data_property)] - navigation_type: v8::Local<'scope, v8::Value>, - #[webapi(data_property)] - committed: v8::Local<'scope, v8::Promise>, - #[webapi(data_property)] - finished: v8::Local<'scope, v8::Promise>, -} pub(super) fn transition_in_realm<'s>( scope: &mut v8::PinScope<'s, '_>, @@ -25,34 +8,21 @@ pub(super) fn transition_in_realm<'s>( context: v8::Local<'s, v8::Context>, ) -> Option> { let transition = world_wrappers::owner(scope, transition); + if world_wrappers::belongs_to_world(scope, transition, context) { + return Some(transition); + } if let Some(wrapper) = world_wrappers::get(scope, transition, context) { return Some(wrapper); } let scope = &mut v8::ContextScope::new(scope, context); - let from = transition.get(scope, v8str(scope, "from").into())?; - let from = entry_wrappers::value_in_realm(scope, from, context); - let to = transition.get(scope, v8str(scope, "to").into())?; - let to = if let Ok(to) = v8::Local::::try_from(to) { - super::navigation_events::navigation_destination_for_realm(scope, to)?.into() - } else { - to - }; - let navigation_type = transition.get(scope, v8str(scope, "navigationType").into())?; - let committed = transition.get(scope, v8str(scope, "committed").into())?; - let committed = - promise_in_current_realm(scope, v8::Local::::try_from(committed).ok()?)?; - let finished = transition.get(scope, v8str(scope, "finished").into())?; - let finished = - promise_in_current_realm(scope, v8::Local::::try_from(finished).ok()?)?; - let wrapper = TransitionView { - from, - to, - navigation_type, - committed, - finished, + let mut view = NavigationTransitionObjectDeclaration::from_private_state(scope, transition)?; + view.from = entry_wrappers::in_realm(scope, view.from, context); + if let Ok(to) = v8::Local::::try_from(view.to) { + view.to = super::navigation_events::navigation_destination_for_realm(scope, to)?.into(); } - .bind(scope) - .ok()?; + view.committed = promise_in_current_realm(scope, view.committed)?; + view.finished = promise_in_current_realm(scope, view.finished)?; + let wrapper = view.bind(scope).ok()?; world_wrappers::insert(scope, transition, wrapper); Some(wrapper) } diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/element_navigation.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/element_navigation.rs index 4314703e3f3..130c0d5dae9 100644 --- a/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/element_navigation.rs +++ b/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/element_navigation.rs @@ -2174,3 +2174,37 @@ __hyperlink.click(); r#"[{"label":"anchor-noopener","hasOpener":false,"referrer":"https://example.com/page.html"},{"label":"anchor-opener","hasOpener":true,"referrer":"https://example.com/page.html"},{"label":"area-noreferrer","hasOpener":false,"referrer":""},{"label":"area-opener","hasOpener":true,"referrer":"https://example.com/page.html"}]"# ); } + +#[tokio::test] +async fn navigation_transition_and_activation_use_private_readonly_state() { + let script = include_str!("../../../../../tests/fixtures/navigation-transition-state.js"); + for target in ["top", "child"] { + let server = StaticHttpServer::spawn(1).await; + let base = server.base_url().origin().ascii_serialization(); + let loader = static_http_loader([]); + let mut vm = + new_storage_page_task_executor_test_vm_with_loader(&format!("{base}/parent"), &loader); + vm.eval(&format!( + "{script}\nglobalThis.transitionStateResult='pending';navigationTransitionState({base:?},{target:?}).then(value=>transitionStateResult=value,error=>transitionStateResult=String(error));" + )).unwrap(); + advance_page_task_executor_until_eval_equals( + &mut vm, + &loader, + "String(transitionStateResult !== 'pending')", + "true", + target, + ) + .await; + let result: serde_json::Value = + serde_json::from_str(&vm.eval("JSON.stringify(transitionStateResult)").unwrap()) + .unwrap(); + let checks = result["checks"].as_array().expect("fixture checks"); + let failures = checks + .iter() + .filter(|row| row["pass"] != true) + .collect::>(); + assert!(failures.is_empty(), "{target}: {failures:?}"); + assert_eq!(result["total"], 145); + assert_eq!(server.finish_targets().await.len(), 1); + } +} diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/navigate_event.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/navigate_event.rs index 9a4ea966ef5..3a7ec84cc4f 100644 --- a/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/navigate_event.rs +++ b/moli-renderer-v8/src/script_vm/tests/browser_api/navigation/navigate_event.rs @@ -615,8 +615,8 @@ fn navigation_transition_object_keeps_declared_brand_and_members() { .filter(name => name.startsWith("__lmNavigationTransition")) .join(","), Object.hasOwn(transition, "from"), - Object.getOwnPropertyDescriptor(transition, "from").enumerable, - Object.getOwnPropertyDescriptor(transition, Symbol.toStringTag).writable, + Object.getOwnPropertyDescriptor(NavigationTransition.prototype, "from").enumerable, + Object.getOwnPropertyDescriptor(NavigationTransition.prototype, Symbol.toStringTag).writable, transition.from === from, transition.to !== null && typeof transition.to === "object", transition.navigationType, @@ -634,7 +634,7 @@ fn navigation_transition_object_keeps_declared_brand_and_members() { assert_eq!( result, - "true|[object NavigationTransition]|||true|false|false|true|true|push|true|true" + "true|[object NavigationTransition]|||false|true|false|true|true|push|true|true" ); } @@ -1919,3 +1919,43 @@ async fn location_href_double_intercept_cancels_first_settlement() { "locationInterceptSpoof:false:spoof-location.js:https://example.com/start:null|navigate:https://example.com/start:null|currententrychange:https://example.com/common/blank.html#1:replace|handler:https://example.com/common/blank.html#1:replace|abort:AbortError:https://example.com/common/blank.html#1:replace|navigateerror:AbortError:https://example.com/common/blank.html#1:replace|navigate:https://example.com/common/blank.html#1:null|currententrychange:https://example.com/common/blank.html#2:replace|handler:https://example.com/common/blank.html#2:replace|transition-rejected:AbortError:https://example.com/common/blank.html#2:replace|microtask:https://example.com/common/blank.html#2:replace|handler-timeout:https://example.com/common/blank.html#2:replace|handler-timeout:https://example.com/common/blank.html#2:replace|navigatesuccess:https://example.com/common/blank.html#2:replace|transition-finished:https://example.com/common/blank.html#2:null" ); } + +#[test] +fn isolated_transition_views_ignore_owner_shadows_and_keep_promise_realms() { + let mut vm = new_storage_html_test_vm("https://navigation-private-world.test/"); + vm.eval(r##" + globalThis.nativeReads=0; + navigation.addEventListener('navigate',e=>e.intercept({handler(){return new Promise(resolve=>globalThis.finishTransition=resolve);}}),{once:true}); + globalThis.navigationResult=navigation.navigate('#private'); + globalThis.ownerTransition=navigation.transition; + globalThis.ownerFrom=ownerTransition.from; + globalThis.ownerFinished=ownerTransition.finished; + for(const name of ['from','to','navigationType','committed','finished']) { + Object.defineProperty(ownerTransition,name,{configurable:true,get(){nativeReads++;throw Error('owner public '+name);}}); + } + "##).unwrap(); + let world = vm + .create_isolated_world("native-transition-state", false) + .unwrap(); + vm.exec_in_execution_context(world, r#" + globalThis.transition=navigation.transition; + if(!transition || transition!==navigation.transition || Object.getPrototypeOf(transition)!==NavigationTransition.prototype)throw Error('world identity'); + if(Object.getOwnPropertyNames(transition).length!==0 || Object.hasOwn(transition,Symbol.toStringTag))throw Error('own fields'); + if(!(transition.from instanceof NavigationHistoryEntry) || !(transition.to instanceof NavigationDestination))throw Error('projected platform objects'); + if(!(transition.committed instanceof Promise) || !(transition.finished instanceof Promise))throw Error('promise realm'); + if(transition.navigationType!=='push')throw Error('native type'); + globalThis.worldFinished=transition.finished; + globalThis.worldSettled=false; + worldFinished.then(()=>worldSettled=true); + "#).unwrap(); + vm.eval("finishTransition()").unwrap(); + assert_eq!( + vm.eval("String(navigation.transition===null && nativeReads===0)") + .unwrap(), + "true" + ); + vm.exec_in_execution_context(world, r#" + if(!worldSettled || navigation.transition!==null || transition.finished!==worldFinished)throw Error('world settlement'); + "#).unwrap(); + vm.destroy_isolated_world_context(world); +} diff --git a/moli-renderer-v8/tests/fixtures/navigation-transition-state.js b/moli-renderer-v8/tests/fixtures/navigation-transition-state.js new file mode 100644 index 00000000000..7a610e4aaf2 --- /dev/null +++ b/moli-renderer-v8/tests/fixtures/navigation-transition-state.js @@ -0,0 +1,109 @@ +async function navigationTransitionState(base, targetKind) { + const checks = []; + const check = (name, run) => { + try { checks.push({name, pass: !!run()}); } + catch (error) { checks.push({name, pass: false, error: error.name}); } + }; + const tick = () => new Promise(resolve => setTimeout(resolve, 0)); + const frame = document.createElement('iframe'); + frame.src = base + '/common/blank.html'; + await new Promise(resolve => { frame.onload = resolve; document.body.appendChild(frame); }); + await tick(); + const win = targetKind === 'child' ? frame.contentWindow : window; + const other = targetKind === 'child' ? window : frame.contentWindow; + const nav = win.navigation; + const activation = frame.contentWindow.navigation.activation; + const activationOwner = frame.contentWindow; + check('network navigation creates an activation', () => activation !== null); + let release; + const pending = new win.Promise(resolve => { release = resolve; }); + let destination; + nav.addEventListener('navigate', event => { + destination = event.destination; + event.intercept({handler: () => pending}); + }, {once: true}); + const from = nav.currentEntry; + const result = nav.navigate('#native-transition-state', {history: 'push'}); + const transition = nav.transition; + check('navigation exposes its current transition', () => transition !== null && transition === nav.transition); + check('transition keeps source and destination identities', () => transition.from === from && transition.to === destination); + const original = {}; + for (const name of ['from','to','navigationType','committed','finished']) original[name] = transition[name]; + check('transition promises use the Navigation realm', () => original.committed instanceof win.Promise && original.finished instanceof win.Promise); + check('transition finished differs from the navigate result promise', () => original.finished !== result.finished); + const rows = [ + ['NavigationTransition',transition,win,other,['navigationType','from','to','committed','finished']], + ['NavigationActivation',activation,activationOwner,window,['from','entry','navigationType']] + ]; + for (const [className, object, owner, foreign, names] of rows) { + const Constructor = owner[className], proto = Constructor.prototype; + check(className+' prototype attributes follow IDL order',()=>Object.keys(proto).filter(name=>names.includes(name)).join(',')===names.join(',')); + const isError = (run, ErrorCtor) => {try {run();return false;}catch(error){return error instanceof ErrorCtor;}}; + const rejectedGetter = async (getter, value, realm) => { + if(typeof getter!=='function')return false; + let promise; + try {promise=getter.call(value);}catch(error){return false;} + if(!(promise instanceof realm.Promise))return false; + return await promise.then(()=>false,error=>error instanceof realm.TypeError); + }; + check(className+' has the owner prototype and tag', () => Object.getPrototypeOf(object)===proto && Object.prototype.toString.call(object)==='[object '+className+']'); + check(className+' has no own IDL fields or tag', () => !Object.hasOwn(object,Symbol.toStringTag) && Object.getOwnPropertyNames(object).length===0); + check(className+' prototype has the standard tag descriptor', () => {const d=Object.getOwnPropertyDescriptor(proto,Symbol.toStringTag);return d.value===className && !d.writable && !d.enumerable && d.configurable;}); + check(className+' is an illegal constructor', () => isError(()=>new Constructor(),owner.TypeError)); + for (const name of names) { + const label=className+'.'+name, d=Object.getOwnPropertyDescriptor(proto,name); + const getter=d?.get, saved=object?.[name]; + check(label+' is a readonly prototype accessor',()=>typeof getter==='function' && d.set===undefined && d.enumerable && d.configurable && getter.name==='get '+name && getter.length===0 && !Object.hasOwn(object,name)); + const accepted=Reflect.set(object,name,null); + if(accepted)object[name]=saved; + check(label+' rejects assignment',()=>!accepted && object[name]===saved); + const strict=isError(()=>{'use strict';object[name]=null;},TypeError); + if(!strict)object[name]=saved; + check(label+' rejects strict assignment',()=>strict); + const revoked=Proxy.revocable(object,{});revoked.revoke();let traps=0; + const proxy=new Proxy(object,{get(){traps++;throw 1;},getPrototypeOf(){traps++;throw 2;}}); + const invalid=[{},Object.create(proto),Object.create(object),proxy,revoked.proxy,null,undefined,1]; + const promiseAttribute=className==='NavigationTransition' && ['committed','finished'].includes(name); + for(let i=0;igetter.call(invalid[i]),owner.TypeError); + check(label+' rejects receiver '+i,()=>rejected); + } + check(label+' brand check avoids author traps',()=>traps===0); + check(label+' getter returns its associated value',()=>typeof getter==='function' && getter.call(object)===saved); + const foreignGetter=Object.getOwnPropertyDescriptor(foreign[className].prototype,name)?.get; + check(label+' genuine cross-realm receiver keeps identity',()=>typeof foreignGetter==='function' && foreignGetter.call(object)===saved); + const foreignRejection=promiseAttribute ? await rejectedGetter(foreignGetter,proxy,foreign) : typeof foreignGetter==='function' && isError(()=>foreignGetter.call(proxy),foreign.TypeError); + check(label+' errors belong to the borrowed getter realm',()=>foreignRejection); + } + } + let publicReads=0; + const descriptors={}; + for(const name of ['from','to','navigationType','committed','finished']) { + descriptors[name]=Object.getOwnPropertyDescriptor(transition,name); + Object.defineProperty(transition,name,{configurable:true,get(){publicReads++;return original[name];}}); + const getter=Object.getOwnPropertyDescriptor(win.NavigationTransition.prototype,name)?.get; + check('native '+name+' getter ignores own shadow',()=>typeof getter==='function' && getter.call(transition)===original[name]); + } + release(); + await Promise.all([result.finished,original.finished]); + check('settlement clears transition without reading author fields',()=>nav.transition===null && publicReads===0); + for(const name of Object.keys(descriptors)) { + if(descriptors[name])Object.defineProperty(transition,name,descriptors[name]); + else delete transition[name]; + } + check('retained transition preserves settled promises',()=>transition.finished===original.finished && transition.committed===original.committed); + check('same-document navigation preserves activation',()=>activationOwner.navigation.activation===activation); + const prior=Object.getOwnPropertyDescriptor(win,'NavigationTransition');let constructorReads=0; + Object.defineProperty(win,'NavigationTransition',{configurable:true,get(){constructorReads++;throw new Error('public constructor');}}); + let second; + nav.addEventListener('navigate',event=>event.intercept({handler(){second=nav.transition;Object.freeze(second);}}),{once:true}); + try { + await nav.navigate('#native-transition-frozen',{history:'push'}).finished; + check('factory uses intrinsic prototype after global tampering',()=>Object.getPrototypeOf(second)===Object.getPrototypeOf(transition) && constructorReads===0); + check('frozen transition still settles and clears',()=>Object.isFrozen(second) && nav.transition===null && second.finished!==original.finished); + } finally { + if(prior)Object.defineProperty(win,'NavigationTransition',prior);else delete win.NavigationTransition; + frame.remove(); + } + return {checks,passed:checks.filter(row=>row.pass).length,total:checks.length}; +}