Skip to content

Commit

Permalink
Apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Oct 25, 2022
1 parent beb6efa commit 94b13c3
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 85 deletions.
22 changes: 11 additions & 11 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ impl<'b> ByteCompiler<'b> {
Expression::This => {
self.access_get(Access::This, use_expr)?;
}
Expression::Spread(spread) => self.compile_expr(spread.val(), true)?,
Expression::Spread(spread) => self.compile_expr(spread.target(), true)?,
Expression::Function(function) => {
self.function(function.into(), NodeKind::Expression, use_expr)?;
}
Expand Down Expand Up @@ -1299,15 +1299,15 @@ impl<'b> ByteCompiler<'b> {
}
}
Expression::Await(expr) => {
self.compile_expr(expr.expr(), true)?;
self.compile_expr(expr.target(), true)?;
self.emit_opcode(Opcode::Await);
self.emit_opcode(Opcode::GeneratorNext);
if !use_expr {
self.emit_opcode(Opcode::Pop);
}
}
Expression::Yield(r#yield) => {
if let Some(expr) = r#yield.expr() {
if let Some(expr) = r#yield.target() {
self.compile_expr(expr, true)?;
} else {
self.emit_opcode(Opcode::PushUndefined);
Expand Down Expand Up @@ -1616,17 +1616,17 @@ impl<'b> ByteCompiler<'b> {
for_in_loop: &ForInLoop,
label: Option<Sym>,
) -> JsResult<()> {
let init_bound_names = for_in_loop.init().bound_names();
let init_bound_names = for_in_loop.initializer().bound_names();
if init_bound_names.is_empty() {
self.compile_expr(for_in_loop.expr(), true)?;
self.compile_expr(for_in_loop.target(), true)?;
} else {
self.context.push_compile_time_environment(false);
let push_env = self.emit_opcode_with_two_operands(Opcode::PushDeclarativeEnvironment);

for name in init_bound_names {
self.context.create_mutable_binding(name, false);
}
self.compile_expr(for_in_loop.expr(), true)?;
self.compile_expr(for_in_loop.target(), true)?;

let (num_bindings, compile_environment) = self.context.pop_compile_time_environment();
let index_compile_environment = self.push_compile_environment(compile_environment);
Expand All @@ -1646,7 +1646,7 @@ impl<'b> ByteCompiler<'b> {
let push_env = self.emit_opcode_with_two_operands(Opcode::PushDeclarativeEnvironment);
let exit = self.emit_opcode_with_operand(Opcode::ForInLoopNext);

match for_in_loop.init() {
match for_in_loop.initializer() {
IterableLoopInitializer::Identifier(ident) => {
self.context.create_mutable_binding(*ident, true);
let binding = self.context.set_mutable_binding(*ident);
Expand Down Expand Up @@ -2106,7 +2106,7 @@ impl<'b> ByteCompiler<'b> {
}
}
Statement::Throw(throw) => {
self.compile_expr(throw.expr(), true)?;
self.compile_expr(throw.target(), true)?;
self.emit(Opcode::Throw, &[]);
}
Statement::Switch(switch) => {
Expand Down Expand Up @@ -2153,7 +2153,7 @@ impl<'b> ByteCompiler<'b> {
self.emit_opcode(Opcode::PopEnvironment);
}
Statement::Return(ret) => {
if let Some(expr) = ret.expr() {
if let Some(expr) = ret.target() {
self.compile_expr(expr, true)?;
} else {
self.emit(Opcode::PushUndefined, &[]);
Expand Down Expand Up @@ -2336,14 +2336,14 @@ impl<'b> ByteCompiler<'b> {
}

let (call, kind) = match callable {
Callable::Call(call) => match call.expr() {
Callable::Call(call) => match call.function() {
Expression::Identifier(ident) if *ident == Sym::EVAL => (call, CallKind::CallEval),
_ => (call, CallKind::Call),
},
Callable::New(new) => (new.call(), CallKind::New),
};

match call.expr() {
match call.function() {
Expression::PropertyAccess(access) => {
self.compile_expr(access.target(), true)?;
if kind == CallKind::Call {
Expand Down
16 changes: 8 additions & 8 deletions boa_engine/src/syntax/ast/expression/await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ use boa_interner::{Interner, ToIndentedString, ToInternedString};
#[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Await {
expr: Box<Expression>,
target: Box<Expression>,
}

impl Await {
/// Return the expression that should be awaited.
/// Return the target expression that should be awaited.
#[inline]
pub(crate) fn expr(&self) -> &Expression {
&self.expr
pub(crate) fn target(&self) -> &Expression {
&self.target
}

#[inline]
pub(crate) fn contains_arguments(&self) -> bool {
self.expr.contains_arguments()
self.target.contains_arguments()
}

#[inline]
pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool {
self.expr.contains(symbol)
self.target.contains(symbol)
}
}

Expand All @@ -44,14 +44,14 @@ where
{
#[inline]
fn from(e: T) -> Self {
Self { expr: e.into() }
Self { target: e.into() }
}
}

impl ToInternedString for Await {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
format!("await {}", self.expr.to_indented_string(interner, 0))
format!("await {}", self.target.to_indented_string(interner, 0))
}
}

Expand Down
18 changes: 9 additions & 9 deletions boa_engine/src/syntax/ast/expression/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ use super::Expression;
#[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Call {
target: Box<Expression>,
function: Box<Expression>,
args: Box<[Expression]>,
}

impl Call {
/// Creates a new `Call` AST Expression.
#[inline]
pub fn new(target: Expression, args: Box<[Expression]>) -> Self {
pub fn new(function: Expression, args: Box<[Expression]>) -> Self {
Self {
target: target.into(),
function: function.into(),
args,
}
}

/// Gets the name of the function call.
/// Gets the target function of this call expression.
#[inline]
pub fn expr(&self) -> &Expression {
&self.target
pub fn function(&self) -> &Expression {
&self.function
}

/// Retrieves the arguments passed to the function.
Expand All @@ -48,12 +48,12 @@ impl Call {

#[inline]
pub(crate) fn contains_arguments(&self) -> bool {
self.target.contains_arguments() || self.args.iter().any(Expression::contains_arguments)
self.function.contains_arguments() || self.args.iter().any(Expression::contains_arguments)
}

#[inline]
pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool {
self.target.contains(symbol) || self.args.iter().any(|expr| expr.contains(symbol))
self.function.contains(symbol) || self.args.iter().any(|expr| expr.contains(symbol))
}
}

Expand All @@ -62,7 +62,7 @@ impl ToInternedString for Call {
fn to_interned_string(&self, interner: &Interner) -> String {
format!(
"{}({})",
self.target.to_interned_string(interner),
self.function.to_interned_string(interner),
join_nodes(interner, &self.args)
)
}
Expand Down
10 changes: 5 additions & 5 deletions boa_engine/src/syntax/ast/expression/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ pub struct New {
}

impl New {
/// Gets the name of the function call.
/// Gets the constructor of the new expression.
#[inline]
pub fn expr(&self) -> &Expression {
self.call.expr()
pub fn constructor(&self) -> &Expression {
self.call.function()
}

/// Retrieves the arguments passed to the function.
/// Retrieves the arguments passed to the constructor.
#[inline]
pub fn args(&self) -> &[Expression] {
self.call.args()
}

/// Returns the inner call
/// Returns the inner call expression.
pub(crate) fn call(&self) -> &Call {
&self.call
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub(crate) fn array_decl_to_declaration_pattern(
});
}
Expression::Spread(spread) => {
match spread.val() {
match spread.target() {
Expression::Identifier(ident) => {
bindings.push(ArrayPatternElement::SingleNameRest { ident: *ident });
}
Expand Down
18 changes: 9 additions & 9 deletions boa_engine/src/syntax/ast/expression/spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,39 @@ use super::Expression;
#[cfg_attr(feature = "deser", serde(transparent))]
#[derive(Clone, Debug, PartialEq)]
pub struct Spread {
expression: Box<Expression>,
target: Box<Expression>,
}

impl Spread {
/// Gets the expression to be expanded by the spread operator.
/// Gets the target expression to be expanded by the spread operator.
#[inline]
pub fn val(&self) -> &Expression {
&self.expression
pub fn target(&self) -> &Expression {
&self.target
}

/// Creates a `Spread` AST Expression.
#[inline]
pub fn new(val: Expression) -> Self {
pub fn new(target: Expression) -> Self {
Self {
expression: Box::new(val),
target: Box::new(target),
}
}

#[inline]
pub(crate) fn contains_arguments(&self) -> bool {
self.expression.contains_arguments()
self.target.contains_arguments()
}

#[inline]
pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool {
self.expression.contains(symbol)
self.target.contains(symbol)
}
}

impl ToInternedString for Spread {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
format!("...{}", self.val().to_interned_string(interner))
format!("...{}", self.target().to_interned_string(interner))
}
}

Expand Down
16 changes: 8 additions & 8 deletions boa_engine/src/syntax/ast/expression/yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use super::Expression;
#[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Yield {
expr: Option<Box<Expression>>,
target: Option<Box<Expression>>,
delegate: bool,
}

impl Yield {
/// Gets the expression of this `Yield` statement.
/// Gets the target expression of this `Yield` statement.
#[inline]
pub fn expr(&self) -> Option<&Expression> {
self.expr.as_ref().map(Box::as_ref)
pub fn target(&self) -> Option<&Expression> {
self.target.as_ref().map(Box::as_ref)
}

/// Returns `true` if this `Yield` statement delegates to another generator or iterable object.
Expand All @@ -36,19 +36,19 @@ impl Yield {
#[inline]
pub fn new(expr: Option<Expression>, delegate: bool) -> Self {
Self {
expr: expr.map(Box::new),
target: expr.map(Box::new),
delegate,
}
}

#[inline]
pub(crate) fn contains_arguments(&self) -> bool {
matches!(self.expr, Some(ref expr) if expr.contains_arguments())
matches!(self.target, Some(ref expr) if expr.contains_arguments())
}

#[inline]
pub(crate) fn contains(&self, symbol: ContainsSymbol) -> bool {
matches!(self.expr, Some(ref expr) if expr.contains(symbol))
matches!(self.target, Some(ref expr) if expr.contains(symbol))
}
}

Expand All @@ -63,7 +63,7 @@ impl ToInternedString for Yield {
#[inline]
fn to_interned_string(&self, interner: &Interner) -> String {
let y = if self.delegate { "yield*" } else { "yield" };
if let Some(ex) = self.expr() {
if let Some(ex) = self.target() {
format!("{y} {}", ex.to_interned_string(interner))
} else {
y.to_owned()
Expand Down
Loading

0 comments on commit 94b13c3

Please sign in to comment.