Skip to content

Commit

Permalink
LibWeb: Don't cache property accesses on WindowProxy
Browse files Browse the repository at this point in the history
Since the underlying HTML::Window can change, caching property accesses
on WindowProxy is not as simple as remembering the shape. Let's disable
caching here for now. We can come back to it in the future when we have
no low-hanging fruit left. :^)

Fixes an assertion failure on https://twinings.co.uk/
  • Loading branch information
awesomekling committed Jul 10, 2023
1 parent dbb018e commit 9a9c8c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
123
undefined
13 changes: 13 additions & 0 deletions Tests/LibWeb/Text/input/window-proxy-property-inline-cache.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script src="include.js"></script>
<script>
test(() => {
function ic(o) {
return o.foo
}

window.foo = 123
println(ic(window))
delete window.foo
println(ic(window))
});
</script>
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/HTML/WindowProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_define_own_property(JS::Proper
}

// 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get
JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const& property_key, JS::Value receiver, JS::CacheablePropertyMetadata* cacheable_metadata) const
JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const& property_key, JS::Value receiver, JS::CacheablePropertyMetadata*) const
{
auto& vm = this->vm();

Expand All @@ -156,7 +156,7 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
// 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver).
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
if (is_platform_object_same_origin(*m_window))
return JS::Object::internal_get(property_key, receiver, cacheable_metadata);
return JS::Object::internal_get(property_key, receiver);

// 4. Return ? CrossOriginGet(this, P, Receiver).
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
Expand Down

0 comments on commit 9a9c8c8

Please sign in to comment.