mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:27:43 +00:00
LibWeb: Make window.{window,self,frames} return the WindowProxy
These now follow the spec and return the WindowProxy rather than the Window itself.
This commit is contained in:
parent
940b455ed0
commit
58522f5088
2 changed files with 39 additions and 6 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <LibJS/Runtime/Completion.h>
|
#include <LibJS/Runtime/Completion.h>
|
||||||
#include <LibJS/Runtime/Error.h>
|
#include <LibJS/Runtime/Error.h>
|
||||||
#include <LibJS/Runtime/FunctionObject.h>
|
#include <LibJS/Runtime/FunctionObject.h>
|
||||||
|
#include <LibJS/Runtime/GlobalEnvironment.h>
|
||||||
#include <LibJS/Runtime/Shape.h>
|
#include <LibJS/Runtime/Shape.h>
|
||||||
#include <LibTextCodec/Decoder.h>
|
#include <LibTextCodec/Decoder.h>
|
||||||
#include <LibWeb/Bindings/CSSNamespace.h>
|
#include <LibWeb/Bindings/CSSNamespace.h>
|
||||||
|
@ -707,10 +708,10 @@ void Window::initialize_web_interfaces(Badge<WindowEnvironmentSettingsObject>)
|
||||||
m_crypto = Crypto::Crypto::create(realm);
|
m_crypto = Crypto::Crypto::create(realm);
|
||||||
|
|
||||||
// FIXME: These should be native accessors, not properties
|
// FIXME: These should be native accessors, not properties
|
||||||
define_direct_property("window", this, JS::Attribute::Enumerable);
|
|
||||||
define_direct_property("frames", this, JS::Attribute::Enumerable);
|
|
||||||
define_direct_property("self", this, JS::Attribute::Enumerable);
|
|
||||||
define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable);
|
define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable);
|
||||||
|
define_native_accessor(realm, "window", window_getter, {}, JS::Attribute::Enumerable);
|
||||||
|
define_native_accessor(realm, "frames", frames_getter, {}, JS::Attribute::Enumerable);
|
||||||
|
define_native_accessor(realm, "self", self_getter, {}, JS::Attribute::Enumerable);
|
||||||
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
|
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
|
||||||
define_native_accessor(realm, "document", document_getter, {}, JS::Attribute::Enumerable);
|
define_native_accessor(realm, "document", document_getter, {}, JS::Attribute::Enumerable);
|
||||||
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
|
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
|
||||||
|
@ -817,9 +818,13 @@ static JS::ThrowCompletionOr<HTML::Window*> impl_from(JS::VM& vm)
|
||||||
|
|
||||||
auto* this_object = MUST(this_value.to_object(vm));
|
auto* this_object = MUST(this_value.to_object(vm));
|
||||||
|
|
||||||
if (!is<Window>(*this_object))
|
if (is<WindowProxy>(*this_object))
|
||||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Window");
|
return static_cast<WindowProxy*>(this_object)->window().ptr();
|
||||||
return static_cast<Window*>(this_object);
|
|
||||||
|
if (is<Window>(*this_object))
|
||||||
|
return static_cast<Window*>(this_object);
|
||||||
|
|
||||||
|
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Window");
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(Window::alert)
|
JS_DEFINE_NATIVE_FUNCTION(Window::alert)
|
||||||
|
@ -1069,6 +1074,30 @@ JS_DEFINE_NATIVE_FUNCTION(Window::top_getter)
|
||||||
return browsing_context->top_level_browsing_context().window_proxy();
|
return browsing_context->top_level_browsing_context().window_proxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/window-object.html#dom-self
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(Window::self_getter)
|
||||||
|
{
|
||||||
|
auto* impl = TRY(impl_from(vm));
|
||||||
|
// The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
|
||||||
|
return &relevant_realm(*impl).global_environment().global_this_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/window-object.html#dom-window
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(Window::window_getter)
|
||||||
|
{
|
||||||
|
auto* impl = TRY(impl_from(vm));
|
||||||
|
// The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
|
||||||
|
return &relevant_realm(*impl).global_environment().global_this_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(Window::frames_getter)
|
||||||
|
{
|
||||||
|
auto* impl = TRY(impl_from(vm));
|
||||||
|
// The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
|
||||||
|
return &relevant_realm(*impl).global_environment().global_this_value();
|
||||||
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
|
JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
|
||||||
{
|
{
|
||||||
auto* impl = TRY(impl_from(vm));
|
auto* impl = TRY(impl_from(vm));
|
||||||
|
|
|
@ -203,6 +203,10 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
|
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
|
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
|
||||||
|
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(window_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(frames_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(self_getter);
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
|
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue