Class: Minjs::ECMA262::ExpAdd
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpAdd
- Includes:
- BinaryOperation
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Class of the Additionr operator expression element.
Instance Attribute Summary
Attributes included from BinaryOperation
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(val, val2) ⇒ ExpAdd
constructor
A new instance of ExpAdd.
-
#priority ⇒ Fixnum
Expression priority.
-
#reduce(parent) ⇒ Object
reduce expression if available.
-
#sym ⇒ Object
symbol of expression.
Methods included from BinaryOperation
#==, #add_paren, #deep_dup, #remove_paren, #replace, #to_js, #traverse
Methods inherited from Expression
#left_hand_side_exp?, #side_effect?
Methods inherited from Base
#==, #add_remove_paren, #concat, #deep_dup, #replace, #to_js, #traverse
Constructor Details
#initialize(val, val2) ⇒ ExpAdd
Returns a new instance of ExpAdd.
1244 1245 1246 1247 |
# File 'lib/minjs/ecma262/expression.rb', line 1244 def initialize(val, val2) @val = val @val2 = val2 end |
Instance Method Details
#priority ⇒ Fixnum
Returns expression priority.
1255 1256 1257 |
# File 'lib/minjs/ecma262/expression.rb', line 1255 def priority PRIORITY_ADDITIVE end |
#reduce(parent) ⇒ Object
reduce expression if available
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
# File 'lib/minjs/ecma262/expression.rb', line 1261 def reduce(parent) # # String + String/ # a + b = a.concat(b) if @val.kind_of? ECMA262String or @val2.kind_of? ECMA262String if @val.respond_to? :to_ecma262_string and @val2.respond_to? :to_ecma262_string v = @val.to_ecma262_string v2 = @val2.to_ecma262_string if !v.nil? and !v2.nil? new_str = ECMA262String.new(v + v2) parent.replace(self, new_str) end end # # Numeric + Numeric # elsif @val.respond_to? :to_ecma262_number and @val2.respond_to? :to_ecma262_number # #11.6.3 Applying the Additive Operators to Numbers(TODO) # # N + M => (N + M) v = @val.to_ecma262_number v2 = @val2.to_ecma262_number if !v.nil? and !v2.nil? parent.replace(self, ECMA262Numeric.new(v + v2)) end end end |
#sym ⇒ Object
symbol of expression
1250 1251 1252 |
# File 'lib/minjs/ecma262/expression.rb', line 1250 def sym "+" end |