diff --git a/crates/dash_vm/src/eval.rs b/crates/dash_vm/src/eval.rs index 0ed35767..750ae14b 100644 --- a/crates/dash_vm/src/eval.rs +++ b/crates/dash_vm/src/eval.rs @@ -2,15 +2,15 @@ use dash_compiler::FunctionCompiler; use dash_lexer::Lexer; use dash_middle::compiler::StaticImportKind; use dash_middle::interner::sym; -use dash_optimizer::type_infer::name_res; use dash_optimizer::OptLevel; +use dash_optimizer::type_infer::name_res; use dash_parser::Parser; use crate::frame::Frame; use crate::localscope::LocalScope; use crate::value::object::{NamedObject, Object, PropertyValue}; use crate::value::{Root, Unrooted, Value}; -use crate::{throw, Vm}; +use crate::{Vm, throw}; #[derive(Debug)] pub enum EvalError { diff --git a/crates/dash_vm/src/js_std/generator.rs b/crates/dash_vm/src/js_std/generator.rs index fcd10560..d7788a9d 100644 --- a/crates/dash_vm/src/js_std/generator.rs +++ b/crates/dash_vm/src/js_std/generator.rs @@ -1,7 +1,7 @@ use std::mem; use crate::dispatch::HandleResult; -use crate::frame::{Frame, This}; +use crate::frame::Frame; use crate::localscope::LocalScope; use crate::throw; use crate::value::function::generator::{GeneratorIterator, GeneratorState}; @@ -18,14 +18,15 @@ pub fn next(cx: CallContext) -> Result { let generator = receiver_t::(cx.scope, &cx.this, "GeneratorIterator.prototype.next")?; let arg = cx.args.first().unwrap_or_undefined(); let frame = { - let (ip, old_stack, arguments, try_blocks) = match &mut *generator.state().borrow_mut() { + let (ip, old_stack, arguments, try_blocks, this) = match &mut *generator.state().borrow_mut() { GeneratorState::Finished => return create_generator_value(cx.scope, true, None), GeneratorState::Running { ip, stack, arguments, try_blocks, - } => (*ip, mem::take(stack), arguments.take(), mem::take(try_blocks)), + this, + } => (*ip, mem::take(stack), arguments.take(), mem::take(try_blocks), *this), }; let function = generator.function(); @@ -39,7 +40,7 @@ pub fn next(cx: CallContext) -> Result { let current_sp = cx.scope.stack_size(); cx.scope.try_extend_stack(old_stack).root_err(cx.scope)?; - let mut frame = Frame::from_function(This::Default, function, None, false, arguments); + let mut frame = Frame::from_function(this, function, None, false, arguments); frame.set_ip(ip); frame.set_sp(current_sp); @@ -99,6 +100,7 @@ pub fn next(cx: CallContext) -> Result { stack, arguments: frame.arguments, try_blocks, + this: frame.this, }); create_generator_value(cx.scope, false, Some(value)) diff --git a/crates/dash_vm/src/value/function/async.rs b/crates/dash_vm/src/value/function/async.rs index 9e06ae32..7beb088c 100644 --- a/crates/dash_vm/src/value/function/async.rs +++ b/crates/dash_vm/src/value/function/async.rs @@ -85,10 +85,7 @@ impl AsyncFunction { Ok(promise) } } - Err(value) => { - let promise = wrap_promise(scope, value); - Err(promise.into()) - } + Err(value) => Err(value.into()), } } } diff --git a/crates/dash_vm/src/value/function/generator.rs b/crates/dash_vm/src/value/function/generator.rs index 11c06884..1682e891 100644 --- a/crates/dash_vm/src/value/function/generator.rs +++ b/crates/dash_vm/src/value/function/generator.rs @@ -28,7 +28,7 @@ impl GeneratorFunction { &self, scope: &mut LocalScope, callee: ObjectId, - _this: This, + this: This, args: Vec, _new_target: Option, ) -> Result { @@ -50,7 +50,7 @@ impl GeneratorFunction { scope.stack.drain(sp..).collect::>() }; - let iter = GeneratorIterator::new(callee, scope, args, arguments, Vec::new()); + let iter = GeneratorIterator::new(callee, scope, args, arguments, Vec::new(), this); Ok(Value::object(scope.register(iter))) } } @@ -63,6 +63,7 @@ pub enum GeneratorState { stack: Vec, try_blocks: Vec, arguments: Option, + this: This, }, } @@ -84,10 +85,12 @@ unsafe impl Trace for GeneratorState { stack, arguments, try_blocks, + this, } => { stack.trace(cx); arguments.trace(cx); try_blocks.trace(cx); + this.trace(cx); } } } @@ -107,6 +110,7 @@ impl GeneratorIterator { stack: Vec, arguments: Option, try_blocks: Vec, + this: This, ) -> Self { Self { function, @@ -116,6 +120,7 @@ impl GeneratorIterator { stack, arguments, try_blocks, + this, }), } }