1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

LibWeb: Implement window.event as a [Replaceable] property

This is the result of debugging React DOM, which would throw a TypeError
when assigning to window.event in strict mode and then not complete
rendering - here:
cae6350/packages/shared/invokeGuardedCallbackImpl.js (L134)

With this change, the following minimal React example now works!

    <div id="app"></div>
    <script src="react.development.js"></script>
    <script src="react-dom.development.js"></script>
    <script>
        ReactDOM.render(
            React.createElement("h1", null, "Hello World"),
            document.getElementById("app")
        );
    </script>
This commit is contained in:
Linus Groh 2021-09-12 11:39:09 +01:00 committed by Andreas Kling
parent a05c998e69
commit 7991077284
2 changed files with 8 additions and 1 deletions

View file

@ -24,6 +24,7 @@
#include <LibWeb/Bindings/NavigatorObject.h> #include <LibWeb/Bindings/NavigatorObject.h>
#include <LibWeb/Bindings/NodeWrapperFactory.h> #include <LibWeb/Bindings/NodeWrapperFactory.h>
#include <LibWeb/Bindings/PerformanceWrapper.h> #include <LibWeb/Bindings/PerformanceWrapper.h>
#include <LibWeb/Bindings/Replaceable.h>
#include <LibWeb/Bindings/ScreenWrapper.h> #include <LibWeb/Bindings/ScreenWrapper.h>
#include <LibWeb/Bindings/WindowObject.h> #include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
@ -89,7 +90,7 @@ void WindowObject::initialize_global_object()
define_native_function("scrollBy", scroll_by, 2, attr); define_native_function("scrollBy", scroll_by, 2, attr);
// Legacy // Legacy
define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable); define_native_accessor("event", event_getter, event_setter, JS::Attribute::Enumerable);
define_direct_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); define_direct_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); define_direct_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -439,6 +440,11 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::event_getter)
return wrap(global_object, const_cast<DOM::Event&>(*impl->current_event())); return wrap(global_object, const_cast<DOM::Event&>(*impl->current_event()));
} }
JS_DEFINE_NATIVE_FUNCTION(WindowObject::event_setter)
{
REPLACEABLE_PROPERTY_SETTER(WindowObject, event);
}
JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_width_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_width_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);

View file

@ -68,6 +68,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(screen_getter); JS_DECLARE_NATIVE_FUNCTION(screen_getter);
JS_DECLARE_NATIVE_FUNCTION(event_getter); JS_DECLARE_NATIVE_FUNCTION(event_getter);
JS_DECLARE_NATIVE_FUNCTION(event_setter);
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);