From fd5c606a7b7905579e34b33aa213328db54efa1f Mon Sep 17 00:00:00 2001 From: Annika Date: Thu, 31 Dec 2020 14:13:50 -0800 Subject: [PATCH] StatementList: Rename `statements` to `items` (#1014) --- boa/src/syntax/ast/node/block/mod.rs | 8 ++++---- .../declaration/arrow_function_decl/mod.rs | 2 +- .../declaration/async_function_decl/mod.rs | 2 +- .../declaration/async_function_expr/mod.rs | 2 +- .../ast/node/declaration/function_decl/mod.rs | 2 +- .../ast/node/declaration/function_expr/mod.rs | 2 +- boa/src/syntax/ast/node/statement_list/mod.rs | 18 ++++++++---------- boa/src/syntax/ast/node/switch/mod.rs | 2 +- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/boa/src/syntax/ast/node/block/mod.rs b/boa/src/syntax/ast/node/block/mod.rs index 7e30149724..93bedf4816 100644 --- a/boa/src/syntax/ast/node/block/mod.rs +++ b/boa/src/syntax/ast/node/block/mod.rs @@ -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. @@ -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() { diff --git a/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs index a783234208..78702c7dc0 100644 --- a/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs @@ -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. diff --git a/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs index bb6fc85d8f..5078b5b294 100644 --- a/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs @@ -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. diff --git a/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs b/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs index 5e0e5e9905..056976f961 100644 --- a/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs +++ b/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs @@ -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. diff --git a/boa/src/syntax/ast/node/declaration/function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/function_decl/mod.rs index 5838cf4961..c7e024803b 100644 --- a/boa/src/syntax/ast/node/declaration/function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/function_decl/mod.rs @@ -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. diff --git a/boa/src/syntax/ast/node/declaration/function_expr/mod.rs b/boa/src/syntax/ast/node/declaration/function_expr/mod.rs index 8496697aab..f76bbd11d8 100644 --- a/boa/src/syntax/ast/node/declaration/function_expr/mod.rs +++ b/boa/src/syntax/ast/node/declaration/function_expr/mod.rs @@ -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. diff --git a/boa/src/syntax/ast/node/statement_list/mod.rs b/boa/src/syntax/ast/node/statement_list/mod.rs index 45cb3e93ec..17e299f899 100644 --- a/boa/src/syntax/ast/node/statement_list/mod.rs +++ b/boa/src/syntax/ast/node/statement_list/mod.rs @@ -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. @@ -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)?; @@ -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 => { @@ -83,7 +83,7 @@ impl Executable for StatementList { // Continue execution } } - if i + 1 == self.statements().len() { + if i + 1 == self.items().len() { obj = val; } } @@ -97,9 +97,7 @@ where T: Into>, { fn from(stm: T) -> Self { - Self { - statements: stm.into(), - } + Self { items: stm.into() } } } diff --git a/boa/src/syntax/ast/node/switch/mod.rs b/boa/src/syntax/ast/node/switch/mod.rs index f062a1a6db..f62de5ae10 100644 --- a/boa/src/syntax/ast/node/switch/mod.rs +++ b/boa/src/syntax/ast/node/switch/mod.rs @@ -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.