class Minjs::ECMA262::ExpNew

Class of the New expression element.

@see www.ecma-international.org/ecma-262 ECMA262 11.2

Attributes

args[R]
name[R]

Public Class Methods

new(name, args) click to toggle source
# File lib/minjs/ecma262/expression.rb, line 695
def initialize(name, args)
  @name = name
  @args = args
end

Public Instance Methods

==(obj) click to toggle source

compare object

# File lib/minjs/ecma262/expression.rb, line 737
def ==(obj)
  self.class == obj.class and @name == obj.name and @args == obj.args
end
add_paren() click to toggle source

add parenthesis if need

# File lib/minjs/ecma262/expression.rb, line 775
def add_paren
  if @name.priority > PRIORITY_LEFT_HAND_SIDE
    @name = ExpParen.new(@name)
  end
  if @args
    @args.map! do |arg|
      if arg.priority > PRIORITY_ASSIGNMENT
        ExpParen.new(arg)
      else
        arg
      end
    end
  end
  self
end
deep_dup() click to toggle source

duplicate object @see Base#deep_dup

# File lib/minjs/ecma262/expression.rb, line 707
def deep_dup
  self.class.new(@name,
                 @args ? @args.collect{|x| x.deep_dup} : nil)
end
left_hand_side_exp?() click to toggle source

@return [Boolean] true if expression is kind of LeftHandSideExpression.

# File lib/minjs/ecma262/expression.rb, line 753
def left_hand_side_exp?
  true
end
priority() click to toggle source

@return [Fixnum] expression priority

# File lib/minjs/ecma262/expression.rb, line 701
def priority
  PRIORITY_LEFT_HAND_SIDE + ((args == nil) ? 1 : 0)
end
remove_paren() click to toggle source

remove parenthesis if possible

# File lib/minjs/ecma262/expression.rb, line 758
def remove_paren
  if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
    @name = @name.val if @name.remove_paren?
  end
  if @args
    @args.map! do |arg|
      if arg.kind_of? ExpParen and arg.val.priority <= PRIORITY_ASSIGNMENT
        arg.val if arg.remove_paren?
      else
        arg
      end
    end
  end
  self
end
replace(from, to) click to toggle source

Replaces children object. @see Base#replace

# File lib/minjs/ecma262/expression.rb, line 714
def replace(from, to)
  if @name .eql? from
    @name = from
  elsif @args .eql? from
    @args = to
  elsif @args and (idx = @args.index(from))
    @args[idx] = to
  end
end
to_js(options = {}) click to toggle source

Returns a ECMAScript string containg the representation of element. @see Base#to_js

# File lib/minjs/ecma262/expression.rb, line 743
def to_js(options = {})
  if @args
    args = @args.collect{|x| x.to_js(options)}.join(",")
    concat options, :new, @name, '(', args, ')'
  else
    concat options, :new, @name
  end
end
traverse(parent) { |parent, self| ... } click to toggle source

Traverses this children and itself with given block. @see Base#traverse

# File lib/minjs/ecma262/expression.rb, line 726
def traverse(parent, &block)
  @name.traverse(self, &block)
  if @args
    @args.each do |arg|
      arg.traverse(self, &block)
    end
  end
  yield parent, self
end