LibJS: Add globalThis

We already have "global" as a way to access the global object in js(1)
(both REPL and script mode). This replaces it with "globalThis", which
is available in all environments, not just js.
This commit is contained in:
Linus Groh 2020-04-09 14:39:02 +01:00 committed by Andreas Kling
parent cbecb23e1d
commit c06a6c67d5
Notes: sideshowbarker 2024-07-19 07:46:53 +09:00
3 changed files with 2 additions and 3 deletions

View file

@ -61,6 +61,7 @@ GlobalObject::GlobalObject()
put("Infinity", js_infinity());
put("undefined", js_undefined());
put("globalThis", this);
put("console", heap().allocate<ConsoleObject>());
put("Math", heap().allocate<MathObject>());

View file

@ -1,6 +1,6 @@
try {
assert(typeof this === "object");
assert(this === global);
assert(this === globalThis);
function Foo() {
this.x = 5;

View file

@ -384,7 +384,6 @@ int main(int argc, char** argv)
if (script_path == nullptr) {
auto interpreter = JS::Interpreter::create<ReplObject>();
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<JS::GlobalObject>();
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);
}