From 2927ab4482133aca3e059015b6057a9ea7886d97 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Wed, 12 Jul 2023 21:22:53 +0200 Subject: [PATCH] Remove yield flag --- boa_engine/src/vm/call_frame/mod.rs | 3 --- boa_engine/src/vm/mod.rs | 14 +++++++------- boa_engine/src/vm/opcode/await_stm/mod.rs | 3 +-- boa_engine/src/vm/opcode/generator/yield_stm.rs | 5 ++--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/boa_engine/src/vm/call_frame/mod.rs b/boa_engine/src/vm/call_frame/mod.rs index b2315f34bc7..470a26581b8 100644 --- a/boa_engine/src/vm/call_frame/mod.rs +++ b/boa_engine/src/vm/call_frame/mod.rs @@ -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, @@ -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, diff --git a/boa_engine/src/vm/mod.rs b/boa_engine/src/vm/mod.rs index 9962270fe5b..235c01bc398 100644 --- a/boa_engine/src/vm/mod.rs +++ b/boa_engine/src/vm/mod.rs @@ -154,6 +154,7 @@ pub(crate) enum CompletionType { Normal, Return, Throw, + Yield, } impl Context<'_> { @@ -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")] { @@ -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:"); @@ -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) diff --git a/boa_engine/src/vm/opcode/await_stm/mod.rs b/boa_engine/src/vm/opcode/await_stm/mod.rs index 6296da9294a..25c92b767de 100644 --- a/boa_engine/src/vm/opcode/await_stm/mod.rs +++ b/boa_engine/src/vm/opcode/await_stm/mod.rs @@ -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) } } diff --git a/boa_engine/src/vm/opcode/generator/yield_stm.rs b/boa_engine/src/vm/opcode/generator/yield_stm.rs index 8f545de58da..708e724d78e 100644 --- a/boa_engine/src/vm/opcode/generator/yield_stm.rs +++ b/boa_engine/src/vm/opcode/generator/yield_stm.rs @@ -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 { - context.vm.frame_mut().r#yield = true; - Ok(CompletionType::Return) + fn execute(_context: &mut Context<'_>) -> JsResult { + Ok(CompletionType::Yield) } }