diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-09 16:52:34 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-09 21:53:47 +0100 |
commit | 0aa24f4ce5e91b6f0b749d328be150322d4e9c14 (patch) | |
tree | 4e5725d444e665eaa147faca24dac10bb2b8fc96 /Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp | |
parent | 4f0313897131676b58ff2a5f374b35133e5cbb14 (diff) | |
download | serenity-0aa24f4ce5e91b6f0b749d328be150322d4e9c14.zip |
LibJS: Convert get_this_binding() to ThrowCompletionOr
Also add spec step comments to it while we're here.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp index 4668640b3c..60f76e8726 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.cpp @@ -65,13 +65,16 @@ bool FunctionEnvironment::has_super_binding() const } // 9.1.1.3.4 GetThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding -Value FunctionEnvironment::get_this_binding(GlobalObject& global_object) const +ThrowCompletionOr<Value> FunctionEnvironment::get_this_binding(GlobalObject& global_object) const { - VERIFY(has_this_binding()); - if (this_binding_status() == ThisBindingStatus::Uninitialized) { - vm().throw_exception<ReferenceError>(global_object, ErrorType::ThisHasNotBeenInitialized); - return {}; - } + // 1. Assert: envRec.[[ThisBindingStatus]] is not lexical. + VERIFY(m_this_binding_status != ThisBindingStatus::Lexical); + + // 2. If envRec.[[ThisBindingStatus]] is uninitialized, throw a ReferenceError exception. + if (m_this_binding_status == ThisBindingStatus::Uninitialized) + return vm().throw_completion<ReferenceError>(global_object, ErrorType::ThisHasNotBeenInitialized); + + // 3. Return envRec.[[ThisValue]]. return m_this_value; } |