mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-18 14:09:42 +00:00
Before this change, PropertyNameIterator (used by for..in) and `Object::enumerable_own_property_names()` (used by `Object.keys()`, `Object.values()`, and `Object.entries()`) enumerated an object's own enumerable properties exactly as the spec prescribes: - Call `internal_own_property_keys()`, allocating a list of JS::Value keys. - For each key, call internal_get_own_property() to obtain a descriptor and check `[[Enumerable]]`. While that is required in the general case (e.g. for Proxy objects or platform/exotic objects that override `[[OwnPropertyKeys]]`), it's overkill for ordinary JS objects that store their own properties in the shape table and indexed-properties storage. This change introduces `for_each_own_property_with_enumerability()`, which, for objects where `eligible_for_own_property_enumeration_fast_path()` is `true`, lets us read the enumerability directly from shape metadata (and from indexed-properties storage) without a per-property descriptor lookup. When we cannot avoid `internal_get_own_property()`, we still benefit by skipping the temporary `Vector<Value>` of keys and avoiding the unnecessary round-trip between PropertyKey and Value.
56 lines
2.4 KiB
C++
56 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Forward.h>
|
|
#include <LibGC/Ptr.h>
|
|
#include <LibJS/Forward.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
#include <LibWeb/Export.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class WEB_API WindowProxy final : public JS::Object {
|
|
JS_OBJECT(WindowProxy, JS::Object);
|
|
GC_DECLARE_ALLOCATOR(WindowProxy);
|
|
|
|
public:
|
|
virtual ~WindowProxy() override = default;
|
|
|
|
virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override;
|
|
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
|
|
virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const override;
|
|
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
|
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const&) const override;
|
|
virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyKey const&, JS::PropertyDescriptor&, Optional<JS::PropertyDescriptor>* precomputed_get_own_property = nullptr) override;
|
|
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver, JS::CacheableGetPropertyMetadata*, PropertyLookupPhase) const override;
|
|
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver, JS::CacheableSetPropertyMetadata*, PropertyLookupPhase) override;
|
|
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
|
|
virtual JS::ThrowCompletionOr<GC::RootVector<JS::Value>> internal_own_property_keys() const override;
|
|
|
|
virtual bool eligible_for_own_property_enumeration_fast_path() const override final { return false; }
|
|
|
|
GC::Ptr<Window> window() const { return m_window; }
|
|
void set_window(GC::Ref<Window>);
|
|
|
|
GC::Ref<BrowsingContext> associated_browsing_context() const;
|
|
|
|
private:
|
|
explicit WindowProxy(JS::Realm&);
|
|
|
|
virtual bool is_html_window_proxy() const override { return true; }
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
|
|
|
// [[Window]], https://html.spec.whatwg.org/multipage/window-object.html#concept-windowproxy-window
|
|
GC::Ptr<Window> m_window;
|
|
};
|
|
|
|
}
|
|
|
|
template<>
|
|
inline bool JS::Object::fast_is<Web::HTML::WindowProxy>() const { return is_html_window_proxy(); }
|