diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-18 13:18:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-18 13:24:45 +0200 |
commit | fca08bd000e613459baf62fa8d37552ef11f3fe6 (patch) | |
tree | f20e36879896fb150a6031b4383b53296de6ca45 /Libraries/LibJS/Runtime | |
parent | cbcf317e760c3370d10cfc525f0f528abd44e820 (diff) | |
download | serenity-fca08bd000e613459baf62fa8d37552ef11f3fe6.zip |
LibJS: Move builtin prototypes to the global object
This moves us towards being able to run JavaScript in different global
objects without allocating a separate GC heap.
Diffstat (limited to 'Libraries/LibJS/Runtime')
28 files changed, 103 insertions, 57 deletions
diff --git a/Libraries/LibJS/Runtime/Array.cpp b/Libraries/LibJS/Runtime/Array.cpp index 0c9ea12235..4ade3791e3 100644 --- a/Libraries/LibJS/Runtime/Array.cpp +++ b/Libraries/LibJS/Runtime/Array.cpp @@ -36,7 +36,7 @@ namespace JS { Array* Array::create(GlobalObject& global_object) { auto& interpreter = global_object.interpreter(); - return interpreter.heap().allocate<Array>(*interpreter.array_prototype()); + return interpreter.heap().allocate<Array>(*global_object.array_prototype()); } Array::Array(Object& prototype) diff --git a/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 2fd7162f33..0c9d2ea12f 100644 --- a/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -29,14 +29,15 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/ArrayConstructor.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Shape.h> namespace JS { ArrayConstructor::ArrayConstructor() - : NativeFunction("Array", *interpreter().function_prototype()) + : NativeFunction("Array", *interpreter().global_object().function_prototype()) { - put("prototype", interpreter().array_prototype()); + put("prototype", interpreter().global_object().array_prototype()); put("length", Value(1)); } diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 1fc08c8a36..8ec1765fcd 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -33,12 +33,13 @@ #include <LibJS/Runtime/ArrayPrototype.h> #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Function.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Value.h> namespace JS { ArrayPrototype::ArrayPrototype() - : Object(interpreter().object_prototype()) + : Object(interpreter().global_object().object_prototype()) { put_native_function("filter", filter, 1); put_native_function("forEach", for_each, 1); diff --git a/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Libraries/LibJS/Runtime/BooleanConstructor.cpp index b588671946..b1522a698c 100644 --- a/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -29,13 +29,14 @@ #include <LibJS/Runtime/BooleanConstructor.h> #include <LibJS/Runtime/BooleanObject.h> #include <LibJS/Runtime/BooleanPrototype.h> +#include <LibJS/Runtime/GlobalObject.h> namespace JS { BooleanConstructor::BooleanConstructor() - : NativeFunction("Boolean", *interpreter().function_prototype()) + : NativeFunction("Boolean", *interpreter().global_object().function_prototype()) { - put("prototype", Value(interpreter().boolean_prototype())); + put("prototype", Value(interpreter().global_object().boolean_prototype())); put("length", Value(1)); } diff --git a/Libraries/LibJS/Runtime/BooleanObject.cpp b/Libraries/LibJS/Runtime/BooleanObject.cpp index c7d4a4c0f9..8537f5a1d8 100644 --- a/Libraries/LibJS/Runtime/BooleanObject.cpp +++ b/Libraries/LibJS/Runtime/BooleanObject.cpp @@ -33,7 +33,7 @@ namespace JS { BooleanObject* BooleanObject::create(GlobalObject& global_object, bool value) { auto& interpreter = global_object.interpreter(); - return interpreter.heap().allocate<BooleanObject>(value, *interpreter.boolean_prototype()); + return interpreter.heap().allocate<BooleanObject>(value, *global_object.boolean_prototype()); } BooleanObject::BooleanObject(bool value, Object& prototype) diff --git a/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Libraries/LibJS/Runtime/BooleanPrototype.cpp index b4f4f36ded..5bd458ae46 100644 --- a/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -28,11 +28,12 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/BooleanPrototype.h> #include <LibJS/Runtime/Error.h> +#include <LibJS/Runtime/GlobalObject.h> namespace JS { BooleanPrototype::BooleanPrototype() - : BooleanObject(false, *interpreter().object_prototype()) + : BooleanObject(false, *interpreter().global_object().object_prototype()) { put_native_function("toString", to_string); put_native_function("valueOf", value_of); diff --git a/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Libraries/LibJS/Runtime/ConsoleObject.cpp index 56464cde3c..de61b1700e 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -29,6 +29,7 @@ #include <AK/Function.h> #include <LibJS/Interpreter.h> #include <LibJS/Runtime/ConsoleObject.h> +#include <LibJS/Runtime/GlobalObject.h> #include <stdio.h> namespace JS { @@ -44,7 +45,7 @@ static void print_args(Interpreter& interpreter) } ConsoleObject::ConsoleObject() - : Object(interpreter().object_prototype()) + : Object(interpreter().global_object().object_prototype()) { put_native_function("log", log); put_native_function("debug", debug); diff --git a/Libraries/LibJS/Runtime/Date.cpp b/Libraries/LibJS/Runtime/Date.cpp index c9565d40ab..6b22c98fdf 100644 --- a/Libraries/LibJS/Runtime/Date.cpp +++ b/Libraries/LibJS/Runtime/Date.cpp @@ -34,7 +34,7 @@ namespace JS { Date* Date::create(GlobalObject& global_object, Core::DateTime datetime, u16 milliseconds) { - return global_object.heap().allocate<Date>(datetime, milliseconds, *global_object.interpreter().date_prototype()); + return global_object.heap().allocate<Date>(datetime, milliseconds, *global_object.date_prototype()); } Date::Date(Core::DateTime datetime, u16 milliseconds, Object& prototype) diff --git a/Libraries/LibJS/Runtime/DateConstructor.cpp b/Libraries/LibJS/Runtime/DateConstructor.cpp index 79bf837e78..d2f09ff9f3 100644 --- a/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -28,15 +28,16 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Date.h> #include <LibJS/Runtime/DateConstructor.h> +#include <LibJS/Runtime/GlobalObject.h> #include <sys/time.h> #include <time.h> namespace JS { DateConstructor::DateConstructor() - : NativeFunction("Date", *interpreter().function_prototype()) + : NativeFunction("Date", *interpreter().global_object().function_prototype()) { - put("prototype", interpreter().date_prototype()); + put("prototype", interpreter().global_object().date_prototype()); put("length", Value(7)); put_native_function("now", now); diff --git a/Libraries/LibJS/Runtime/DatePrototype.cpp b/Libraries/LibJS/Runtime/DatePrototype.cpp index 0c79e4d099..899232ba78 100644 --- a/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -31,6 +31,7 @@ #include <LibJS/Runtime/Date.h> #include <LibJS/Runtime/DatePrototype.h> #include <LibJS/Runtime/Error.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Value.h> namespace JS { @@ -48,7 +49,7 @@ static Date* this_date_from_interpreter(Interpreter& interpreter) } DatePrototype::DatePrototype() - : Object(interpreter().object_prototype()) + : Object(interpreter().global_object().object_prototype()) { put_native_function("getDate", get_date); put_native_function("getDay", get_day); diff --git a/Libraries/LibJS/Runtime/Error.cpp b/Libraries/LibJS/Runtime/Error.cpp index d6ea45cf4f..c41e87854f 100644 --- a/Libraries/LibJS/Runtime/Error.cpp +++ b/Libraries/LibJS/Runtime/Error.cpp @@ -33,7 +33,7 @@ namespace JS { Error* Error::create(GlobalObject& global_object, const FlyString& name, const String& message) { auto& interpreter = global_object.interpreter(); - return interpreter.heap().allocate<Error>(name, message, *interpreter.error_prototype()); + return interpreter.heap().allocate<Error>(name, message, *global_object.error_prototype()); } Error::Error(const FlyString& name, const String& message, Object& prototype) @@ -51,8 +51,7 @@ Error::~Error() #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ ClassName* ClassName::create(GlobalObject& global_object, const String& message) \ { \ - auto& interpreter = global_object.interpreter(); \ - return interpreter.heap().allocate<ClassName>(message, *interpreter.snake_name##_prototype()); \ + return global_object.heap().allocate<ClassName>(message, *global_object.snake_name##_prototype()); \ } \ ClassName::ClassName(const String& message, Object& prototype) \ : Error(#ClassName, message, prototype) \ diff --git a/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Libraries/LibJS/Runtime/ErrorConstructor.cpp index 11ce86f885..480a069cfb 100644 --- a/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -27,13 +27,14 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/ErrorConstructor.h> +#include <LibJS/Runtime/GlobalObject.h> namespace JS { ErrorConstructor::ErrorConstructor() - : NativeFunction("Error", *interpreter().function_prototype()) + : NativeFunction("Error", *interpreter().global_object().function_prototype()) { - put("prototype", interpreter().error_prototype()); + put("prototype", interpreter().global_object().error_prototype()); put("length", Value(1)); } @@ -56,9 +57,9 @@ Value ErrorConstructor::construct(Interpreter& interpreter) #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ ConstructorName::ConstructorName() \ - : NativeFunction(*interpreter().function_prototype()) \ + : NativeFunction(*interpreter().global_object().function_prototype()) \ { \ - put("prototype", interpreter().snake_name##_prototype()); \ + put("prototype", interpreter().global_object().snake_name##_prototype()); \ put("length", Value(1)); \ } \ ConstructorName::~ConstructorName() {} \ diff --git a/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Libraries/LibJS/Runtime/ErrorPrototype.cpp index 1082b8f06c..d2602e021c 100644 --- a/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -29,13 +29,14 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/ErrorPrototype.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/PrimitiveString.h> #include <LibJS/Runtime/Value.h> namespace JS { ErrorPrototype::ErrorPrototype() - : Object(interpreter().object_prototype()) + : Object(interpreter().global_object().object_prototype()) { put_native_property("name", name_getter, name_setter); put_native_property("message", message_getter, nullptr); @@ -104,7 +105,7 @@ Value ErrorPrototype::to_string(Interpreter& interpreter) #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ PrototypeName::PrototypeName() \ - : Object(interpreter().error_prototype()) \ + : Object(interpreter().global_object().error_prototype()) \ { \ } \ PrototypeName::~PrototypeName() {} \ diff --git a/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Libraries/LibJS/Runtime/FunctionConstructor.cpp index cb716e6206..4dbfcbaed4 100644 --- a/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -30,14 +30,15 @@ #include <LibJS/Parser.h> #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/FunctionConstructor.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/ScriptFunction.h> namespace JS { FunctionConstructor::FunctionConstructor() - : NativeFunction("Function", *interpreter().function_prototype()) + : NativeFunction("Function", *interpreter().global_object().function_prototype()) { - put("prototype", interpreter().function_prototype()); + put("prototype", interpreter().global_object().function_prototype()); put("length", Value(1)); } diff --git a/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Libraries/LibJS/Runtime/FunctionPrototype.cpp index c7511bcb00..69a6c24934 100644 --- a/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -31,12 +31,13 @@ #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Function.h> #include <LibJS/Runtime/FunctionPrototype.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/ScriptFunction.h> namespace JS { FunctionPrototype::FunctionPrototype() - : Object(interpreter().object_prototype()) + : Object(interpreter().global_object().object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp index 30b1f67a9b..0ff1d13fef 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -29,17 +29,29 @@ #include <LibJS/Heap/Heap.h> #include <LibJS/Interpreter.h> #include <LibJS/Runtime/ArrayConstructor.h> +#include <LibJS/Runtime/ArrayPrototype.h> #include <LibJS/Runtime/BooleanConstructor.h> +#include <LibJS/Runtime/BooleanPrototype.h> #include <LibJS/Runtime/ConsoleObject.h> #include <LibJS/Runtime/DateConstructor.h> +#include <LibJS/Runtime/DatePrototype.h> +#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/ErrorConstructor.h> +#include <LibJS/Runtime/ErrorPrototype.h> #include <LibJS/Runtime/FunctionConstructor.h> +#include <LibJS/Runtime/FunctionPrototype.h> #include <LibJS/Runtime/GlobalObject.h> +#include <LibJS/Runtime/LexicalEnvironment.h> #include <LibJS/Runtime/MathObject.h> #include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NumberConstructor.h> +#include <LibJS/Runtime/NumberPrototype.h> +#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/ObjectConstructor.h> +#include <LibJS/Runtime/ObjectPrototype.h> +#include <LibJS/Runtime/Shape.h> #include <LibJS/Runtime/StringConstructor.h> +#include <LibJS/Runtime/StringPrototype.h> #include <LibJS/Runtime/Value.h> namespace JS { @@ -53,8 +65,25 @@ void GlobalObject::add_constructor(const FlyString& property_name, ConstructorTy } GlobalObject::GlobalObject() - : Object(interpreter().object_prototype()) + : Object(nullptr) { +} + +void GlobalObject::initialize() +{ + // These are done first since other prototypes depend on their presence. + m_object_prototype = heap().allocate<ObjectPrototype>(); + m_function_prototype = heap().allocate<FunctionPrototype>(); + + static_cast<FunctionPrototype*>(m_function_prototype)->initialize(); + static_cast<ObjectPrototype*>(m_object_prototype)->initialize(); + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + if (!m_##snake_name##_prototype) \ + m_##snake_name##_prototype = heap().allocate<PrototypeName>(); + JS_ENUMERATE_BUILTIN_TYPES +#undef __JS_ENUMERATE + put_native_function("gc", gc); put_native_function("isNaN", is_nan, 1); @@ -67,17 +96,17 @@ GlobalObject::GlobalObject() put("console", heap().allocate<ConsoleObject>()); put("Math", heap().allocate<MathObject>()); - add_constructor("Array", m_array_constructor, *interpreter().array_prototype()); - add_constructor("Boolean", m_boolean_constructor, *interpreter().boolean_prototype()); - add_constructor("Date", m_date_constructor, *interpreter().date_prototype()); - add_constructor("Error", m_error_constructor, *interpreter().error_prototype()); - add_constructor("Function", m_function_constructor, *interpreter().function_prototype()); - add_constructor("Number", m_number_constructor, *interpreter().number_prototype()); - add_constructor("Object", m_object_constructor, *interpreter().object_prototype()); - add_constructor("String", m_string_constructor, *interpreter().string_prototype()); + add_constructor("Array", m_array_constructor, *m_array_prototype); + add_constructor("Boolean", m_boolean_constructor, *m_boolean_prototype); + add_constructor("Date", m_date_constructor, *m_date_prototype); + add_constructor("Error", m_error_constructor, *m_error_prototype); + add_constructor("Function", m_function_constructor, *m_function_prototype); + add_constructor("Number", m_number_constructor, *m_number_prototype); + add_constructor("Object", m_object_constructor, *m_object_prototype); + add_constructor("String", m_string_constructor, *m_string_prototype); #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - add_constructor(#ClassName, m_##snake_name##_constructor, *interpreter().snake_name##_prototype()); + add_constructor(#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 14f7bcf530..2f349dd86e 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Libraries/LibJS/Runtime/GlobalObject.h @@ -33,10 +33,13 @@ namespace JS { class GlobalObject : public Object { public: explicit GlobalObject(); + virtual void initialize(); + virtual ~GlobalObject() override; -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - ConstructorName* snake_name##_constructor() { return m_##snake_name##_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; } JS_ENUMERATE_BUILTIN_TYPES #undef __JS_ENUMERATE @@ -53,7 +56,8 @@ private: void add_constructor(const FlyString& property_name, ConstructorType*&, Object& prototype); #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - ConstructorName* m_##snake_name##_constructor { nullptr }; + ConstructorName* m_##snake_name##_constructor { nullptr }; \ + Object* m_##snake_name##_prototype { nullptr }; JS_ENUMERATE_BUILTIN_TYPES #undef __JS_ENUMERATE }; diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index fb3bd7fa99..a714123a3b 100644 --- a/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Libraries/LibJS/Runtime/MathObject.cpp @@ -27,13 +27,14 @@ #include <AK/FlyString.h> #include <AK/Function.h> #include <LibJS/Interpreter.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/MathObject.h> #include <math.h> namespace JS { MathObject::MathObject() - : Object(interpreter().object_prototype()) + : Object(interpreter().global_object().object_prototype()) { put_native_function("abs", abs, 1); put_native_function("random", random); diff --git a/Libraries/LibJS/Runtime/NativeFunction.cpp b/Libraries/LibJS/Runtime/NativeFunction.cpp index f0fe227216..3dd43660fc 100644 --- a/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -31,9 +31,9 @@ namespace JS { -NativeFunction* NativeFunction::create(Interpreter& interpreter, GlobalObject&, const FlyString& name, AK::Function<Value(Interpreter&)> function) +NativeFunction* NativeFunction::create(Interpreter&, GlobalObject& global_object, const FlyString& name, AK::Function<Value(Interpreter&)> function) { - return interpreter.heap().allocate<NativeFunction>(name, move(function), *interpreter.function_prototype()); + return global_object.heap().allocate<NativeFunction>(name, move(function), *global_object.function_prototype()); } NativeFunction::NativeFunction(Object& prototype) diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp index 0d7c08e873..1713253d0c 100644 --- a/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -26,6 +26,7 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Error.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/NumberConstructor.h> #include <LibJS/Runtime/NumberObject.h> #include <math.h> @@ -37,11 +38,11 @@ namespace JS { NumberConstructor::NumberConstructor() - : NativeFunction("Number", *interpreter().function_prototype()) + : NativeFunction("Number", *interpreter().global_object().function_prototype()) { put_native_function("isSafeInteger", is_safe_integer, 1); - put("prototype", interpreter().number_prototype()); + put("prototype", interpreter().global_object().number_prototype()); put("length", Value(1)); put("EPSILON", Value(EPSILON)); put("MAX_SAFE_INTEGER", Value(MAX_SAFE_INTEGER)); diff --git a/Libraries/LibJS/Runtime/NumberObject.cpp b/Libraries/LibJS/Runtime/NumberObject.cpp index c2432da33c..46fdf73052 100644 --- a/Libraries/LibJS/Runtime/NumberObject.cpp +++ b/Libraries/LibJS/Runtime/NumberObject.cpp @@ -35,8 +35,7 @@ namespace JS { NumberObject* NumberObject::create(GlobalObject& global_object, double value) { - auto& interpreter = global_object.interpreter(); - return interpreter.heap().allocate<NumberObject>(value, *interpreter.number_prototype()); + return global_object.heap().allocate<NumberObject>(value, *global_object.number_prototype()); } NumberObject::NumberObject(double value, Object& prototype) diff --git a/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Libraries/LibJS/Runtime/NumberPrototype.cpp index 9db8c33604..3d17abf394 100644 --- a/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -25,12 +25,13 @@ */ #include <LibJS/Interpreter.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/NumberPrototype.h> namespace JS { NumberPrototype::NumberPrototype() - : NumberObject(0, *interpreter().object_prototype()) + : NumberObject(0, *interpreter().global_object().object_prototype()) { } diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index f7ecb0b4a1..f35205dffc 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -38,9 +38,9 @@ namespace JS { -Object* Object::create_empty(Interpreter& interpreter, GlobalObject&) +Object* Object::create_empty(Interpreter&, GlobalObject& global_object) { - return interpreter.heap().allocate<Object>(interpreter.object_prototype()); + return global_object.heap().allocate<Object>(global_object.object_prototype()); } Object::Object(Object* prototype) diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index d18ef48353..d12dfbc355 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -29,15 +29,16 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Error.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/ObjectConstructor.h> #include <LibJS/Runtime/Shape.h> namespace JS { ObjectConstructor::ObjectConstructor() - : NativeFunction("Object", *interpreter().function_prototype()) + : NativeFunction("Object", *interpreter().global_object().function_prototype()) { - put("prototype", interpreter().object_prototype()); + put("prototype", interpreter().global_object().object_prototype()); put_native_function("defineProperty", define_property, 3); put_native_function("getOwnPropertyDescriptor", get_own_property_descriptor, 2); diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp index 4ad613850c..3086951a3a 100644 --- a/Libraries/LibJS/Runtime/ScriptFunction.cpp +++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp @@ -36,8 +36,7 @@ namespace JS { ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FlyString> parameters, LexicalEnvironment* parent_environment) { - auto& interpreter = global_object.interpreter(); - return interpreter.heap().allocate<ScriptFunction>(name, body, move(parameters), parent_environment, *interpreter.function_prototype()); + return global_object.heap().allocate<ScriptFunction>(name, body, move(parameters), parent_environment, *global_object.function_prototype()); } ScriptFunction::ScriptFunction(const FlyString& name, const Statement& body, Vector<FlyString> parameters, LexicalEnvironment* parent_environment, Object& prototype) diff --git a/Libraries/LibJS/Runtime/StringConstructor.cpp b/Libraries/LibJS/Runtime/StringConstructor.cpp index 53fc50e3d1..0858ceef2d 100644 --- a/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -26,6 +26,7 @@ #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Error.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/StringConstructor.h> #include <LibJS/Runtime/StringObject.h> #include <math.h> @@ -33,9 +34,9 @@ namespace JS { StringConstructor::StringConstructor() - : NativeFunction("String", *interpreter().function_prototype()) + : NativeFunction("String", *interpreter().global_object().function_prototype()) { - put("prototype", interpreter().string_prototype()); + put("prototype", interpreter().global_object().string_prototype()); put("length", Value(1)); } diff --git a/Libraries/LibJS/Runtime/StringObject.cpp b/Libraries/LibJS/Runtime/StringObject.cpp index 0be4afdfad..db14c40773 100644 --- a/Libraries/LibJS/Runtime/StringObject.cpp +++ b/Libraries/LibJS/Runtime/StringObject.cpp @@ -36,8 +36,7 @@ namespace JS { StringObject* StringObject::create(GlobalObject& global_object, PrimitiveString& primitive_string) { - auto& interpreter = global_object.interpreter(); - return interpreter.heap().allocate<StringObject>(primitive_string, *interpreter.string_prototype()); + return global_object.heap().allocate<StringObject>(primitive_string, *global_object.string_prototype()); } StringObject::StringObject(PrimitiveString& string, Object& prototype) diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index 146e0890d9..dac1f057c2 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -29,6 +29,7 @@ #include <LibJS/Heap/Heap.h> #include <LibJS/Interpreter.h> #include <LibJS/Runtime/Error.h> +#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/PrimitiveString.h> #include <LibJS/Runtime/StringObject.h> #include <LibJS/Runtime/StringPrototype.h> @@ -38,7 +39,7 @@ namespace JS { StringPrototype::StringPrototype() - : StringObject(*js_string(interpreter(), String::empty()), *interpreter().object_prototype()) + : StringObject(*js_string(interpreter(), String::empty()), *interpreter().global_object().object_prototype()) { put_native_property("length", length_getter, nullptr); put_native_function("charAt", char_at, 1); |