mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibJS: Convert bind_this_value() to ThrowCompletionOr
Also add spec step comments to it while we're here.
This commit is contained in:
parent
0aa24f4ce5
commit
617d3cd3d3
4 changed files with 16 additions and 11 deletions
|
@ -378,9 +378,7 @@ Value SuperCall::execute(Interpreter& interpreter, GlobalObject& global_object)
|
||||||
auto& this_er = verify_cast<FunctionEnvironment>(get_this_environment(interpreter.vm()));
|
auto& this_er = verify_cast<FunctionEnvironment>(get_this_environment(interpreter.vm()));
|
||||||
|
|
||||||
// 8. Perform ? thisER.BindThisValue(result).
|
// 8. Perform ? thisER.BindThisValue(result).
|
||||||
this_er.bind_this_value(global_object, result);
|
TRY_OR_DISCARD(this_er.bind_this_value(global_object, result));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
// 9. Let F be thisER.[[FunctionObject]].
|
// 9. Let F be thisER.[[FunctionObject]].
|
||||||
// 10. Assert: F is an ECMAScript function object. (NOTE: This is implied by the strong C++ type.)
|
// 10. Assert: F is an ECMAScript function object. (NOTE: This is implied by the strong C++ type.)
|
||||||
|
|
|
@ -656,7 +656,7 @@ void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_
|
||||||
// 7. Assert: localEnv is a function Environment Record.
|
// 7. Assert: localEnv is a function Environment Record.
|
||||||
// 8. Assert: The next step never returns an abrupt completion because localEnv.[[ThisBindingStatus]] is not initialized.
|
// 8. Assert: The next step never returns an abrupt completion because localEnv.[[ThisBindingStatus]] is not initialized.
|
||||||
// 9. Return localEnv.BindThisValue(thisValue).
|
// 9. Return localEnv.BindThisValue(thisValue).
|
||||||
verify_cast<FunctionEnvironment>(local_env)->bind_this_value(global_object(), this_value);
|
MUST(verify_cast<FunctionEnvironment>(local_env)->bind_this_value(global_object(), this_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList ), https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
|
// 10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList ), https://tc39.es/ecma262/#sec-ordinarycallevaluatebody
|
||||||
|
|
|
@ -79,15 +79,22 @@ ThrowCompletionOr<Value> FunctionEnvironment::get_this_binding(GlobalObject& glo
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9.1.1.3.1 BindThisValue ( V ), https://tc39.es/ecma262/#sec-bindthisvalue
|
// 9.1.1.3.1 BindThisValue ( V ), https://tc39.es/ecma262/#sec-bindthisvalue
|
||||||
Value FunctionEnvironment::bind_this_value(GlobalObject& global_object, Value this_value)
|
ThrowCompletionOr<Value> FunctionEnvironment::bind_this_value(GlobalObject& global_object, Value this_value)
|
||||||
{
|
{
|
||||||
VERIFY(this_binding_status() != ThisBindingStatus::Lexical);
|
// 1. Assert: envRec.[[ThisBindingStatus]] is not lexical.
|
||||||
if (this_binding_status() == ThisBindingStatus::Initialized) {
|
VERIFY(m_this_binding_status != ThisBindingStatus::Lexical);
|
||||||
vm().throw_exception<ReferenceError>(global_object, ErrorType::ThisIsAlreadyInitialized);
|
|
||||||
return {};
|
// 2. If envRec.[[ThisBindingStatus]] is initialized, throw a ReferenceError exception.
|
||||||
}
|
if (m_this_binding_status == ThisBindingStatus::Initialized)
|
||||||
|
return vm().throw_completion<ReferenceError>(global_object, ErrorType::ThisIsAlreadyInitialized);
|
||||||
|
|
||||||
|
// 3. Set envRec.[[ThisValue]] to V.
|
||||||
m_this_value = this_value;
|
m_this_value = this_value;
|
||||||
|
|
||||||
|
// 4. Set envRec.[[ThisBindingStatus]] to initialized.
|
||||||
m_this_binding_status = ThisBindingStatus::Initialized;
|
m_this_binding_status = ThisBindingStatus::Initialized;
|
||||||
|
|
||||||
|
// 5. Return V.
|
||||||
return this_value;
|
return this_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
bool has_super_binding() const;
|
bool has_super_binding() const;
|
||||||
virtual bool has_this_binding() const override;
|
virtual bool has_this_binding() const override;
|
||||||
virtual ThrowCompletionOr<Value> get_this_binding(GlobalObject&) const override;
|
virtual ThrowCompletionOr<Value> get_this_binding(GlobalObject&) const override;
|
||||||
Value bind_this_value(GlobalObject&, Value);
|
ThrowCompletionOr<Value> bind_this_value(GlobalObject&, Value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_function_environment() const override { return true; }
|
virtual bool is_function_environment() const override { return true; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue