From 19ea0d8dcf7b0b34c483c81f5c547e9521db7986 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 12 Dec 2022 21:17:24 +0000 Subject: [PATCH] LibJS: Add spec comments to get_this_environment() --- Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 739dbac45d..48b09df586 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -445,9 +445,17 @@ PrivateEnvironment* new_private_environment(VM& vm, PrivateEnvironment* outer) // 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment Environment& get_this_environment(VM& vm) { + // 1. Let env be the running execution context's LexicalEnvironment. + // 2. Repeat, for (auto* env = vm.lexical_environment(); env; env = env->outer_environment()) { + // a. Let exists be env.HasThisBinding(). + // b. If exists is true, return env. if (env->has_this_binding()) return *env; + + // c. Let outer be env.[[OuterEnv]]. + // d. Assert: outer is not null. + // e. Set env to outer. } VERIFY_NOT_REACHED(); }