Skip to content

Commit

Permalink
mergeup
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump committed Mar 8, 2022
2 parents 052aae3 + 44b5617 commit 58fd56a
Show file tree
Hide file tree
Showing 32 changed files with 868 additions and 127 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ jobs:
~/.cargo/git
~/.cargo/registry
key: ${{ runner.os }}-cargo-examples-${{ hashFiles('**/Cargo.lock') }}
- run: cd boa_examples
- name: Build examples
uses: actions-rs/cargo@v1
with:
command: build
args: --examples -v
- name: Run example classes
uses: actions-rs/cargo@v1
with:
command: run
args: --example classes
args: --bin classes

doc:
name: Documentation
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ jobs:
~/.cargo/git
~/.cargo/registry
key: ${{ runner.os }}-cargo-examples-${{ hashFiles('**/Cargo.lock') }}
- run: cd boa_examples
- name: Build examples
uses: actions-rs/cargo@v1
with:
command: build
args: --examples -v
- name: Run example classes
uses: actions-rs/cargo@v1
with:
command: run
args: --example classes
args: --bin classes

doc:
name: Documentation
Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"boa_tester",
"boa_unicode",
"boa_wasm",
"boa_examples",
]

# The release profile, used for `cargo build --release`.
Expand Down
224 changes: 154 additions & 70 deletions boa_engine/src/bytecompiler.rs

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions boa_engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,8 @@ impl Context {
pub fn compile(&mut self, statement_list: &StatementList) -> JsResult<Gc<CodeBlock>> {
let _timer = Profiler::global().start_event("Compilation", "Main");
let mut compiler = ByteCompiler::new(Sym::MAIN, statement_list.strict(), self);
for node in statement_list.items() {
compiler.create_declarations(node)?;
}
compiler.compile_statement_list(statement_list, true)?;
compiler.create_declarations(statement_list.items())?;
compiler.compile_statement_list(statement_list.items(), true)?;
Ok(Gc::new(compiler.finish()))
}

Expand Down
25 changes: 24 additions & 1 deletion boa_engine/src/syntax/ast/node/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ mod tests;
pub struct ArrayDecl {
#[cfg_attr(feature = "deser", serde(flatten))]
arr: Box<[Node]>,
has_trailing_comma_spread: bool,
}

impl ArrayDecl {
/// Crate a new array declaration.
pub(crate) fn new<A>(array: A, has_trailing_comma_spread: bool) -> Self
where
A: Into<Box<[Node]>>,
{
Self {
arr: array.into(),
has_trailing_comma_spread,
}
}

/// Indicates if a spread operator in the array literal has a trailing comma.
/// This is a syntax error in some cases.
pub(crate) fn has_trailing_comma_spread(&self) -> bool {
self.has_trailing_comma_spread
}
}

impl AsRef<[Node]> for ArrayDecl {
Expand All @@ -44,7 +64,10 @@ where
T: Into<Box<[Node]>>,
{
fn from(decl: T) -> Self {
Self { arr: decl.into() }
Self {
arr: decl.into(),
has_trailing_comma_spread: false,
}
}
}

Expand Down
100 changes: 93 additions & 7 deletions boa_engine/src/syntax/ast/node/declaration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Declaration nodes
use crate::syntax::ast::node::{join_nodes, Identifier, Node};
use crate::syntax::ast::node::{
field::{GetConstField, GetField},
join_nodes,
statement_list::StatementList,
Identifier, Node,
};
use boa_gc::{Finalize, Trace};
use boa_interner::{Interner, Sym, ToInternedString};

Expand All @@ -23,8 +28,6 @@ pub use self::{
function_expr::FunctionExpr,
};

use super::StatementList;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -337,10 +340,12 @@ impl DeclarationPatternObject {
let mut idents = Vec::new();

for binding in &self.bindings {
use BindingPatternTypeObject::{BindingPattern, Empty, RestProperty, SingleName};
use BindingPatternTypeObject::{
BindingPattern, Empty, RestGetConstField, RestProperty, SingleName,
};

match binding {
Empty => {}
Empty | RestGetConstField { .. } => {}
SingleName {
ident,
property_name: _,
Expand Down Expand Up @@ -437,11 +442,17 @@ impl DeclarationPatternArray {

for binding in &self.bindings {
use BindingPatternTypeArray::{
BindingPattern, BindingPatternRest, Elision, Empty, SingleName, SingleNameRest,
BindingPattern, BindingPatternRest, Elision, Empty, GetConstField,
GetConstFieldRest, GetField, GetFieldRest, SingleName, SingleNameRest,
};

match binding {
Empty | Elision => {}
Empty
| Elision
| GetField { .. }
| GetConstField { .. }
| GetFieldRest { .. }
| GetConstFieldRest { .. } => {}
SingleName {
ident,
default_init: _,
Expand Down Expand Up @@ -500,6 +511,20 @@ pub enum BindingPatternTypeObject {
/// [spec1]: https://tc39.es/ecma262/#prod-BindingRestProperty
RestProperty { ident: Sym, excluded_keys: Vec<Sym> },

/// RestGetConstField represents a rest property (spread operator) with a property accessor.
///
/// Note: According to the spec this is not part of an ObjectBindingPattern.
/// This is only used when a object literal is used as the left-hand-side of an assignment expression.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression
RestGetConstField {
get_const_field: GetConstField,
excluded_keys: Vec<Sym>,
},

/// BindingPattern represents a `BindingProperty` with a `BindingPattern` as the `BindingElement`.
///
/// Additionally to the identifier of the new property and the nested binding pattern,
Expand Down Expand Up @@ -545,6 +570,11 @@ impl ToInternedString for BindingPatternTypeObject {
} => {
format!(" ... {}", interner.resolve_expect(*property_name))
}
BindingPatternTypeObject::RestGetConstField {
get_const_field, ..
} => {
format!(" ... {}", get_const_field.to_interned_string(interner))
}
BindingPatternTypeObject::BindingPattern {
ident: property_name,
pattern,
Expand Down Expand Up @@ -606,6 +636,28 @@ pub enum BindingPatternTypeArray {
default_init: Option<Node>,
},

/// GetField represents a binding with a property accessor.
///
/// Note: According to the spec this is not part of an ArrayBindingPattern.
/// This is only used when a array literal is used as the left-hand-side of an assignment expression.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression
GetField { get_field: GetField },

/// GetConstField represents a binding with a property accessor.
///
/// Note: According to the spec this is not part of an ArrayBindingPattern.
/// This is only used when a array literal is used as the left-hand-side of an assignment expression.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression
GetConstField { get_const_field: GetConstField },

/// BindingPattern represents a `BindingPattern` in a `BindingElement` of an array binding pattern.
///
/// The pattern and the optional default initializer are both stored in the DeclarationPattern.
Expand All @@ -624,6 +676,28 @@ pub enum BindingPatternTypeArray {
/// [spec1]: https://tc39.es/ecma262/#prod-BindingRestElement
SingleNameRest { ident: Sym },

/// GetFieldRest represents a rest binding (spread operator) with a property accessor.
///
/// Note: According to the spec this is not part of an ArrayBindingPattern.
/// This is only used when a array literal is used as the left-hand-side of an assignment expression.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression
GetFieldRest { get_field: GetField },

/// GetConstFieldRest represents a rest binding (spread operator) with a property accessor.
///
/// Note: According to the spec this is not part of an ArrayBindingPattern.
/// This is only used when a array literal is used as the left-hand-side of an assignment expression.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression
GetConstFieldRest { get_const_field: GetConstField },

/// SingleNameRest represents a `BindingPattern` in a `BindingRestElement` of an array binding pattern.
///
/// More information:
Expand All @@ -648,12 +722,24 @@ impl ToInternedString for BindingPatternTypeArray {
}
buf
}
BindingPatternTypeArray::GetField { get_field } => {
format!(" {}", get_field.to_interned_string(interner))
}
BindingPatternTypeArray::GetConstField { get_const_field } => {
format!(" {}", get_const_field.to_interned_string(interner))
}
BindingPatternTypeArray::BindingPattern { pattern } => {
format!(" {}", pattern.to_interned_string(interner))
}
BindingPatternTypeArray::SingleNameRest { ident } => {
format!(" ... {}", interner.resolve_expect(*ident))
}
BindingPatternTypeArray::GetFieldRest { get_field } => {
format!(" ... {}", get_field.to_interned_string(interner))
}
BindingPatternTypeArray::GetConstFieldRest { get_const_field } => {
format!(" ... {}", get_const_field.to_interned_string(interner))
}
BindingPatternTypeArray::BindingPatternRest { pattern } => {
format!(" ... {}", pattern.to_interned_string(interner))
}
Expand Down
8 changes: 7 additions & 1 deletion boa_engine/src/syntax/ast/node/iteration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pub use self::{
break_node::Break, continue_node::Continue, do_while_loop::DoWhileLoop, for_in_loop::ForInLoop,
for_loop::ForLoop, for_of_loop::ForOfLoop, while_loop::WhileLoop,
};
use crate::syntax::ast::node::{declaration::Declaration, identifier::Identifier};
use crate::syntax::ast::node::{
declaration::Declaration, identifier::Identifier, DeclarationPattern,
};
use boa_gc::{Finalize, Trace};
use boa_interner::{Interner, ToInternedString};

Expand All @@ -21,6 +23,7 @@ pub enum IterableLoopInitializer {
Var(Declaration),
Let(Declaration),
Const(Declaration),
DeclarationPattern(DeclarationPattern),
}

impl ToInternedString for IterableLoopInitializer {
Expand All @@ -38,6 +41,9 @@ impl ToInternedString for IterableLoopInitializer {
IterableLoopInitializer::Const(declaration) => {
format!("const {}", declaration.to_interned_string(interner))
}
IterableLoopInitializer::DeclarationPattern(declaration) => {
declaration.to_interned_string(interner)
}
}
}
}
Expand Down
Loading

0 comments on commit 58fd56a

Please sign in to comment.