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:
parent
cbecb23e1d
commit
c06a6c67d5
Notes:
sideshowbarker
2024-07-19 07:46:53 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/c06a6c67d5d Pull-request: https://github.com/SerenityOS/serenity/pull/1711
3 changed files with 2 additions and 3 deletions
|
@ -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>());
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
try {
|
||||
assert(typeof this === "object");
|
||||
assert(this === global);
|
||||
assert(this === globalThis);
|
||||
|
||||
function Foo() {
|
||||
this.x = 5;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue