Skip to content

Commit

Permalink
Remove yield flag
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jul 12, 2023
1 parent 089d106 commit 2927ab4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
3 changes: 0 additions & 3 deletions boa_engine/src/vm/call_frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ pub struct CallFrame {
pub(crate) pc: u32,
pub(crate) fp: u32,
pub(crate) env_fp: u32,
#[unsafe_ignore_trace]
pub(crate) r#yield: bool,
// Tracks the number of environments in environment entry.
// On abrupt returns this is used to decide how many environments need to be pop'ed.
pub(crate) argument_count: u32,
Expand Down Expand Up @@ -65,7 +63,6 @@ impl CallFrame {
pc: 0,
fp: 0,
env_fp: 0,
r#yield: false,
argument_count: 0,
generator_resume_kind: GeneratorResumeKind::Normal,
promise_capability: None,
Expand Down
14 changes: 7 additions & 7 deletions boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub(crate) enum CompletionType {
Normal,
Return,
Throw,
Yield,
}

impl Context<'_> {
Expand Down Expand Up @@ -290,6 +291,11 @@ impl Context<'_> {
Ok(CompletionType::Throw) => {
break CompletionType::Throw;
}
// Early return immediately.
Ok(CompletionType::Yield) => {
let result = self.vm.pop();
return CompletionRecord::Return(result);
}
Err(err) => {
#[cfg(feature = "fuzz")]
{
Expand Down Expand Up @@ -327,13 +333,6 @@ impl Context<'_> {
}
};

// Early return immediately after loop.
if self.vm.frame().r#yield {
self.vm.frame_mut().r#yield = false;
let result = self.vm.pop();
return CompletionRecord::Return(result);
}

#[cfg(feature = "trace")]
if self.vm.trace {
println!("\nStack:");
Expand Down Expand Up @@ -385,6 +384,7 @@ impl Context<'_> {
.expect("cannot fail per spec");
self.vm.err = Some(err);
}
CompletionType::Yield => unreachable!(),
}
} else if let Some(generator_object) = self.vm.frame().async_generator.clone() {
// Step 3.e-g in [AsyncGeneratorStart](https://tc39.es/ecma262/#sec-asyncgeneratorstart)
Expand Down
3 changes: 1 addition & 2 deletions boa_engine/src/vm/opcode/await_stm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ impl Operation for Await {
);

context.vm.push(JsValue::undefined());
context.vm.frame_mut().r#yield = true;
Ok(CompletionType::Return)
Ok(CompletionType::Yield)
}
}
5 changes: 2 additions & 3 deletions boa_engine/src/vm/opcode/generator/yield_stm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ impl Operation for GeneratorYield {
const NAME: &'static str = "GeneratorYield";
const INSTRUCTION: &'static str = "INST - GeneratorYield";

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
context.vm.frame_mut().r#yield = true;
Ok(CompletionType::Return)
fn execute(_context: &mut Context<'_>) -> JsResult<CompletionType> {
Ok(CompletionType::Yield)
}
}

Expand Down

0 comments on commit 2927ab4

Please sign in to comment.