Class: Minjs::ECMA262::ECMA262Object

Inherits:
Literal show all
Includes:
Ctype
Defined in:
lib/minjs/ecma262/literal.rb

Overview

Class of ECMA262 Array element

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods included from Ctype

#decimal_digit?, #hex_digit?, #identifier_part?, #identifier_start?, #idname?, #line_terminator?, #octal_digit?, #white_space?

Methods inherited from Literal

#lt?, #priority, #side_effect?, #ws?

Methods inherited from Base

#add_remove_paren, #concat, #replace

Constructor Details

#initialize(val) ⇒ ECMA262Object

val is tupple [[k,v],,…]



1029
1030
1031
# File 'lib/minjs/ecma262/literal.rb', line 1029

def initialize(val)
  @val = val
end

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



1026
1027
1028
# File 'lib/minjs/ecma262/literal.rb', line 1026

def val
  @val
end

Instance Method Details

#==(obj) ⇒ Object

compare object



1051
1052
1053
# File 'lib/minjs/ecma262/literal.rb', line 1051

def ==(obj)
  self.class == obj.class and @val == obj.val
end

#deep_dupObject

duplicate object

See Also:



1035
1036
1037
# File 'lib/minjs/ecma262/literal.rb', line 1035

def deep_dup
  self.class.new(@val.collect{|x, y| [x.deep_dup, y ? y.deep_dup : y]})
end

#left_hand_side_exp?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



1078
1079
1080
# File 'lib/minjs/ecma262/literal.rb', line 1078

def left_hand_side_exp?
  true
end

#to_ecma262_booleanBoolean

Returns results of ToBoolean()

Returns true or false if trivial, otherwise nil.

Returns:

See Also:



1090
1091
1092
# File 'lib/minjs/ecma262/literal.rb', line 1090

def to_ecma262_boolean
  true
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
# File 'lib/minjs/ecma262/literal.rb', line 1057

def to_js(options = {})
  concat(options, "{" + @val.collect{|x, y|
           if y.kind_of? StFunc and (y.getter? || y.setter?)
             if y.name.val == :get
               t = concat options, "get", x.val, "()", "{", y.statements, "}"
             else
               t = concat options, "set", x.val, "(", y.args[0], ")", "{", y.statements, "}"
             end
           else
             if x.kind_of? ECMA262Numeric
               t = concat options, x.to_ecma262_string, ":", y
             elsif idname?(x.val.to_s)
               t = concat options, x.val, ":", y
             else
               t = concat options, x, ":", y
             end
           end
         }.join(","), "}")
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



1042
1043
1044
1045
1046
1047
1048
# File 'lib/minjs/ecma262/literal.rb', line 1042

def traverse(parent, &block)
  yield parent, self
  @val.each do |k, v|
    k.traverse(parent, &block)
    v.traverse(parent, &block)
  end
end