Class: Twostroke::Runtime::Types::NumberObject

Inherits:
Object
  • Object
show all
Defined in:
lib/twostroke/runtime/types/number_object.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#_class, #data, #extensible, #prototype

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#can_put, #construct, #constructing?, #default_value, #define_own_property, #delete, #delete!, #each_enumerable_property, #generic_items, #get, #get_own_property, #get_property, #has_accessor, #has_own_property, #has_property, #proto_put, #put, set_global_prototype, #typeof

Methods inherited from Value

#has_instance, #typeof

Constructor Details

#initialize(number) ⇒ NumberObject

Returns a new instance of NumberObject.



15
16
17
18
19
# File 'lib/twostroke/runtime/types/number_object.rb', line 15

def initialize(number)
  @number = number
  @prototype = NumberObject.constructor_function.get("prototype")
  super()
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



14
15
16
# File 'lib/twostroke/runtime/types/number_object.rb', line 14

def number
  @number
end

Class Method Details

.constructor_functionObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/twostroke/runtime/types/number_object.rb', line 3

def self.constructor_function
  @@constructor_function ||=
    Function.new(->(scope, this, args) {
      if this.constructing?
        Twostroke::Runtime::Types.to_object(Twostroke::Runtime::Types.to_number(args[0] || Undefined.new))
      else
        Twostroke::Runtime::Types.to_number(args[0])
      end
    }, nil, "Number", [])
end

Instance Method Details

#primitive_valueObject



21
22
23
# File 'lib/twostroke/runtime/types/number_object.rb', line 21

def primitive_value
  Number.new number
end