Skip to content

Commit

Permalink
Fix some generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jul 20, 2023
1 parent 75180c9 commit 55ee085
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions boa_engine/src/bytecompiler/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl ByteCompiler<'_, '_> {

self.emit_opcode(Opcode::SetReturnValue);
self.emit_opcode(Opcode::GeneratorResumeReturn);
self.r#return();

self.patch_jump(throw_method_undefined);
self.iterator_close(self.in_async_generator);
Expand Down
18 changes: 10 additions & 8 deletions boa_engine/src/bytecompiler/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ impl ByteCompiler<'_, '_> {
}
self.emit_opcode(Opcode::SetReturnValue);

// if !self.in_async_generator {
let actions = self.return_jump_record_actions();

JumpRecord::new(JumpRecordKind::Return, Self::DUMMY_LABEL, actions)
.perform_actions(u32::MAX, self);
// }

self.emit_opcode(Opcode::Return);
self.r#return();
}
Statement::Try(t) => self.compile_try(t, use_expr),
Statement::Expression(expr) => {
Expand All @@ -95,6 +88,15 @@ impl ByteCompiler<'_, '_> {
}
}

pub(crate) fn r#return(&mut self) {
let actions = self.return_jump_record_actions();

JumpRecord::new(JumpRecordKind::Return, Self::DUMMY_LABEL, actions)
.perform_actions(u32::MAX, self);

self.emit_opcode(Opcode::Return);
}

fn return_jump_record_actions(&self) -> Vec<JumpRecordAction> {
let mut actions = Vec::default();

Expand Down
1 change: 1 addition & 0 deletions boa_engine/src/bytecompiler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl ByteCompiler<'_, '_> {
self.emit_u8(u8::from(false));
self.emit_opcode(Opcode::GeneratorYield);
}

self.emit_opcode(Opcode::GeneratorNext);
}

Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Operation for GeneratorResumeReturn {
if context.vm.frame().generator_resume_kind == GeneratorResumeKind::Throw {
return Err(JsError::from_opaque(context.vm.pop()));
}
Return::execute(context)
Ok(CompletionType::Normal)
}
}

Expand Down

0 comments on commit 55ee085

Please sign in to comment.