Class: Minjs::ECMA262::Boolean

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

Overview

Class of ECMA262 Boolean element

See Also:

Constant Summary collapse

@@true =
self.new(:true)
@@false =
self.new(:false)

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Literal

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

Methods inherited from Base

#add_remove_paren, #concat, #replace

Constructor Details

#initialize(val) ⇒ Boolean

Returns a new instance of Boolean.



278
279
280
281
282
283
284
# File 'lib/minjs/ecma262/literal.rb', line 278

def initialize(val)
  if val.to_s == "true"
    @val = :"true"
  else
    @val = :"false"
  end
end

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



276
277
278
# File 'lib/minjs/ecma262/literal.rb', line 276

def val
  @val
end

Class Method Details

.get(val) ⇒ Object

get instance



379
380
381
382
383
384
385
# File 'lib/minjs/ecma262/literal.rb', line 379

def self.get(val)
  if val.to_sym == :true || val == true
    @@true
  else
    @@false
  end
end

Instance Method Details

#==(obj) ⇒ Object

compare object



300
301
302
303
# File 'lib/minjs/ecma262/literal.rb', line 300

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

#deep_dupObject

duplicate object



288
289
290
# File 'lib/minjs/ecma262/literal.rb', line 288

def deep_dup
  self #//not dup
end

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    :boolean



371
372
373
# File 'lib/minjs/ecma262/literal.rb', line 371

def ecma262_typeof
  :boolean
end

#left_hand_side_exp?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



312
313
314
# File 'lib/minjs/ecma262/literal.rb', line 312

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:



344
345
346
347
348
349
350
# File 'lib/minjs/ecma262/literal.rb', line 344

def to_ecma262_boolean
  if @val == :false
    false
  else
    true
  end
end

#to_ecma262_numberNumeric

Returns results of ToNumber()

Returns number if value is trivial, otherwise nil.

Returns:

  • (Numeric)

See Also:



360
361
362
363
364
365
366
# File 'lib/minjs/ecma262/literal.rb', line 360

def to_ecma262_number
  if @val == :false
    0
  else
    1
  end
end

#to_ecma262_stringNumeric

Returns results of ToString()

Returns string if value is trivial, otherwise nil.

Returns:

  • (Numeric)

See Also:



328
329
330
331
332
333
334
# File 'lib/minjs/ecma262/literal.rb', line 328

def to_ecma262_string
  if @val == :false
    "false"
  else
    "true"
  end
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.



307
308
309
# File 'lib/minjs/ecma262/literal.rb', line 307

def to_js(options = {})
  @val.to_s
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



295
296
297
# File 'lib/minjs/ecma262/literal.rb', line 295

def traverse(parent, &block)
  yield parent, self
end

#true?Boolean

Returns:



316
317
318
# File 'lib/minjs/ecma262/literal.rb', line 316

def true?
  @val == :true
end