From 06a362554520ef96ef97f79cca32b1bc0d421f9c Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 6 Nov 2020 18:56:54 +0000 Subject: 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. --- Libraries/LibJS/Runtime/GlobalObject.cpp | 2 ++ Libraries/LibJS/Tests/builtins/Object/Object.prototype.toString.js | 2 ++ 2 files changed, 4 insertions(+) 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(m_function_prototype)->initialize(*this); static_cast(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(*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]"); }); -- cgit v1.2.3