summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-11-30 22:50:43 +0000
committerAndreas Kling <kling@serenityos.org>2020-12-01 09:54:37 +0100
commit48c19cdb065fdb0a58696a05058943259f4dcce5 (patch)
tree18df572b1bbfb1af85cc96c5b4046dd8c6046e4b
parent78f1b5e359f1436f90d1c54929be30c0e41d8df0 (diff)
downloadserenity-48c19cdb065fdb0a58696a05058943259f4dcce5.zip
LibJS: Remove ProxyPrototype
Proxy is an "exotic object" and doesn't have its own prototype. Use the regular object prototype instead, but most stuff is happening on the target object anyway. :^)
-rw-r--r--Libraries/LibJS/CMakeLists.txt1
-rw-r--r--Libraries/LibJS/Forward.h6
-rw-r--r--Libraries/LibJS/Runtime/GlobalObject.cpp27
-rw-r--r--Libraries/LibJS/Runtime/GlobalObject.h18
-rw-r--r--Libraries/LibJS/Runtime/ProxyConstructor.cpp1
-rw-r--r--Libraries/LibJS/Runtime/ProxyObject.cpp2
-rw-r--r--Libraries/LibJS/Runtime/ProxyPrototype.cpp45
-rw-r--r--Libraries/LibJS/Runtime/ProxyPrototype.h41
-rw-r--r--Libraries/LibWeb/Bindings/WindowObject.cpp2
9 files changed, 33 insertions, 110 deletions
diff --git a/Libraries/LibJS/CMakeLists.txt b/Libraries/LibJS/CMakeLists.txt
index 90b336df9d..6517907288 100644
--- a/Libraries/LibJS/CMakeLists.txt
+++ b/Libraries/LibJS/CMakeLists.txt
@@ -55,7 +55,6 @@ set(SOURCES
Runtime/PropertyAttributes.cpp
Runtime/ProxyConstructor.cpp
Runtime/ProxyObject.cpp
- Runtime/ProxyPrototype.cpp
Runtime/Reference.cpp
Runtime/ReflectObject.cpp
Runtime/RegExpConstructor.cpp
diff --git a/Libraries/LibJS/Forward.h b/Libraries/LibJS/Forward.h
index 57cf1e33dc..a6f482f825 100644
--- a/Libraries/LibJS/Forward.h
+++ b/Libraries/LibJS/Forward.h
@@ -44,6 +44,7 @@
#define JS_DEFINE_NATIVE_SETTER(name) \
void name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object, JS::Value value)
+// NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately.
#define JS_ENUMERATE_NATIVE_OBJECTS \
__JS_ENUMERATE(Array, array, ArrayPrototype, ArrayConstructor) \
__JS_ENUMERATE(BigIntObject, bigint, BigIntPrototype, BigIntConstructor) \
@@ -53,7 +54,6 @@
__JS_ENUMERATE(Function, function, FunctionPrototype, FunctionConstructor) \
__JS_ENUMERATE(NumberObject, number, NumberPrototype, NumberConstructor) \
__JS_ENUMERATE(Object, object, ObjectPrototype, ObjectConstructor) \
- __JS_ENUMERATE(ProxyObject, proxy, ProxyPrototype, ProxyConstructor) \
__JS_ENUMERATE(RegExpObject, regexp, RegExpPrototype, RegExpConstructor) \
__JS_ENUMERATE(StringObject, string, StringPrototype, StringConstructor) \
__JS_ENUMERATE(SymbolObject, symbol, SymbolPrototype, SymbolConstructor)
@@ -134,6 +134,10 @@ class VM;
class Value;
enum class DeclarationKind;
+// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
+class ProxyObject;
+class ProxyConstructor;
+
#define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \
class ClassName; \
class ConstructorName; \
diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp
index d878996b44..7d8b0992df 100644
--- a/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -53,7 +53,6 @@
#include <LibJS/Runtime/ObjectConstructor.h>
#include <LibJS/Runtime/ObjectPrototype.h>
#include <LibJS/Runtime/ProxyConstructor.h>
-#include <LibJS/Runtime/ProxyPrototype.h>
#include <LibJS/Runtime/ReflectObject.h>
#include <LibJS/Runtime/RegExpConstructor.h>
#include <LibJS/Runtime/RegExpPrototype.h>
@@ -124,21 +123,21 @@ void GlobalObject::initialize()
define_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr);
define_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr);
- add_constructor(vm.names.Array, m_array_constructor, *m_array_prototype);
- add_constructor(vm.names.BigInt, m_bigint_constructor, *m_bigint_prototype);
- add_constructor(vm.names.Boolean, m_boolean_constructor, *m_boolean_prototype);
- add_constructor(vm.names.Date, m_date_constructor, *m_date_prototype);
- add_constructor(vm.names.Error, m_error_constructor, *m_error_prototype);
- add_constructor(vm.names.Function, m_function_constructor, *m_function_prototype);
- add_constructor(vm.names.Number, m_number_constructor, *m_number_prototype);
- add_constructor(vm.names.Object, m_object_constructor, *m_object_prototype);
- add_constructor(vm.names.Proxy, m_proxy_constructor, *m_proxy_prototype);
- add_constructor(vm.names.RegExp, m_regexp_constructor, *m_regexp_prototype);
- add_constructor(vm.names.String, m_string_constructor, *m_string_prototype);
- add_constructor(vm.names.Symbol, m_symbol_constructor, *m_symbol_prototype);
+ add_constructor(vm.names.Array, m_array_constructor, m_array_prototype);
+ add_constructor(vm.names.BigInt, m_bigint_constructor, m_bigint_prototype);
+ add_constructor(vm.names.Boolean, m_boolean_constructor, m_boolean_prototype);
+ add_constructor(vm.names.Date, m_date_constructor, m_date_prototype);
+ add_constructor(vm.names.Error, m_error_constructor, m_error_prototype);
+ add_constructor(vm.names.Function, m_function_constructor, m_function_prototype);
+ add_constructor(vm.names.Number, m_number_constructor, m_number_prototype);
+ add_constructor(vm.names.Object, m_object_constructor, m_object_prototype);
+ add_constructor(vm.names.Proxy, m_proxy_constructor, nullptr);
+ add_constructor(vm.names.RegExp, m_regexp_constructor, m_regexp_prototype);
+ add_constructor(vm.names.String, m_string_constructor, m_string_prototype);
+ add_constructor(vm.names.Symbol, m_symbol_constructor, m_symbol_prototype);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
- add_constructor(vm.names.ClassName, m_##snake_name##_constructor, *m_##snake_name##_prototype);
+ add_constructor(vm.names.ClassName, m_##snake_name##_constructor, m_##snake_name##_prototype);
JS_ENUMERATE_ERROR_SUBCLASSES
#undef __JS_ENUMERATE
}
diff --git a/Libraries/LibJS/Runtime/GlobalObject.h b/Libraries/LibJS/Runtime/GlobalObject.h
index b0d8214478..6ac0eaaa47 100644
--- a/Libraries/LibJS/Runtime/GlobalObject.h
+++ b/Libraries/LibJS/Runtime/GlobalObject.h
@@ -53,6 +53,9 @@ public:
Shape* new_object_shape() { return m_new_object_shape; }
Shape* new_script_function_prototype_object_shape() { return m_new_script_function_prototype_object_shape; }
+ // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
+ ProxyConstructor* proxy_constructor() { return m_proxy_constructor; }
+
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
ConstructorName* snake_name##_constructor() { return m_##snake_name##_constructor; } \
Object* snake_name##_prototype() { return m_##snake_name##_prototype; }
@@ -68,7 +71,7 @@ protected:
virtual void visit_edges(Visitor&) override;
template<typename ConstructorType>
- void add_constructor(const FlyString& property_name, ConstructorType*&, Object& prototype);
+ void add_constructor(const FlyString& property_name, ConstructorType*&, Object* prototype);
private:
virtual bool is_global_object() const final { return true; }
@@ -84,6 +87,9 @@ private:
Shape* m_new_object_shape { nullptr };
Shape* m_new_script_function_prototype_object_shape { nullptr };
+ // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
+ ProxyConstructor* m_proxy_constructor { nullptr };
+
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
ConstructorName* m_##snake_name##_constructor { nullptr }; \
Object* m_##snake_name##_prototype { nullptr };
@@ -97,16 +103,18 @@ private:
};
template<typename ConstructorType>
-inline void GlobalObject::add_constructor(const FlyString& property_name, ConstructorType*& constructor, Object& prototype)
+inline void GlobalObject::add_constructor(const FlyString& property_name, ConstructorType*& constructor, Object* prototype)
{
auto& vm = this->vm();
constructor = heap().allocate<ConstructorType>(*this, *this);
constructor->define_property(vm.names.name, js_string(heap(), property_name), Attribute::Configurable);
if (vm.exception())
return;
- prototype.define_property(vm.names.constructor, constructor, Attribute::Writable | Attribute::Configurable);
- if (vm.exception())
- return;
+ if (prototype) {
+ prototype->define_property(vm.names.constructor, constructor, Attribute::Writable | Attribute::Configurable);
+ if (vm.exception())
+ return;
+ }
define_property(property_name, constructor, Attribute::Writable | Attribute::Configurable);
}
diff --git a/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Libraries/LibJS/Runtime/ProxyConstructor.cpp
index 747b74a852..53515ccbe1 100644
--- a/Libraries/LibJS/Runtime/ProxyConstructor.cpp
+++ b/Libraries/LibJS/Runtime/ProxyConstructor.cpp
@@ -41,7 +41,6 @@ void ProxyConstructor::initialize(GlobalObject& global_object)
{
auto& vm = this->vm();
NativeFunction::initialize(global_object);
- define_property(vm.names.prototype, global_object.proxy_prototype(), 0);
define_property(vm.names.length, Value(2), Attribute::Configurable);
}
diff --git a/Libraries/LibJS/Runtime/ProxyObject.cpp b/Libraries/LibJS/Runtime/ProxyObject.cpp
index 12f9a99202..85a0d9db1b 100644
--- a/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -59,7 +59,7 @@ bool static is_compatible_property_descriptor(bool is_extensible, PropertyDescri
ProxyObject* ProxyObject::create(GlobalObject& global_object, Object& target, Object& handler)
{
- return global_object.heap().allocate<ProxyObject>(global_object, target, handler, *global_object.proxy_prototype());
+ return global_object.heap().allocate<ProxyObject>(global_object, target, handler, *global_object.object_prototype());
}
ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
diff --git a/Libraries/LibJS/Runtime/ProxyPrototype.cpp b/Libraries/LibJS/Runtime/ProxyPrototype.cpp
deleted file mode 100644
index ce44b0e364..0000000000
--- a/Libraries/LibJS/Runtime/ProxyPrototype.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <AK/Function.h>
-#include <AK/StringBuilder.h>
-#include <LibJS/Heap/Heap.h>
-#include <LibJS/Runtime/Error.h>
-#include <LibJS/Runtime/GlobalObject.h>
-#include <LibJS/Runtime/ProxyPrototype.h>
-
-namespace JS {
-
-ProxyPrototype::ProxyPrototype(GlobalObject& global_object)
- : Object(*global_object.object_prototype())
-{
-}
-
-ProxyPrototype::~ProxyPrototype()
-{
-}
-
-}
diff --git a/Libraries/LibJS/Runtime/ProxyPrototype.h b/Libraries/LibJS/Runtime/ProxyPrototype.h
deleted file mode 100644
index b680f6dacb..0000000000
--- a/Libraries/LibJS/Runtime/ProxyPrototype.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <LibJS/Runtime/Object.h>
-
-namespace JS {
-
-class ProxyPrototype final : public Object {
- JS_OBJECT(ProxyPrototype, Object);
-
-public:
- explicit ProxyPrototype(GlobalObject&);
- virtual ~ProxyPrototype() override;
-};
-
-}
diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp
index 7d271f00e5..ec740dfa79 100644
--- a/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -87,7 +87,7 @@ void WindowObject::initialize()
m_xhr_prototype = heap().allocate<XMLHttpRequestPrototype>(*this, *this);
m_xhr_constructor = heap().allocate<XMLHttpRequestConstructor>(*this, *this);
m_xhr_constructor->define_property("prototype", m_xhr_prototype, 0);
- add_constructor("XMLHttpRequest", m_xhr_constructor, *m_xhr_prototype);
+ add_constructor("XMLHttpRequest", m_xhr_constructor, m_xhr_prototype);
}
WindowObject::~WindowObject()