Truly independent web browser
LibJS+LibWeb: Keep WindowProxy and Location out of cross-realm caches
Tim Ledbetter4235b2e5758f
diff --git a/Libraries/LibJS/HostClassBuilder.h b/Libraries/LibJS/HostClassBuilder.hindex d93a2b8ecb6..1827951c76a 100644--- a/Libraries/LibJS/HostClassBuilder.h+++ b/Libraries/LibJS/HostClassBuilder.h@@ -567,6 +567,7 @@ consteval JSHostClass make_host_class(u8 kind, StringView name, JSHostClass consconstexpr u32 host_object_flags = JS_HOST_CLASS_IMMUTABLE_PROTOTYPE| JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE| JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE+ | JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS| JS_HOST_CLASS_NOT_ELIGIBLE_FOR_OWN_PROPERTY_ENUMERATION_FAST_PATH;u32 allowed_flags = JS_HOST_CLASS_SHARES_ALLOCATOR_WITH_PARENT;diff --git a/Libraries/LibJS/HostObjectABI.h b/Libraries/LibJS/HostObjectABI.hindex 9632093c1a0..2fc875b1550 100644--- a/Libraries/LibJS/HostObjectABI.h+++ b/Libraries/LibJS/HostObjectABI.h@@ -140,6 +140,10 @@ enum {// answer for keys missing from its shape must set the first flag, or the second if they only answer for array// indices, and one whose hooks can start shadowing inherited properties must have that hook return false.//+ // A class whose hooks answer differently depending on the realm that asks must set+ // JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS, which keeps its objects out of the caches that every realm shares. Its+ // hooks must also give no cacheable metadata to lookups that reach its objects through a prototype chain.+ //// Enumeration (for-in, Object.keys, Object.assign, object spread, JSON.stringify) has fast paths that read keys,// attributes and values straight from the shape and storage. The engine never takes them for an object whose class// has a get_prototype_of, get_own_property, has_property, get or own_property_keys hook, nor for one whose class sets@@ -148,6 +152,7 @@ enum {JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE = 1 << 6,JS_HOST_CLASS_NOT_ELIGIBLE_FOR_OWN_PROPERTY_ENUMERATION_FAST_PATH = 1 << 7,JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE = 1 << 10,+ JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS = 1 << 11,// Only for JS_HOST_CLASS_FUNCTION, which must then have a construct hook.JS_HOST_CLASS_HAS_CONSTRUCTOR = 1 << 8,diff --git a/Libraries/LibJS/Rust/generate/layout_header.rs b/Libraries/LibJS/Rust/generate/layout_header.rsindex 1bed8d1dfbd..8bca29b6a57 100644--- a/Libraries/LibJS/Rust/generate/layout_header.rs+++ b/Libraries/LibJS/Rust/generate/layout_header.rs@@ -495,6 +495,7 @@ pub fn generate() -> LayoutHeader {JS_HOST_CLASS_HAS_CONSTRUCTOR,JS_HOST_CLASS_SHARES_ALLOCATOR_WITH_PARENT,JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE,+ JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS,JS_RESOLVED_BINDING_BINDING_NAME,JS_RESOLVED_BINDING_NAMESPACE,JS_RESOLVED_BINDING_AMBIGUOUS,diff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rsindex 75e67f36bed..71c759a4237 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs@@ -830,6 +830,10 @@ impl StaticPropertyLookupCaches {&self.caches[site as usize]}+ pub fn contains(&self, cache: &PropertyLookupCache) -> bool {+ self.caches.as_ptr_range().contains(&core::ptr::from_ref(cache))+ }+pub fn remove_dead_entries(&self, sweep: &Sweep<'_>) {for cache in &self.caches {cache.remove_dead_entries(sweep);diff --git a/Libraries/LibJS/Rust/src/bytecode/property_access.rs b/Libraries/LibJS/Rust/src/bytecode/property_access.rsindex e29b8c7e5bd..ea1dc1a4465 100644--- a/Libraries/LibJS/Rust/src/bytecode/property_access.rs+++ b/Libraries/LibJS/Rust/src/bytecode/property_access.rs@@ -90,7 +90,7 @@ pub fn get_by_value_with_keyed_cache(property_key: &PropertyKey,site_cache: Option<(&PropertyLookupCache, u64)>,) -> ThrowCompletionOr<Value> {- if !property_key.is_string() {+ if !property_key.is_string() || !base_object.is_cacheable_across_realms() {return base_object.internal_get(vm, property_key, this_value, None, PropertyLookupPhase::OwnProperty);}@@ -384,6 +384,9 @@ pub fn get_with_property_lookup_cache(if let Some(value) = cached_property_slot(base_obj, cache, cache_key) {return get_cached_property_value(vm, value, this_value);}+ if vm.is_static_property_lookup_cache(cache) && !base_obj.is_cacheable_across_realms() {+ return base_obj.internal_get(vm, property_name, this_value, None, PropertyLookupPhase::OwnProperty);+ }let shape = base_obj.shape();let prototype_chain_validity = shape.prototype()@@ -609,6 +612,8 @@ pub fn put_by_property_key(}}+ let caches = caches+ .filter(|cache| !vm.is_static_property_lookup_cache(cache) || object.is_cacheable_across_realms());let prototype_chain_validity = object.shape().prototype()diff --git a/Libraries/LibJS/Rust/src/embedding/host/class_table.rs b/Libraries/LibJS/Rust/src/embedding/host/class_table.rsindex 004dbcfe36f..9d21e1c083c 100644--- a/Libraries/LibJS/Rust/src/embedding/host/class_table.rs+++ b/Libraries/LibJS/Rust/src/embedding/host/class_table.rs@@ -16,7 +16,8 @@ use crate::layout::host_class::{JS_HOST_ABI_VERSION, JS_HOST_CLASS_ARRAY, JS_HOST_CLASS_FUNCTION, JS_HOST_CLASS_HAS_CONSTRUCTOR,JS_HOST_CLASS_IMMUTABLE_PROTOTYPE, JS_HOST_CLASS_IS_GLOBAL_OBJECT, JS_HOST_CLASS_IS_HTMLDDA,JS_HOST_CLASS_IS_PLATFORM_OBJECT, JS_HOST_CLASS_MAY_INTERFERE_WITH_INDEXED_PROPERTY_ACCESS, JS_HOST_CLASS_MODULE,- JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE, JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE,+ JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS, JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE,+ JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE,JS_HOST_CLASS_NOT_ELIGIBLE_FOR_OWN_PROPERTY_ENUMERATION_FAST_PATH, JS_HOST_CLASS_OBJECT,JS_HOST_CLASS_REQUIRES_SLOW_ADD_OWN_PROPERTY, JS_HOST_CLASS_SHARES_ALLOCATOR_WITH_PARENT,JS_PROPERTY_LOOKUP_PHASE_OWN_PROPERTY, JS_PROPERTY_LOOKUP_PHASE_PROTOTYPE_CHAIN, JSCompletion, JSGetCacheMetadata,@@ -37,6 +38,7 @@ const FLAGS_COPIED_INTO_OBJECTS: u32 = JS_HOST_CLASS_IS_PLATFORM_OBJECTconst FLAGS_OF_HOST_OBJECTS_ONLY: u32 = JS_HOST_CLASS_IMMUTABLE_PROTOTYPE| JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE| JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE+ | JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS| JS_HOST_CLASS_NOT_ELIGIBLE_FOR_OWN_PROPERTY_ENUMERATION_FAST_PATH;static HOST_OBJECT_HOOKS_THAT_ARE_ALL_ORDINARY: JSHostObjectHooks = JSHostObjectHooks {diff --git a/Libraries/LibJS/Rust/src/embedding/host/host_object.rs b/Libraries/LibJS/Rust/src/embedding/host/host_object.rsindex ec58f9a952c..b255772ea9d 100644--- a/Libraries/LibJS/Rust/src/embedding/host/host_object.rs+++ b/Libraries/LibJS/Rust/src/embedding/host/host_object.rs@@ -41,8 +41,8 @@ use crate::gc::visitor::{Trace, Visitor};use crate::interpreter::vm::Vm;use crate::layout::cell::Gc;use crate::layout::host_class::{- JS_HOST_CLASS_IMMUTABLE_PROTOTYPE, JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE,- JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE,+ JS_HOST_CLASS_IMMUTABLE_PROTOTYPE, JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS,+ JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE, JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE,JS_HOST_CLASS_NOT_ELIGIBLE_FOR_OWN_PROPERTY_ENUMERATION_FAST_PATH, JS_HOST_CLASS_OBJECT, JS_PD_CONFIGURABLE,JS_PD_ENUMERABLE, JS_PD_HAS_CONFIGURABLE, JS_PD_HAS_ENUMERABLE, JS_PD_HAS_VALUE, JS_PD_HAS_WRITABLE, JS_PD_PRESENT,JS_PD_WRITABLE, JSHostClass, JSHostObjectHooks, JSObject, JSPropertyDescriptor, JSVM, JSValue, JSValueSink,@@ -58,6 +58,7 @@ use crate::runtime::object::{use crate::runtime::property_descriptor::PropertyDescriptor;use crate::runtime::property_key::PropertyKey;use crate::runtime::realm::Realm;+use crate::runtime::shape::Shape;// The class that the class of every host class table of this kind extends. Its own internal methods are ordinary,// and no object has it as its class.@@ -140,6 +141,9 @@ fn host_object_methods(table: &'static JSHostClass) -> ObjectMethods {if hooks.is_cacheable_for_inherited_property.is_some() {methods.is_cacheable_for_inherited_property = is_cacheable_for_inherited_property_through_hook;}+ if table.has_flag(JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS) {+ methods.is_cacheable_across_realms = |_| false;+ }// The fast paths read keys, attributes and values straight from the shape and storage and follow the shape's// prototype, so they would bypass these hooks.let hooks_answer_instead_of_the_shape = hooks.get_prototype_of.is_some()@@ -417,8 +421,8 @@ fn error_data_through_hook(object: &Object) -> Option<&ErrorData> {}impl HostObject {- /// HostObject::create(): a host object of the class `table` describes, with the realm's empty object shape- /// transitioned to `prototype`, holding the embedder's `wrappable` and `host_data` cells.+ /// HostObject::create(): a host object of the class `table` describes, with `prototype` as its [[Prototype]],+ /// holding the embedder's `wrappable` and `host_data` cells.////// # Safety///@@ -433,13 +437,15 @@ impl HostObject {host_data: Option<NonNull<c_void>>,) -> Gc<HostObject> {let (class, allocator) = runtime_class_and_allocator_of_host_class(vm, table, JS_HOST_CLASS_OBJECT);- let base = Object::new_with_realm_and_prototype(- vm,- class,- realm,- prototype,- MayInterfereWithIndexedPropertyAccess::No,- );+ let base = if table.has_flag(JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS) {+ let shape = Shape::create(vm, realm);+ if let Some(prototype) = prototype {+ shape.set_prototype_without_transition(vm, prototype);+ }+ Object::new_with_shape(class, shape, MayInterfereWithIndexedPropertyAccess::No)+ } else {+ Object::new_with_realm_and_prototype(vm, class, realm, prototype, MayInterfereWithIndexedPropertyAccess::No)+ };copy_host_class_flags_into_object(vm, table, &base);let host_object = HostObject {base,@@ -506,8 +512,8 @@ pub unsafe fn set_host_data(object: &Object, host_data: Option<NonNull<c_void>>)// The embedding ABI of host objects, and of what every kind of host object shares-/// HostObject::create(): a host object of `host_class`, a table of kind JS_HOST_CLASS_OBJECT, made from the realm's-/// empty object shape with `prototype_or_null` as its [[Prototype]]. `wrappable_or_null` is the embedder's+/// HostObject::create(): a host object of `host_class`, a table of kind JS_HOST_CLASS_OBJECT, with+/// `prototype_or_null` as its [[Prototype]]. `wrappable_or_null` is the embedder's/// implementation object, which direct getter functions read at JS_HOST_OBJECT_WRAPPABLE_OFFSET, and/// `host_data_or_null` a cell with the rest of its per-object state; the object keeps both alive. Returns an unrooted/// object. Main thread only.diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rsindex 2185e4c6da6..888a18c6c00 100644--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs@@ -488,7 +488,11 @@ pub fn put_by_value();return SlowPathControl::continue_at(pc + op::PutByValue::LENGTH);}- if base.is_object() && property_key.is_string() && put_kind_from_operand(instruction.kind) == PutKind::Normal {+ if base.is_object()+ && base.as_object().is_cacheable_across_realms()+ && property_key.is_string()+ && put_kind_from_operand(instruction.kind) == PutKind::Normal+ {asm_try!(vm,pc,diff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rsindex ed0195f1df1..f2c5af6c263 100644--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs@@ -1405,6 +1405,10 @@ impl Vm {self.static_property_lookup_caches.get(site)}+ pub fn is_static_property_lookup_cache(&self, cache: &PropertyLookupCache) -> bool {+ self.static_property_lookup_caches.contains(cache)+ }+pub fn keyed_property_lookup_cache(&self) -> &KeyedPropertyLookupCache {&self.keyed_property_lookup_cache}diff --git a/Libraries/LibJS/Rust/src/layout/host_class.rs b/Libraries/LibJS/Rust/src/layout/host_class.rsindex 840efd50e19..1a321d8ac05 100644--- a/Libraries/LibJS/Rust/src/layout/host_class.rs+++ b/Libraries/LibJS/Rust/src/layout/host_class.rs@@ -108,6 +108,7 @@ pub const JS_HOST_CLASS_NOT_ELIGIBLE_FOR_OWN_PROPERTY_ENUMERATION_FAST_PATH: u32pub const JS_HOST_CLASS_HAS_CONSTRUCTOR: u32 = 1 << 8;pub const JS_HOST_CLASS_SHARES_ALLOCATOR_WITH_PARENT: u32 = 1 << 9;pub const JS_HOST_CLASS_NOT_CACHEABLE_FOR_INDEXED_PROPERTY_ABSENCE: u32 = 1 << 10;+pub const JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS: u32 = 1 << 11;#[repr(C)]pub struct JSHostObjectHooks {diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rsindex a8dd4a2b6c6..e0e388385dd 100644--- a/Libraries/LibJS/Rust/src/runtime/object.rs+++ b/Libraries/LibJS/Rust/src/runtime/object.rs@@ -271,6 +271,7 @@ pub struct ObjectMethods {/// for a few names whatever their shape holds.pub is_cacheable_for_absence_of: fn(&Object, &Vm, &PropertyKey) -> bool,pub is_cacheable_for_inherited_property: fn(&Object) -> bool,+ pub is_cacheable_across_realms: fn(&Object) -> bool,pub eligible_for_own_property_enumeration_fast_path: fn(&Object) -> bool,/// The step of a built-in iterator whose next method is the original one, which IteratorStep takes without calling/// it; given the iterator and the next method of its iterator record.@@ -312,6 +313,7 @@ pub static ORDINARY_OBJECT_METHODS: ObjectMethods = ObjectMethods {is_cacheable_for_property_absence: |_| true,is_cacheable_for_absence_of: |object, _, _| object.is_cacheable_for_property_absence(),is_cacheable_for_inherited_property: |_| true,+ is_cacheable_across_realms: |_| true,eligible_for_own_property_enumeration_fast_path: |_| true,as_builtin_iterator_if_next_is_not_redefined: |_, _| None,error_data: error_data_of_error,@@ -2055,6 +2057,10 @@ impl Object {(self.methods().is_cacheable_for_inherited_property)(self)}+ pub fn is_cacheable_across_realms(&self) -> bool {+ (self.methods().is_cacheable_across_realms)(self)+ }+pub fn eligible_for_own_property_enumeration_fast_path(&self) -> bool {(self.methods().eligible_for_own_property_enumeration_fast_path)(self)}diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cppindex 3b1e857ebe6..629b5943c05 100644--- a/Libraries/LibWeb/HTML/Location.cpp+++ b/Libraries/LibWeb/HTML/Location.cpp@@ -220,8 +220,10 @@ struct LocationWrapperTraits {static JS::ThrowCompletionOr<JS::Value> get(JS::HostObject const& wrapper, JS::PropertyKey const& property_key, JS::Value receiver, JS::CacheableGetPropertyMetadata* cacheable_metadata, JS::Object::PropertyLookupPhase phase){// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryGet(this, P, Receiver).- if (HTML::is_platform_object_same_origin(location_of(wrapper)))- return wrapper.ordinary_get(property_key, receiver, cacheable_metadata, phase);+ if (HTML::is_platform_object_same_origin(location_of(wrapper))) {+ auto may_cache_lookup = phase == JS::Object::PropertyLookupPhase::OwnProperty;+ return wrapper.ordinary_get(property_key, receiver, may_cache_lookup ? cacheable_metadata : nullptr, phase);+ }// 2. Return ? CrossOriginGet(this, P, Receiver).return HTML::cross_origin_get(wrapper.vm(), wrapper, property_key, receiver);@@ -231,8 +233,10 @@ struct LocationWrapperTraits {static JS::ThrowCompletionOr<bool> set(JS::HostObject& wrapper, JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver, JS::CacheableSetPropertyMetadata* cacheable_metadata, JS::Object::PropertyLookupPhase phase){// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinarySet(this, P, V, Receiver).- if (HTML::is_platform_object_same_origin(location_of(wrapper)))- return wrapper.ordinary_set(property_key, value, receiver, cacheable_metadata, phase);+ if (HTML::is_platform_object_same_origin(location_of(wrapper))) {+ auto may_cache_lookup = phase == JS::Object::PropertyLookupPhase::OwnProperty;+ return wrapper.ordinary_set(property_key, value, receiver, may_cache_lookup ? cacheable_metadata : nullptr, phase);+ }// 2. Return ? CrossOriginSet(this, P, V, Receiver).return HTML::cross_origin_set(wrapper.vm(), wrapper, property_key, value, receiver);diff --git a/Libraries/LibWeb/HTML/WindowProxy.cpp b/Libraries/LibWeb/HTML/WindowProxy.cppindex d1778cf65e2..cadfe8d2a66 100644--- a/Libraries/LibWeb/HTML/WindowProxy.cpp+++ b/Libraries/LibWeb/HTML/WindowProxy.cpp@@ -92,7 +92,8 @@ static constexpr JSHostObjectHooks window_proxy_hooks = JS::make_host_object_hooconstexpr JSHostClass window_proxy_host_class = JS::make_host_class(JS_HOST_CLASS_OBJECT, "WindowProxy"sv, nullptr, &window_proxy_hooks, nullptr,Bindings::platform_object_host_class_flags| JS_HOST_CLASS_MAY_INTERFERE_WITH_INDEXED_PROPERTY_ACCESS- | JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE);+ | JS_HOST_CLASS_NOT_CACHEABLE_FOR_PROPERTY_ABSENCE+ | JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS);// NB: Direct getters read the wrappable slot of any platform object without checking what it holds, so it stays null// here. [[Window]] is not an implementation object that this proxy wraps.diff --git a/Meta/Generators/libweb_bindings/wrappers.py b/Meta/Generators/libweb_bindings/wrappers.pyindex a87b407016d..08993d474ff 100644--- a/Meta/Generators/libweb_bindings/wrappers.py+++ b/Meta/Generators/libweb_bindings/wrappers.py@@ -167,6 +167,7 @@ def wrapper_host_class_flags(context: GenerationContext, interface: Interface) -flags = ["platform_object_host_class_flags"]if is_location:flags.append("JS_HOST_CLASS_MAY_INTERFERE_WITH_INDEXED_PROPERTY_ACCESS")+ flags.append("JS_HOST_CLASS_NOT_CACHEABLE_ACROSS_REALMS")if any(interface_in_chain.name == "HTMLAllCollection" for interface_in_chain in interfaces):flags.append("JS_HOST_CLASS_IS_HTMLDDA")if is_global:diff --git a/Tests/LibWeb/Text/expected/HTML/cross-origin-WindowProxy-and-Location-computed-key-access.txt b/Tests/LibWeb/Text/expected/HTML/cross-origin-WindowProxy-and-Location-computed-key-access.txtnew file mode 100644index 00000000000..ee04dc3ae38--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/cross-origin-WindowProxy-and-Location-computed-key-access.txt@@ -0,0 +1,8 @@+Read of a WindowProxy property: SecurityError+Read of a Location property: SecurityError+Write of a Location property: SecurityError+Read through an object inheriting from Location: SecurityError+Write through an object inheriting from Location: SecurityError+Read of a Location property after reading a copy of Location: SecurityError+Object.prototype.toString of a WindowProxy: [object Object]+Promise resolved with a WindowProxy: the WindowProxydiff --git a/Tests/LibWeb/Text/input/HTML/cross-origin-WindowProxy-and-Location-computed-key-access.html b/Tests/LibWeb/Text/input/HTML/cross-origin-WindowProxy-and-Location-computed-key-access.htmlnew file mode 100644index 00000000000..c8a23b6a23a--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/cross-origin-WindowProxy-and-Location-computed-key-access.html@@ -0,0 +1,92 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ function read(object, key) {+ return object[key];+ }++ function write(object, key, value) {+ object[key] = value;+ }++ function makeReadsGeneric() {+ for (let i = 0; i < 1500; ++i)+ read({ [`key${i}`]: i }, `key${i}`);+ }++ function makeWritesGeneric() {+ for (let i = 0; i < 1500; ++i)+ write({}, `key${i}`, i);+ }++ function accessOwnWindowAndLocation() {+ window.secret = {};+ read(window, "secret");+ makeWritesGeneric();+ write(location, "expando", 1);+ write(location, "expando", 2);+ read(location, "reload");+ parent.postMessage("ready", "*");+ }++ function accessOwnLocationThroughPrototype() {+ makeWritesGeneric();+ read(Object.create(location), "reload");+ write(Object.create(location), "expando", 1);+ parent.postMessage("ready", "*");+ }++ function readCopyOfOwnLocation() {+ const copy = Object.create(Object.getPrototypeOf(location), Object.getOwnPropertyDescriptors(location));+ read(copy, "reload");+ parent.postMessage("ready", "*");+ }++ function passOwnWindowToBuiltIns() {+ window.then = resolve => resolve("the frame's then function");+ Object.prototype.toString.call(window);+ Promise.resolve(window);+ parent.postMessage("ready", "*");+ }++ function loadSandboxedFrame(script) {+ const ready = new Promise(resolve => window.addEventListener("message", resolve, { once: true }));+ const iframe = document.createElement("iframe");+ iframe.sandbox = "allow-scripts";+ iframe.srcdoc = `<script>${read}${write}${makeWritesGeneric}(${script})()<\/script>`;+ document.body.appendChild(iframe);+ return ready;+ }++ function report(description, callback) {+ try {+ callback();+ println(`${description}: no exception`);+ } catch (e) {+ println(`${description}: ${e.name}`);+ }+ }++ promiseTest(async () => {+ makeReadsGeneric();+ makeWritesGeneric();++ await loadSandboxedFrame(accessOwnWindowAndLocation);+ report("Read of a WindowProxy property", () => read(frames[0], "secret"));+ report("Read of a Location property", () => read(frames[0].location, "reload"));+ report("Write of a Location property", () => write(frames[0].location, "expando", 3));++ await loadSandboxedFrame(accessOwnLocationThroughPrototype);+ const inheritsFromLocation = () => Object.create(frames[1].location);+ report("Read through an object inheriting from Location", () => read(inheritsFromLocation(), "reload"));+ report("Write through an object inheriting from Location", () => write(inheritsFromLocation(), "expando", 2));++ await loadSandboxedFrame(readCopyOfOwnLocation);+ report("Read of a Location property after reading a copy of Location", () => read(frames[2].location, "reload"));++ await loadSandboxedFrame(passOwnWindowToBuiltIns);+ println(`Object.prototype.toString of a WindowProxy: ${Object.prototype.toString.call(frames[3])}`);+ const resolution = await Promise.resolve(frames[3]);+ println(`Promise resolved with a WindowProxy: ${resolution === frames[3] ? "the WindowProxy" : resolution}`);+ });+</script>