Class: Minjs::ECMA262::StFunc
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 FunctionDeclaration / FunctionExpression element
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#exe_context ⇒ Object
Returns the value of attribute exe_context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
-
#var_env ⇒ Object
readonly
Returns the value of attribute var_env.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#decl? ⇒ Boolean
Returns true if this object is function declaration.
-
#deep_dup ⇒ Object
duplicate object.
- #enter(outer_exe_context) ⇒ Object
-
#getter? ⇒ Boolean
Returns true if this object is setter in object.
-
#initialize(var_env, name, args, statements, options = {}) ⇒ StFunc
constructor
A new instance of StFunc.
-
#left_hand_side_exp? ⇒ Boolean
True if expression is kind of LeftHandSideExpression.
-
#priority ⇒ Fixnum
Expression priority.
-
#setter? ⇒ Boolean
Returns true if this object is setter in object.
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
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, = {}) @var_env = var_env @name = name @args = args #=> array @statements = statements #=> Prog @decl = [:decl] @getter = [:getter] @setter = [:setter] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
1534 1535 1536 |
# File 'lib/minjs/ecma262/statement.rb', line 1534 def args @args end |
#exe_context ⇒ Object
Returns the value of attribute exe_context.
1537 1538 1539 |
# File 'lib/minjs/ecma262/statement.rb', line 1537 def exe_context @exe_context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1533 1534 1535 |
# File 'lib/minjs/ecma262/statement.rb', line 1533 def name @name end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
1535 1536 1537 |
# File 'lib/minjs/ecma262/statement.rb', line 1535 def statements @statements end |
#var_env ⇒ Object (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
1610 1611 1612 |
# File 'lib/minjs/ecma262/statement.rb', line 1610 def decl? @decl end |
#deep_dup ⇒ Object
duplicate object
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
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.
1595 1596 1597 |
# File 'lib/minjs/ecma262/statement.rb', line 1595 def left_hand_side_exp? true end |
#priority ⇒ Fixnum
Returns 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
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.
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 |
# File 'lib/minjs/ecma262/statement.rb', line 1583 def to_js( = {}) _args = @args.collect{|x|x.to_js()}.join(",") if @getter concat , :get, @name, "()", "{", @statements, "}" elsif @setter concat , :set, @name, '(', _args, ")", "{", @statements, "}" else concat , :function, @name, '(', _args, ")", "{", @statements, "}" end end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
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 |