Skip to content

Commit

Permalink
LibJS/Bytecode: Propagate FunctionDeclarationInstantiation exceptions
Browse files Browse the repository at this point in the history
If an exception is thrown by FunctionDeclarationInstantiation for an
async or async-generator function, we still need to return a promise.
We can't just throw the exception.

81 new passes on test262. :^)
  • Loading branch information
awesomekling authored and gmta committed Jun 26, 2023
1 parent 57404ba commit 9430bbc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,22 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
}
}

TRY(function_declaration_instantiation(nullptr));
auto declaration_result = function_declaration_instantiation(nullptr);

if (!m_bytecode_executable) {
if (m_kind == FunctionKind::Normal || m_kind == FunctionKind::Generator) {
if (declaration_result.is_error())
return declaration_result.release_error();
}

if (!m_bytecode_executable)
m_bytecode_executable = TRY(Bytecode::compile(vm, *m_ecmascript_code, m_kind, m_name));

if (m_kind == FunctionKind::Async || m_kind == FunctionKind::AsyncGenerator) {
if (declaration_result.is_throw_completion()) {
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
MUST(call(vm, *promise_capability->reject(), js_undefined(), *declaration_result.throw_completion().value()));
return Completion { Completion::Type::Return, promise_capability->promise(), {} };
}
}

auto result_and_frame = bytecode_interpreter->run_and_return_frame(realm, *m_bytecode_executable, nullptr);
Expand Down

0 comments on commit 9430bbc

Please sign in to comment.