diff --git a/boa/src/exec/call/mod.rs b/boa/src/exec/call/mod.rs index 363c165327a..173f79d11b7 100644 --- a/boa/src/exec/call/mod.rs +++ b/boa/src/exec/call/mod.rs @@ -8,6 +8,7 @@ use crate::{ impl Executable for Call { fn run(&self, interpreter: &mut Interpreter) -> ResultValue { let _timer = BoaProfiler::global().start_event("Call", "exec"); + let (this, func) = match self.expr() { Node::GetConstField(ref get_const_field) => { let mut obj = get_const_field.obj().run(interpreter)?; diff --git a/boa/src/exec/new/mod.rs b/boa/src/exec/new/mod.rs index b611b617aac..cc1a19ee5af 100644 --- a/boa/src/exec/new/mod.rs +++ b/boa/src/exec/new/mod.rs @@ -11,10 +11,6 @@ use crate::{ impl Executable for New { fn run(&self, interpreter: &mut Interpreter) -> ResultValue { let _timer = BoaProfiler::global().start_event("New", "exec"); - // let (callee, args) = match call.as_ref() { - // Node::Call(callee, args) => (callee, args), - // _ => unreachable!("Node::New(ref call): 'call' must only be Node::Call type."), - // }; let func_object = self.expr().run(interpreter)?; let mut v_args = Vec::with_capacity(self.args().len()); diff --git a/boa/src/syntax/ast/node/expression.rs b/boa/src/syntax/ast/node/call.rs similarity index 55% rename from boa/src/syntax/ast/node/expression.rs rename to boa/src/syntax/ast/node/call.rs index 5c2b8ae12f6..f8061087b83 100644 --- a/boa/src/syntax/ast/node/expression.rs +++ b/boa/src/syntax/ast/node/call.rs @@ -1,5 +1,3 @@ -//! Expression nodes. - use super::{join_nodes, Node}; use gc::{Finalize, Trace}; use std::fmt; @@ -65,54 +63,3 @@ impl From for Node { Self::Call(call) } } - -/// The `new` operator lets developers create an instance of a user-defined object type or of -/// one of the built-in object types that has a constructor function. -/// -/// The new keyword does the following things: -/// - Creates a blank, plain JavaScript object; -/// - Links (sets the constructor of) this object to another object; -/// - Passes the newly created object from Step 1 as the this context; -/// - Returns this if the function doesn't return its own object. -/// -/// More information: -/// - [ECMAScript reference][spec] -/// - [MDN documentation][mdn] -/// -/// [spec]: https://tc39.es/ecma262/#prod-NewExpression -/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Clone, Debug, Trace, Finalize, PartialEq)] -pub struct New { - call: Call, -} - -impl New { - /// Gets the name of the function call. - pub fn expr(&self) -> &Node { - &self.call.expr() - } - - /// Retrieves the arguments passed to the function. - pub fn args(&self) -> &[Node] { - &self.call.args() - } -} - -impl From for New { - fn from(call: Call) -> Self { - Self { call } - } -} - -impl fmt::Display for New { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "new {}", self.call) - } -} - -impl From for Node { - fn from(new: New) -> Self { - Self::New(new) - } -} diff --git a/boa/src/syntax/ast/node/mod.rs b/boa/src/syntax/ast/node/mod.rs index 0e54628b55f..6ad32b9f9ca 100644 --- a/boa/src/syntax/ast/node/mod.rs +++ b/boa/src/syntax/ast/node/mod.rs @@ -3,12 +3,13 @@ pub mod array; pub mod block; pub mod break_node; +pub mod call; pub mod conditional; pub mod declaration; -pub mod expression; pub mod field; pub mod identifier; pub mod iteration; +pub mod new; pub mod object; pub mod operator; pub mod return_smt; @@ -22,15 +23,16 @@ pub use self::{ array::ArrayDecl, block::Block, break_node::Break, + call::Call, conditional::{ConditionalOp, If}, declaration::{ ArrowFunctionDecl, ConstDecl, ConstDeclList, FunctionDecl, FunctionExpr, LetDecl, LetDeclList, VarDecl, VarDeclList, }, - expression::{Call, New}, field::{GetConstField, GetField}, identifier::Identifier, iteration::{Continue, DoWhileLoop, ForLoop, WhileLoop}, + new::New, object::Object, operator::{Assign, BinOp, UnaryOp}, return_smt::Return, diff --git a/boa/src/syntax/ast/node/new.rs b/boa/src/syntax/ast/node/new.rs new file mode 100644 index 00000000000..2cf7bf6bc56 --- /dev/null +++ b/boa/src/syntax/ast/node/new.rs @@ -0,0 +1,59 @@ +use super::Node; +use gc::{Finalize, Trace}; +use std::fmt; + +pub use super::call::Call; + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +/// The `new` operator lets developers create an instance of a user-defined object type or of +/// one of the built-in object types that has a constructor function. +/// +/// The new keyword does the following things: +/// - Creates a blank, plain JavaScript object; +/// - Links (sets the constructor of) this object to another object; +/// - Passes the newly created object from Step 1 as the this context; +/// - Returns this if the function doesn't return its own object. +/// +/// More information: +/// - [ECMAScript reference][spec] +/// - [MDN documentation][mdn] +/// +/// [spec]: https://tc39.es/ecma262/#prod-NewExpression +/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Debug, Trace, Finalize, PartialEq)] +pub struct New { + call: Call, +} + +impl New { + /// Gets the name of the function call. + pub fn expr(&self) -> &Node { + &self.call.expr() + } + + /// Retrieves the arguments passed to the function. + pub fn args(&self) -> &[Node] { + &self.call.args() + } +} + +impl From for New { + fn from(call: Call) -> Self { + Self { call } + } +} + +impl fmt::Display for New { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "new {}", self.call) + } +} + +impl From for Node { + fn from(new: New) -> Self { + Self::New(new) + } +}