Skip to content

Commit

Permalink
Implement generator execution (#1790)
Browse files Browse the repository at this point in the history
This Pull Request fixes/closes #1559.

It changes the following:

- Implement GeneratorFunction Objects
- Implement Generator Objects
- Implement generator execution in vm
- Create `FormalParameterList` to remove duplicate checks on function parameters 
- Refactor  `MethodDefinition` on object literals
  • Loading branch information
raskad committed Feb 27, 2022
1 parent f7fab07 commit 60e2294
Show file tree
Hide file tree
Showing 47 changed files with 2,303 additions and 941 deletions.
6 changes: 3 additions & 3 deletions boa_engine/src/builtins/function/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
object::{JsObject, ObjectData},
property::PropertyDescriptor,
symbol::{self, WellKnownSymbols},
syntax::ast::node::FormalParameter,
syntax::ast::node::FormalParameterList,
Context, JsValue,
};
use boa_gc::{Finalize, Gc, Trace};
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Arguments {
/// <https://tc39.es/ecma262/#sec-createmappedargumentsobject>
pub(crate) fn create_mapped_arguments_object(
func: &JsObject,
formals: &[FormalParameter],
formals: &FormalParameterList,
arguments_list: &[JsValue],
env: &Gc<DeclarativeEnvironment>,
context: &mut Context,
Expand Down Expand Up @@ -199,7 +199,7 @@ impl Arguments {

let mut bindings = FxHashMap::default();
let mut property_index = 0;
'outer: for formal in formals {
'outer: for formal in formals.parameters.iter() {
for name in formal.names() {
if property_index >= len {
break 'outer;
Expand Down
18 changes: 13 additions & 5 deletions boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ pub enum Function {
constructor: bool,
captures: Captures,
},
VmOrdinary {
Ordinary {
code: Gc<crate::vm::CodeBlock>,
environments: DeclarativeEnvironmentStack,
},
Generator {
code: Gc<crate::vm::CodeBlock>,
environments: DeclarativeEnvironmentStack,
},
Expand All @@ -192,7 +196,7 @@ impl Function {
pub fn is_constructor(&self) -> bool {
match self {
Self::Native { constructor, .. } | Self::Closure { constructor, .. } => *constructor,
Self::VmOrdinary { code, .. } => code.constructor,
Self::Ordinary { code, .. } | Self::Generator { code, .. } => code.constructor,
}
}
}
Expand Down Expand Up @@ -454,11 +458,15 @@ impl BuiltInFunctionObject {
},
Some(name),
) => Ok(format!("function {name}() {{\n [native Code]\n}}").into()),
(Function::VmOrdinary { .. }, Some(name)) if name.is_empty() => {
(Function::Ordinary { .. }, Some(name)) if name.is_empty() => {
Ok("[Function (anonymous)]".into())
}
(Function::VmOrdinary { .. }, Some(name)) => Ok(format!("[Function: {name}]").into()),
(Function::VmOrdinary { .. }, None) => Ok("[Function (anonymous)]".into()),
(Function::Ordinary { .. }, Some(name)) => Ok(format!("[Function: {name}]").into()),
(Function::Ordinary { .. }, None) => Ok("[Function (anonymous)]".into()),
(Function::Generator { .. }, Some(name)) => {
Ok(format!("[Function*: {}]", &name).into())
}
(Function::Generator { .. }, None) => Ok("[Function* (anonymous)]".into()),
_ => Ok("TODO".into()),
}
}
Expand Down
Loading

0 comments on commit 60e2294

Please sign in to comment.