Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatementList: Rename statements to items #1014

Merged
merged 2 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions boa/src/syntax/ast/node/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub struct Block {
}

impl Block {
/// Gets the list of statements in this block.
pub(crate) fn statements(&self) -> &[Node] {
self.statements.statements()
/// Gets the list of statements and declarations in this block.
pub(crate) fn items(&self) -> &[Node] {
self.statements.items()
}

/// Implements the display formatting with indentation.
Expand All @@ -63,7 +63,7 @@ impl Executable for Block {
// https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
// The return value is uninitialized, which means it defaults to Value::Undefined
let mut obj = Value::default();
for statement in self.statements() {
for statement in self.items() {
obj = statement.run(context)?;

match context.executor().get_current_state() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ArrowFunctionDecl {

/// Gets the body of the arrow function.
pub(crate) fn body(&self) -> &[Node] {
&self.body.statements()
&self.body.items()
}

/// Implements the display formatting with indentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl AsyncFunctionDecl {

/// Gets the body of the async function declaration.
pub fn body(&self) -> &[Node] {
self.body.statements()
self.body.items()
}

/// Implements the display formatting with indentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl AsyncFunctionExpr {

/// Gets the body of the function declaration.
pub fn body(&self) -> &[Node] {
self.body.statements()
self.body.items()
}

/// Implements the display formatting with indentation.
Expand Down
2 changes: 1 addition & 1 deletion boa/src/syntax/ast/node/declaration/function_decl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl FunctionDecl {

/// Gets the body of the function declaration.
pub fn body(&self) -> &[Node] {
self.body.statements()
self.body.items()
}

/// Implements the display formatting with indentation.
Expand Down
2 changes: 1 addition & 1 deletion boa/src/syntax/ast/node/declaration/function_expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FunctionExpr {

/// Gets the body of the function declaration.
pub fn body(&self) -> &[Node] {
self.body.statements()
self.body.items()
}

/// Implements the display formatting with indentation.
Expand Down
18 changes: 8 additions & 10 deletions boa/src/syntax/ast/node/statement_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Trace, Finalize, PartialEq)]
pub struct StatementList {
#[cfg_attr(feature = "deser", serde(flatten))]
statements: Box<[Node]>,
items: Box<[Node]>,
}

impl StatementList {
/// Gets the list of statements.
pub fn statements(&self) -> &[Node] {
&self.statements
/// Gets the list of items.
pub fn items(&self) -> &[Node] {
&self.items
}

/// Implements the display formatting with indentation.
Expand All @@ -40,7 +40,7 @@ impl StatementList {
) -> fmt::Result {
let indent = " ".repeat(indentation);
// Print statements
for node in self.statements.iter() {
for node in self.items.iter() {
f.write_str(&indent)?;
node.display(f, indentation + 1)?;

Expand All @@ -64,7 +64,7 @@ impl Executable for StatementList {
context
.executor()
.set_current_state(InterpreterState::Executing);
for (i, item) in self.statements().iter().enumerate() {
for (i, item) in self.items().iter().enumerate() {
let val = item.run(context)?;
match context.executor().get_current_state() {
InterpreterState::Return => {
Expand All @@ -83,7 +83,7 @@ impl Executable for StatementList {
// Continue execution
}
}
if i + 1 == self.statements().len() {
if i + 1 == self.items().len() {
obj = val;
}
}
Expand All @@ -97,9 +97,7 @@ where
T: Into<Box<[Node]>>,
{
fn from(stm: T) -> Self {
Self {
statements: stm.into(),
}
Self { items: stm.into() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa/src/syntax/ast/node/switch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Switch {

/// Gets the default statement list, if any.
pub fn default(&self) -> Option<&[Node]> {
self.default.as_ref().map(StatementList::statements)
self.default.as_ref().map(StatementList::items)
}

/// Implements the display formatting with indentation.
Expand Down