mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibJS: Make run_executable() return simple ThrowCompletionOr<Value>
We don't need to return two values; running an executable only ever produces a throw completion, or a normal completion, i.e a Value. This necessitated a few minor changes, such as adding a way to check if a JS::Cell is a GeneratorResult.
This commit is contained in:
parent
2f7797f854
commit
5706831328
Notes:
github-actions[bot]
2025-10-31 07:57:15 +00:00
Author: https://github.com/awesomekling
Commit: 5706831328
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6648
10 changed files with 37 additions and 51 deletions
|
|
@ -84,13 +84,13 @@ ThrowCompletionOr<GeneratorObject::IterationResult> GeneratorObject::execute(VM&
|
|||
// Loosely based on step 4 of https://tc39.es/ecma262/#sec-generatorstart mixed with https://tc39.es/ecma262/#sec-generatoryield at the end.
|
||||
|
||||
auto generated_value = [](Value value) -> Value {
|
||||
if (value.is_cell())
|
||||
if (value.is_cell() && value.as_cell().is_generator_result())
|
||||
return static_cast<GeneratorResult const&>(value.as_cell()).result();
|
||||
return value.is_special_empty_value() ? js_undefined() : value;
|
||||
};
|
||||
|
||||
auto generated_continuation = [&](Value value) -> Optional<size_t> {
|
||||
if (value.is_cell()) {
|
||||
if (value.is_cell() && value.as_cell().is_generator_result()) {
|
||||
auto number_value = static_cast<GeneratorResult const&>(value.as_cell()).continuation();
|
||||
if (number_value.is_null())
|
||||
return {};
|
||||
|
|
@ -108,11 +108,10 @@ ThrowCompletionOr<GeneratorObject::IterationResult> GeneratorObject::execute(VM&
|
|||
// We should never enter `execute` again after the generator is complete.
|
||||
VERIFY(next_block.has_value());
|
||||
|
||||
auto next_result = bytecode_interpreter.run_executable(vm.running_execution_context(), *m_generating_function->bytecode_executable(), next_block, compleion_cell);
|
||||
auto result_value = bytecode_interpreter.run_executable(vm.running_execution_context(), *m_generating_function->bytecode_executable(), next_block, compleion_cell);
|
||||
|
||||
vm.pop_execution_context();
|
||||
|
||||
auto result_value = move(next_result.value);
|
||||
if (result_value.is_throw_completion()) {
|
||||
// Uncaught exceptions disable the generator.
|
||||
m_generator_state = GeneratorState::Completed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue