summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-11-06 18:56:54 +0000
committerAndreas Kling <kling@serenityos.org>2020-11-07 10:08:05 +0100
commit06a362554520ef96ef97f79cca32b1bc0d421f9c (patch)
tree8e652a4537ac85e01228f680717da3c8c8311ee7
parent965050796f901fb28696e83574568db20e3b7b2b (diff)
downloadserenity-06a362554520ef96ef97f79cca32b1bc0d421f9c.zip
LibJS: Set prototype of GlobalObject to ObjectPrototype
As the global object is constructed and initialized in a different way than most other objects we were not setting its prototype! This made things like "globalThis.toString()" fail unexpectedly.
-rw-r--r--Libraries/LibJS/Runtime/GlobalObject.cpp2
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js2
2 files changed, 4 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp
index 6b6cfa68fd..9d49598464 100644
--- a/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -94,6 +94,8 @@ void GlobalObject::initialize()
static_cast<FunctionPrototype*>(m_function_prototype)->initialize(*this);
static_cast<ObjectPrototype*>(m_object_prototype)->initialize(*this);
+ set_prototype(m_object_prototype);
+
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
if (!m_##snake_name##_prototype) \
m_##snake_name##_prototype = heap().allocate<PrototypeName>(*this, *this);
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js
index c5d6d77b0e..5bdd157de4 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js
@@ -15,4 +15,6 @@ test("result for various object types", () => {
expect(oToString(new Date())).toBe("[object Date]");
expect(oToString(new RegExp())).toBe("[object RegExp]");
expect(oToString({})).toBe("[object Object]");
+
+ expect(globalThis.toString()).toBe("[object Object]");
});