Class: Minjs::ECMA262::StForIn
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 ‘for(in)’ IterationStatement element.
Instance Attribute Summary collapse
-
#exp1 ⇒ Object
readonly
Returns the value of attribute exp1.
-
#exp2 ⇒ Object
readonly
Returns the value of attribute exp2.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#initialize(exp1, exp2, statement) ⇒ StForIn
constructor
A new instance of StForIn.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#replace(from, to) ⇒ Object
Replaces children 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?, #priority, #to_exp?, #to_return?
Methods inherited from Base
Constructor Details
#initialize(exp1, exp2, statement) ⇒ StForIn
Returns a new instance of StForIn.
843 844 845 846 847 |
# File 'lib/minjs/ecma262/statement.rb', line 843 def initialize(exp1, exp2, statement) @exp1 = exp1 @exp2 = exp2 @statement = statement end |
Instance Attribute Details
#exp1 ⇒ Object (readonly)
Returns the value of attribute exp1.
841 842 843 |
# File 'lib/minjs/ecma262/statement.rb', line 841 def exp1 @exp1 end |
#exp2 ⇒ Object (readonly)
Returns the value of attribute exp2.
841 842 843 |
# File 'lib/minjs/ecma262/statement.rb', line 841 def exp2 @exp2 end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
841 842 843 |
# File 'lib/minjs/ecma262/statement.rb', line 841 def statement @statement end |
Instance Method Details
#==(obj) ⇒ Object
compare object
872 873 874 875 876 877 |
# File 'lib/minjs/ecma262/statement.rb', line 872 def ==(obj) self.class == obj.class and @exp1 == obj.exp1 and @exp2 == obj.exp2 and @statement == obj.statement end |
#add_paren ⇒ Object
add parenthesis if need
903 904 905 906 907 908 |
# File 'lib/minjs/ecma262/statement.rb', line 903 def add_paren if @exp1.priority > PRIORITY_LEFT_HAND_SIDE @exp1 = ExpParen.new(@exp1) end self end |
#deep_dup ⇒ Object
duplicate object
851 852 853 |
# File 'lib/minjs/ecma262/statement.rb', line 851 def deep_dup self.class.new(@exp1.deep_dup, @exp2.deep_dup, @statement.deep_dup) end |
#remove_paren ⇒ Object
remove parenthesis if possible
892 893 894 895 896 897 898 899 900 |
# File 'lib/minjs/ecma262/statement.rb', line 892 def remove_paren if @exp1.kind_of? ExpParen and @exp1.val.priority <= PRIORITY_LEFT_HAND_SIDE @exp1 = @exp1.val end if @exp2.kind_of? ExpParen @exp2 = @exp2.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
857 858 859 860 861 |
# File 'lib/minjs/ecma262/statement.rb', line 857 def replace(from, to) if from .eql? @statement @statement = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
881 882 883 884 885 886 887 888 889 |
# File 'lib/minjs/ecma262/statement.rb', line 881 def to_js( = {}) if @statement.kind_of? StBlock and @statement.statement_list.length == 1 statement = @statement.statement_list.statement_list[0] else statement = @statement end concat , :for, '(', @exp1, :in, @exp2, ')', statement end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
864 865 866 867 868 869 |
# File 'lib/minjs/ecma262/statement.rb', line 864 def traverse(parent, &block) @exp1.traverse(self, &block) @exp2.traverse(self, &block) @statement.traverse(self, &block) yield parent, self end |