From ee5bac08912dc4cbe565bd31636aa8b962b9f727 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Sun, 12 Sep 2021 14:54:17 +0100 Subject: [PATCH] LibWeb: Implement some custom JS internal overrides for Location As required by the spec. Note that this isn't the full suite of overrides. --- .../LibWeb/Bindings/LocationObject.cpp | 22 +++++++++++++++++-- .../LibWeb/Bindings/LocationObject.h | 7 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 9a9cdf7b84..e1d5e355f5 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -11,8 +11,7 @@ #include #include -namespace Web { -namespace Bindings { +namespace Web::Bindings { LocationObject::LocationObject(JS::GlobalObject& global_object) : Object(*global_object.object_prototype()) @@ -118,6 +117,25 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) return JS::js_undefined(); } +// https://html.spec.whatwg.org/multipage/history.html#location-setprototypeof +bool LocationObject::internal_set_prototype_of(Object* prototype) +{ + // 1. Return ! SetImmutablePrototype(this, V). + return set_immutable_prototype(prototype); +} + +// https://html.spec.whatwg.org/multipage/history.html#location-isextensible +bool LocationObject::internal_is_extensible() const +{ + // 1. Return true. + return true; +} + +// https://html.spec.whatwg.org/multipage/history.html#location-preventextensions +bool LocationObject::internal_prevent_extensions() +{ + // 1. Return false. + return false; } } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h index 282104f888..df01f699e5 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h @@ -20,6 +20,13 @@ public: virtual void initialize(JS::GlobalObject&) override; virtual ~LocationObject() override; + virtual bool internal_set_prototype_of(Object* prototype) override; + virtual bool internal_is_extensible() const override; + virtual bool internal_prevent_extensions() override; + + // FIXME: There should also be a custom [[GetPrototypeOf]], [[GetOwnProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]] and [[OwnPropertyKeys]], + // but we don't have the infrastructure in place to implement them yet. + private: JS_DECLARE_NATIVE_FUNCTION(reload);