Class: Minjs::ECMA262::StFunc

Inherits:
Statement show all
Defined in:
lib/minjs/ecma262/statement.rb

Overview

Base class of ECMA262 FunctionDeclaration / FunctionExpression element

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Statement

#empty?, #to_exp?, #to_return?

Methods inherited from Base

#add_remove_paren, #concat, #replace

Constructor Details

#initialize(var_env, name, args, statements, options = {}) ⇒ StFunc

Returns a new instance of StFunc.



1539
1540
1541
1542
1543
1544
1545
1546
1547
# File 'lib/minjs/ecma262/statement.rb', line 1539

def initialize(var_env, name, args, statements, options = {})
  @var_env = var_env
  @name = name
  @args = args #=> array
  @statements = statements #=> Prog
  @decl = options[:decl]
  @getter = options[:getter]
  @setter = options[:setter]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



1534
1535
1536
# File 'lib/minjs/ecma262/statement.rb', line 1534

def args
  @args
end

#exe_contextObject

Returns the value of attribute exe_context.



1537
1538
1539
# File 'lib/minjs/ecma262/statement.rb', line 1537

def exe_context
  @exe_context
end

#nameObject (readonly)

Returns the value of attribute name.



1533
1534
1535
# File 'lib/minjs/ecma262/statement.rb', line 1533

def name
  @name
end

#statementsObject (readonly)

Returns the value of attribute statements.



1535
1536
1537
# File 'lib/minjs/ecma262/statement.rb', line 1535

def statements
  @statements
end

#var_envObject (readonly)

Returns the value of attribute var_env.



1536
1537
1538
# File 'lib/minjs/ecma262/statement.rb', line 1536

def var_env
  @var_env
end

Instance Method Details

#==(obj) ⇒ Object

compare object



1574
1575
1576
1577
1578
1579
# File 'lib/minjs/ecma262/statement.rb', line 1574

def ==(obj)
  self.class == obj.class and
    @name == obj.name and
    @args == obj.args and
    @statements == obj.statements
end

#decl?Boolean

Returns true if this object is function declaration

Returns:



1610
1611
1612
# File 'lib/minjs/ecma262/statement.rb', line 1610

def decl?
  @decl
end

#deep_dupObject

duplicate object

See Also:



1556
1557
1558
1559
1560
1561
# File 'lib/minjs/ecma262/statement.rb', line 1556

def deep_dup
  self.class.new(@var_env, @name ? @name.deep_dup : nil,
                     @args.collect{|args|args.deep_dup},
                     @statements.deep_dup,
                     {decl: @decl, getter: @getter, setter: @setter})
end

#enter(outer_exe_context) ⇒ Object



1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
# File 'lib/minjs/ecma262/statement.rb', line 1614

def enter(outer_exe_context)
  local_env = LexEnv.new_declarative_env(outer_exe_context.lex_env)
  var_env.record.binding.each do |k, v|
    local_env.record.create_mutable_binding(k, nil)
    val = v.delete(:value)
    local_env.record.set_mutable_binding(k, val, nil, v)
  end
  new_exe_context = ExeContext.new
  new_exe_context.lex_env = local_env
  new_exe_context.var_env = var_env
  new_exe_context
end

#getter?Boolean

Returns true if this object is setter in object

Returns:



1600
1601
1602
# File 'lib/minjs/ecma262/statement.rb', line 1600

def getter?
  @getter
end

#left_hand_side_exp?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



1595
1596
1597
# File 'lib/minjs/ecma262/statement.rb', line 1595

def left_hand_side_exp?
  true
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



1550
1551
1552
# File 'lib/minjs/ecma262/statement.rb', line 1550

def priority
  PRIORITY_PRIMARY
end

#setter?Boolean

Returns true if this object is setter in object

Returns:



1605
1606
1607
# File 'lib/minjs/ecma262/statement.rb', line 1605

def setter?
  @setter
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
# File 'lib/minjs/ecma262/statement.rb', line 1583

def to_js(options = {})
  _args = @args.collect{|x|x.to_js(options)}.join(",")
  if @getter
    concat options, :get, @name, "()", "{", @statements, "}"
  elsif @setter
    concat options, :set, @name, '(', _args, ")", "{", @statements, "}"
  else
    concat options, :function, @name, '(', _args, ")", "{", @statements, "}"
  end
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

Yield Parameters:



1564
1565
1566
1567
1568
1569
1570
1571
# File 'lib/minjs/ecma262/statement.rb', line 1564

def traverse(parent, &block)
  @name.traverse(self, &block) if @name
  @args.each do |arg|
    arg.traverse(self, &block)
  end
  @statements.traverse(self, &block)
  yield parent, self
end