diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-23 16:57:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-23 16:57:39 +0200 |
commit | fc4ed8d444535f6ddf5b2d8f414466e2bdfb46b5 (patch) | |
tree | da312b4d7a231ef27f421213552bba25c5db3710 | |
parent | c24f5585b29a52c32315dbed49aa66c7fe94caa0 (diff) | |
download | serenity-fc4ed8d444535f6ddf5b2d8f414466e2bdfb46b5.zip |
LibWeb: Make wrapper factory functions take JS::GlobalObject&
Instead of taking the JS::Heap&. This allows us to get rid of some
calls to JS::Interpreter::global_object(). We're getting closer and
closer to multiple global objects. :^)
-rw-r--r-- | Libraries/LibJS/Runtime/GlobalObject.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/EventWrapperFactory.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/EventWrapperFactory.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/NodeWrapperFactory.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/WindowObject.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/Wrappable.h | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Node.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/XMLHttpRequest.cpp | 8 |
12 files changed, 33 insertions, 36 deletions
diff --git a/Libraries/LibJS/Runtime/GlobalObject.h b/Libraries/LibJS/Runtime/GlobalObject.h index 0801d712c3..862522a0f1 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Libraries/LibJS/Runtime/GlobalObject.h @@ -27,6 +27,7 @@ #pragma once #include <LibJS/Heap/Heap.h> +#include <LibJS/Interpreter.h> #include <LibJS/Runtime/Object.h> namespace JS { diff --git a/Libraries/LibWeb/Bindings/EventWrapperFactory.cpp b/Libraries/LibWeb/Bindings/EventWrapperFactory.cpp index ced48a4155..d741d678cc 100644 --- a/Libraries/LibWeb/Bindings/EventWrapperFactory.cpp +++ b/Libraries/LibWeb/Bindings/EventWrapperFactory.cpp @@ -24,18 +24,17 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <LibJS/Interpreter.h> #include <LibWeb/Bindings/EventWrapper.h> #include <LibWeb/Bindings/MouseEventWrapper.h> namespace Web { namespace Bindings { -EventWrapper* wrap(JS::Heap& heap, Event& event) +EventWrapper* wrap(JS::GlobalObject& global_object, Event& event) { if (event.is_mouse_event()) - return static_cast<MouseEventWrapper*>(wrap_impl(heap, static_cast<MouseEvent&>(event))); - return static_cast<EventWrapper*>(wrap_impl(heap, event)); + return static_cast<MouseEventWrapper*>(wrap_impl(global_object, static_cast<MouseEvent&>(event))); + return static_cast<EventWrapper*>(wrap_impl(global_object, event)); } } diff --git a/Libraries/LibWeb/Bindings/EventWrapperFactory.h b/Libraries/LibWeb/Bindings/EventWrapperFactory.h index dee3c5422a..c5a701385e 100644 --- a/Libraries/LibWeb/Bindings/EventWrapperFactory.h +++ b/Libraries/LibWeb/Bindings/EventWrapperFactory.h @@ -32,7 +32,7 @@ namespace Web { namespace Bindings { -EventWrapper* wrap(JS::Heap&, Event&); +EventWrapper* wrap(JS::GlobalObject&, Event&); } } diff --git a/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp b/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp index 30bc0edeb1..9647829240 100644 --- a/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp +++ b/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp @@ -24,7 +24,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <LibJS/Interpreter.h> #include <LibWeb/Bindings/DocumentWrapper.h> #include <LibWeb/Bindings/HTMLCanvasElementWrapper.h> #include <LibWeb/Bindings/HTMLImageElementWrapper.h> @@ -38,19 +37,19 @@ namespace Web { namespace Bindings { -NodeWrapper* wrap(JS::Heap& heap, Node& node) +NodeWrapper* wrap(JS::GlobalObject& global_object, Node& node) { if (is<Document>(node)) - return static_cast<NodeWrapper*>(wrap_impl(heap, to<Document>(node))); + return static_cast<NodeWrapper*>(wrap_impl(global_object, to<Document>(node))); if (is<HTMLCanvasElement>(node)) - return static_cast<NodeWrapper*>(wrap_impl(heap, to<HTMLCanvasElement>(node))); + return static_cast<NodeWrapper*>(wrap_impl(global_object, to<HTMLCanvasElement>(node))); if (is<HTMLImageElement>(node)) - return static_cast<NodeWrapper*>(wrap_impl(heap, to<HTMLImageElement>(node))); + return static_cast<NodeWrapper*>(wrap_impl(global_object, to<HTMLImageElement>(node))); if (is<HTMLElement>(node)) - return static_cast<NodeWrapper*>(wrap_impl(heap, to<HTMLElement>(node))); + return static_cast<NodeWrapper*>(wrap_impl(global_object, to<HTMLElement>(node))); if (is<Element>(node)) - return static_cast<NodeWrapper*>(wrap_impl(heap, to<Element>(node))); - return static_cast<NodeWrapper*>(wrap_impl(heap, node)); + return static_cast<NodeWrapper*>(wrap_impl(global_object, to<Element>(node))); + return static_cast<NodeWrapper*>(wrap_impl(global_object, node)); } } diff --git a/Libraries/LibWeb/Bindings/NodeWrapperFactory.h b/Libraries/LibWeb/Bindings/NodeWrapperFactory.h index b8fa0cd10b..28093e1b03 100644 --- a/Libraries/LibWeb/Bindings/NodeWrapperFactory.h +++ b/Libraries/LibWeb/Bindings/NodeWrapperFactory.h @@ -32,7 +32,7 @@ namespace Web { namespace Bindings { -NodeWrapper* wrap(JS::Heap&, Node&); +NodeWrapper* wrap(JS::GlobalObject&, Node&); } } diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index a347f22d44..2382dd16de 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -244,7 +244,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter) auto* impl = impl_from(interpreter, global_object); if (!impl) return {}; - return wrap(interpreter.heap(), impl->document()); + return wrap(global_object, impl->document()); } JS_DEFINE_NATIVE_SETTER(WindowObject::document_setter) diff --git a/Libraries/LibWeb/Bindings/Wrappable.h b/Libraries/LibWeb/Bindings/Wrappable.h index 696ca7b199..f0b440145a 100644 --- a/Libraries/LibWeb/Bindings/Wrappable.h +++ b/Libraries/LibWeb/Bindings/Wrappable.h @@ -28,7 +28,7 @@ #include <AK/WeakPtr.h> #include <LibJS/Heap/Heap.h> -#include <LibJS/Interpreter.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibWeb/Forward.h> namespace Web { @@ -47,11 +47,10 @@ private: }; template<class NativeObject> -inline Wrapper* wrap_impl(JS::Heap& heap, NativeObject& native_object) +inline Wrapper* wrap_impl(JS::GlobalObject& global_object, NativeObject& native_object) { if (!native_object.wrapper()) { - auto& global_object = heap.interpreter().global_object(); - native_object.set_wrapper(*heap.allocate<typename NativeObject::WrapperType>(global_object, global_object, native_object)); + native_object.set_wrapper(*global_object.heap().allocate<typename NativeObject::WrapperType>(global_object, global_object, native_object)); } return native_object.wrapper(); } diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.cpp b/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.cpp index df38dce6ca..98ae528e95 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.cpp +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.cpp @@ -25,7 +25,6 @@ */ #include <AK/FlyString.h> -#include <LibJS/Interpreter.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Value.h> #include <LibWeb/Bindings/WindowObject.h> @@ -36,9 +35,9 @@ namespace Web { namespace Bindings { -XMLHttpRequestWrapper* wrap(JS::Heap& heap, XMLHttpRequest& impl) +XMLHttpRequestWrapper* wrap(JS::GlobalObject& global_object, XMLHttpRequest& impl) { - return static_cast<XMLHttpRequestWrapper*>(wrap_impl(heap, impl)); + return static_cast<XMLHttpRequestWrapper*>(wrap_impl(global_object, impl)); } XMLHttpRequestWrapper::XMLHttpRequestWrapper(JS::GlobalObject& global_object, XMLHttpRequest& impl) diff --git a/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.h b/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.h index 3f18d76b76..cf23e15fce 100644 --- a/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.h +++ b/Libraries/LibWeb/Bindings/XMLHttpRequestWrapper.h @@ -43,7 +43,7 @@ private: virtual const char* class_name() const override { return "XMLHttpRequestWrapper"; } }; -XMLHttpRequestWrapper* wrap(JS::Heap&, XMLHttpRequest&); +XMLHttpRequestWrapper* wrap(JS::GlobalObject&, XMLHttpRequest&); } } diff --git a/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index 89df442390..5d626e17ba 100644 --- a/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -398,7 +398,7 @@ static void generate_header(const IDL::Interface& interface) out() << "};"; if (should_emit_wrapper_factory(interface)) { - out() << wrapper_class << "* wrap(JS::Heap&, " << interface.name << "&);"; + out() << wrapper_class << "* wrap(JS::GlobalObject&, " << interface.name << "&);"; } out() << "}"; @@ -549,7 +549,7 @@ void generate_implementation(const IDL::Interface& interface) // Basically once we have NodeList we can throw this out. out() << " auto* new_array = JS::Array::create(global_object);"; out() << " for (auto& element : retval) {"; - out() << " new_array->indexed_properties().append(wrap(interpreter.heap(), element));"; + out() << " new_array->indexed_properties().append(wrap(global_object, element));"; out() << " }"; out() << " return new_array;"; } else if (return_type.name == "long" || return_type.name == "double") { @@ -557,7 +557,7 @@ void generate_implementation(const IDL::Interface& interface) } else if (return_type.name == "Uint8ClampedArray") { out() << " return retval;"; } else { - out() << " return wrap(interpreter.heap(), const_cast<" << return_type.name << "&>(*retval));"; + out() << " return wrap(global_object, const_cast<" << return_type.name << "&>(*retval));"; } }; @@ -613,9 +613,9 @@ void generate_implementation(const IDL::Interface& interface) // Implementation: Wrapper factory if (should_emit_wrapper_factory(interface)) { - out() << wrapper_class << "* wrap(JS::Heap& heap, " << interface.name << "& impl)"; + out() << wrapper_class << "* wrap(JS::GlobalObject& global_object, " << interface.name << "& impl)"; out() << "{"; - out() << " return static_cast<" << wrapper_class << "*>(wrap_impl(heap, impl));"; + out() << " return static_cast<" << wrapper_class << "*>(wrap_impl(global_object, impl));"; out() << "}"; } diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 43bab85987..2683f0f3cb 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -137,13 +137,13 @@ void Node::dispatch_event(NonnullRefPtr<Event> event) #ifdef EVENT_DEBUG static_cast<const JS::ScriptFunction*>(function)->body().dump(0); #endif - auto& heap = function.heap(); - auto* this_value = wrap(heap, *this); + auto& global_object = function.global_object(); + auto* this_value = wrap(global_object, *this); #ifdef EVENT_DEBUG dbg() << "calling event listener with this=" << this_value; #endif - auto* event_wrapper = wrap(heap, *event); - JS::MarkedValueList arguments(heap); + auto* event_wrapper = wrap(global_object, *event); + JS::MarkedValueList arguments(global_object.heap()); arguments.append(event_wrapper); document().interpreter().call(function, this_value, move(arguments)); } diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp index 89789c2a63..46e41187ad 100644 --- a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp +++ b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp @@ -94,10 +94,10 @@ void XMLHttpRequest::dispatch_event(NonnullRefPtr<Event> event) for (auto& listener : listeners()) { if (listener.event_name == event->type()) { auto& function = const_cast<EventListener&>(*listener.listener).function(); - auto& heap = function.heap(); - auto* this_value = wrap(heap, *this); - JS::MarkedValueList arguments(heap); - arguments.append(wrap(heap, *event)); + auto& global_object = function.global_object(); + auto* this_value = wrap(global_object, *this); + JS::MarkedValueList arguments(global_object.heap()); + arguments.append(wrap(global_object, *event)); function.interpreter().call(function, this_value, move(arguments)); } } |