summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-03-17 22:45:54 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-18 01:12:12 +0100
commit599b2bee4a399ae30712010a4b6f4e792932b304 (patch)
treef732354e9c51c3f7b66eafa0624190213e08f355 /Userland/Libraries/LibJS
parent29964dc15261d18327b9e0cf3c6273bdf719363a (diff)
downloadserenity-599b2bee4a399ae30712010a4b6f4e792932b304.zip
LibJS: Tweak Interpreter::create() for more spec-likeness
Store a reference to the newly created execution context in an aptly named variable, rename global_this_value to just this_value, and only call set_global_object() in a single place.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Interpreter.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/Userland/Libraries/LibJS/Interpreter.h b/Userland/Libraries/LibJS/Interpreter.h
index 79ec10edb3..8d31526610 100644
--- a/Userland/Libraries/LibJS/Interpreter.h
+++ b/Userland/Libraries/LibJS/Interpreter.h
@@ -47,17 +47,18 @@ public:
// 1. Let realm be CreateRealm().
auto* realm = Realm::create(vm);
- // 2. Let newContext be a new execution context. (This was done in the Interpreter constructor)
+ // 2. Let newContext be a new execution context.
+ auto& new_context = interpreter->m_global_execution_context;
// 3. Set the Function of newContext to null. (This is done for us when the execution context is constructed)
// 4. Set the Realm of newContext to realm.
- interpreter->m_global_execution_context.realm = realm;
+ new_context.realm = realm;
// 5. Set the ScriptOrModule of newContext to null. (This was done during execution context construction)
// 6. Push newContext onto the execution context stack; newContext is now the running execution context.
- vm.push_execution_context(interpreter->m_global_execution_context);
+ vm.push_execution_context(new_context);
// 7. If the host requires use of an exotic object to serve as realm's global object, let global be such an object created in a host-defined manner.
// Otherwise, let global be undefined, indicating that an ordinary object should be created as the global object.
@@ -65,17 +66,17 @@ public:
// 8. If the host requires that the this binding in realm's global scope return an object other than the global object, let thisValue be such an object created
// in a host-defined manner. Otherwise, let thisValue be undefined, indicating that realm's global this binding should be the global object.
+ Object* this_value;
if constexpr (IsSame<GlobalObjectType, GlobalThisObjectType>) {
- // 9. Perform SetRealmGlobalObject(realm, global, thisValue).
- realm->set_global_object(*global_object, global_object);
+ this_value = global_object;
} else {
// FIXME: Should we pass args in here? Let's er on the side of caution and say yes.
- auto* global_this_value = static_cast<Object*>(interpreter->heap().allocate_without_global_object<GlobalThisObjectType>(forward<Args>(args)...));
-
- // 9. Perform SetRealmGlobalObject(realm, global, thisValue).
- realm->set_global_object(*global_object, global_this_value);
+ this_value = static_cast<Object*>(interpreter->heap().allocate_without_global_object<GlobalThisObjectType>(forward<Args>(args)...));
}
+ // 9. Perform SetRealmGlobalObject(realm, global, thisValue).
+ realm->set_global_object(*global_object, this_value);
+
// NOTE: These are not in the spec.
static FlyString global_execution_context_name = "(global execution context)";
interpreter->m_global_execution_context.function_name = global_execution_context_name;