diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp index 1ca293e6ab..65142ad7a7 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -61,6 +61,7 @@ GlobalObject::GlobalObject() put("Infinity", js_infinity()); put("undefined", js_undefined()); + put("globalThis", this); put("console", heap().allocate()); put("Math", heap().allocate()); diff --git a/Libraries/LibJS/Tests/function-this-in-arguments.js b/Libraries/LibJS/Tests/function-this-in-arguments.js index efa8d6bfea..0bfa3de834 100644 --- a/Libraries/LibJS/Tests/function-this-in-arguments.js +++ b/Libraries/LibJS/Tests/function-this-in-arguments.js @@ -1,6 +1,6 @@ try { assert(typeof this === "object"); - assert(this === global); + assert(this === globalThis); function Foo() { this.x = 5; diff --git a/Userland/js.cpp b/Userland/js.cpp index f9f2a5c22d..cf8c5d804c 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -384,7 +384,6 @@ int main(int argc, char** argv) if (script_path == nullptr) { auto interpreter = JS::Interpreter::create(); interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation); - interpreter->global_object().put("global", &interpreter->global_object()); if (test_mode) { interpreter->global_object().put_native_function("assert", assert_impl); } @@ -515,7 +514,6 @@ int main(int argc, char** argv) } else { auto interpreter = JS::Interpreter::create(); interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation); - interpreter->global_object().put("global", &interpreter->global_object()); if (test_mode) { interpreter->global_object().put_native_function("assert", assert_impl); }