Module: Minjs::ECMA262::AssignmentOperation

Overview

Module of typically Assignment operation.

Typically unary operation expression has left-hand value(val) and right-hand value(val2)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



195
196
197
# File 'lib/minjs/ecma262/expression.rb', line 195

def val
  @val
end

#val2Object (readonly)

Returns the value of attribute val2.



195
196
197
# File 'lib/minjs/ecma262/expression.rb', line 195

def val2
  @val2
end

Instance Method Details

#==(obj) ⇒ Object

compare object



220
221
222
# File 'lib/minjs/ecma262/expression.rb', line 220

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

#add_parenObject

add parenthesis if need



209
210
211
212
213
214
215
216
217
# File 'lib/minjs/ecma262/expression.rb', line 209

def add_paren
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
    @val = ExpParen.new(@val)
  end
  if @val2.priority > PRIORITY_ASSIGNMENT
    @val2 = ExpParen.new(@val2)
  end
  self
end

#deep_dupObject

duplicate object

See Also:



237
238
239
# File 'lib/minjs/ecma262/expression.rb', line 237

def deep_dup
  self.class.new(@val.deep_dup, @val2.deep_dup)
end

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    type of right-side-hand expression or nil if typeof value is undetermined.



228
229
230
231
232
233
234
# File 'lib/minjs/ecma262/expression.rb', line 228

def ecma262_typeof
  if @val2.respond_to? :ecma262_typeof
    @val2.ecma262_typeof
  else
    nil
  end
end

#reduce(parent) ⇒ Object

reduce expression if available

Parameters:

  • parent (Base)

    parent element



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/minjs/ecma262/expression.rb', line 267

def reduce(parent)
  #
  # a = a / b => a /= b
  #
  if @val2.kind_of? ExpDiv and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpDivAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpMul and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpMulAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpMod and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpModAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpAdd and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpAddAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpSub and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpSubAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpLShift and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpLShiftAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpRShift and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpRShiftAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpURShift and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpURShiftAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpAnd and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpAndAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpOr and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpOrAssign.new(@val, @val2.val2)))
  elsif @val2.kind_of? ExpXor and @val2.val == @val
    parent.replace(self,
                   ExpParen.new(
                     ExpXorAssign.new(@val, @val2.val2)))
  end
end

#remove_parenObject

remove parenthesis if possible



198
199
200
201
202
203
204
205
206
# File 'lib/minjs/ecma262/expression.rb', line 198

def remove_paren
  if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
    @val = @val.val if @val.remove_paren?
  end
  if @val2.kind_of? ExpParen and @val2.val.priority <= PRIORITY_ASSIGNMENT
    @val2 = @val2.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



243
244
245
246
247
248
249
# File 'lib/minjs/ecma262/expression.rb', line 243

def replace(from, to)
  if @val .eql? from
    @val = to
  elsif @val2 .eql? from
    @val2 = to
  end
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



261
262
263
# File 'lib/minjs/ecma262/expression.rb', line 261

def to_js(options = {})
  concat options, @val, sym, @val2
end

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

Traverses this children and itself with given block.

Yields:

  • (parent, _self)

Yield Parameters:

See Also:



253
254
255
256
257
# File 'lib/minjs/ecma262/expression.rb', line 253

def traverse(parent, &block)
  @val.traverse(self, &block)
  @val2.traverse(self, &block)
  yield parent, self
end