LibJS: Make more use of Value::is and Value::as_if in JS runtime

This commit is contained in:
Timothy Flynn
2026-02-27 10:05:55 -05:00
committed by Shannon Booth
parent cadba4c0e7
commit d7e828a366
Notes: github-actions[bot] 2026-02-27 16:20:55 +00:00
31 changed files with 109 additions and 145 deletions

View File

@@ -136,14 +136,13 @@ void AsyncFunctionDriverWrapper::continue_async_execution(VM& vm, Value value, b
auto promise_value = result.value;
if (result.done) {
// When returning a promise, we need to unwrap it.
if (promise_value.is_object() && is<Promise>(promise_value.as_object())) {
auto& returned_promise = static_cast<Promise&>(promise_value.as_object());
if (returned_promise.state() == Promise::State::Fulfilled) {
m_top_level_promise->fulfill(returned_promise.result());
if (auto returned_promise = promise_value.as_if<Promise>()) {
if (returned_promise->state() == Promise::State::Fulfilled) {
m_top_level_promise->fulfill(returned_promise->result());
return {};
}
if (returned_promise.state() == Promise::State::Rejected)
return throw_completion(returned_promise.result());
if (returned_promise->state() == Promise::State::Rejected)
return throw_completion(returned_promise->result());
// The promise is still pending but there's nothing more to do here.
return {};