Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jul 8, 2023
1 parent 445f63d commit 7b84063
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
29 changes: 17 additions & 12 deletions boa_engine/src/bytecompiler/jump_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,23 +286,28 @@ impl ByteCompiler<'_, '_> {
}

if info.is_try_block() || info.finally() {
let handler_index = self.handlers.len() as u32;
let start_address = self.next_opcode_location();

// FIXME(HalidOdat): figure out value stack fp value.
let env_fp = self.current_open_environments_count;
self.handlers.push(Handler {
range: (start_address..u32::MAX),
handler: 0,
fp: 0,
env_fp,
});
info.handler_index = Some(handler_index);
info.handler_index = Some(self.push_handler());
}

self.jump_info.push(info);
}

pub(crate) fn push_handler(&mut self) -> u32 {
let handler_index = self.handlers.len() as u32;
let start_address = self.next_opcode_location();

// FIXME(HalidOdat): figure out value stack fp value.
let env_fp = self.current_open_environments_count;
self.handlers.push(Handler {
range: (start_address..u32::MAX),
handler: 0,
fp: 0,
env_fp,
});

handler_index
}

pub(crate) fn patch_handler(&mut self, end_address: u32, handler_address: u32) {
let info = self
.jump_info
Expand Down
31 changes: 31 additions & 0 deletions boa_engine/src/bytecompiler/statement/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ impl ByteCompiler<'_, '_> {
Some(self.emit_opcode_with_operand(Opcode::PushDeclarativeEnvironment))
};

let mut handler_index = None;
match for_of_loop.initializer() {
IterableLoopInitializer::Identifier(ref ident) => {
match self.set_mutable_binding(*ident) {
Expand All @@ -315,6 +316,7 @@ impl ByteCompiler<'_, '_> {
}
}
IterableLoopInitializer::Access(access) => {
handler_index = Some(self.push_handler());
self.access_set(
Access::Property { access },
false,
Expand Down Expand Up @@ -358,10 +360,39 @@ impl ByteCompiler<'_, '_> {
}
},
IterableLoopInitializer::Pattern(pattern) => {
handler_index = Some(self.push_handler());
self.compile_declaration_pattern(pattern, BindingOpcode::SetName);
}
}

// If the left-hand side is not a lexical binding and the assignment produces
// an error, the iterator should be closed and the error forwarded to the
// runtime.
if let Some(handler_index) = handler_index {
let end_address = self.next_opcode_location();

let exit = self.jump();
let handler_address = self.next_opcode_location();

self.emit_opcode(Opcode::Exception);

// NOTE: Capture throws of the iterator close and handle it.
{
let handler_index = self.push_handler();
self.iterator_close(for_of_loop.r#await());
let end_address = self.next_opcode_location();
self.handlers[handler_index as usize].handler = end_address;
self.handlers[handler_index as usize].range.end = end_address;
}

self.emit_opcode(Opcode::Throw);
self.patch_jump(exit);

let handler_index = handler_index as usize;
self.handlers[handler_index].handler = handler_address;
self.handlers[handler_index].range.end = end_address;
}

self.compile_stmt(for_of_loop.body(), use_expr, true);

if let Some(iteration_environment) = iteration_environment {
Expand Down
10 changes: 5 additions & 5 deletions boa_engine/src/bytecompiler/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ impl ByteCompiler<'_, '_> {
}
self.emit_opcode(Opcode::SetReturnValue);

if !self.in_async_generator {
let actions = self.return_jump_record_actions();
// 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);
}
JumpRecord::new(JumpRecordKind::Return, Self::DUMMY_LABEL, actions)
.perform_actions(u32::MAX, self);
// }

self.emit_opcode(Opcode::Return);
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ generate_impl! {
/// Iterator Stack: `iterator` **=>** `iterator`
IteratorValue,

/// - Gets the last iteration result of the current iterator record.
/// Gets the last iteration result of the current iterator record.
///
/// Stack: **=>** `result`
///
Expand Down

0 comments on commit 7b84063

Please sign in to comment.