Class: RubyRunJs::GlobalScope

Inherits:
JsBaseObject show all
Includes:
ScopeHelper
Defined in:
lib/ruby_run_js/scope.rb

Instance Attribute Summary collapse

Attributes inherited from JsBaseObject

#extensible, #own, #prototype, #value

Instance Method Summary collapse

Methods included from ScopeHelper

#create_and_set_binding, #create_bindings

Methods inherited from JsBaseObject

#_type, #can_put, #default_value, #define_own_property, #delete, #get, #get_items, #get_own_property, #get_property, #has_property, #put, #set_items

Methods included from Helper

#check_object, #get_member, #get_member_dot, #is_accessor_descriptor, #is_callable, #is_data_descriptor, #is_generic_descriptor, #is_primitive, #make_error, #strict_equality

Methods included from ConversionHelper

#convert_to_js_type, #to_boolean, #to_int32, #to_integer, #to_number, #to_object, #to_primitive, #to_string, #to_uint16, #to_uint32

Constructor Details

#initialize(builtin) ⇒ GlobalScope

Returns a new instance of GlobalScope.



26
27
28
29
30
# File 'lib/ruby_run_js/scope.rb', line 26

def initialize(builtin)
  super()
  @stack = []
  @builtin = builtin
end

Instance Attribute Details

#builtinObject (readonly)

Returns the value of attribute builtin.



23
24
25
# File 'lib/ruby_run_js/scope.rb', line 23

def builtin
  @builtin
end

#stackObject (readonly)

Returns the value of attribute stack.



23
24
25
# File 'lib/ruby_run_js/scope.rb', line 23

def stack
  @stack
end

#this_bindingObject

Returns the value of attribute this_binding.



24
25
26
# File 'lib/ruby_run_js/scope.rb', line 24

def this_binding
  @this_binding
end

Instance Method Details

#_classObject



32
33
34
# File 'lib/ruby_run_js/scope.rb', line 32

def _class
  'Global'
end

#create_binding(var_label) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_run_js/scope.rb', line 36

def create_binding(var_label)
  unless has_binding(var_label)
    define_own_property(var_label,
        {
          'value' => undefined,
          'configurable' => false,
          'writable' => true,
          'enumerable' => true
        },false)
  end
end

#get_binding_value(var_label, throw = false) ⇒ Object



48
49
50
51
52
53
# File 'lib/ruby_run_js/scope.rb', line 48

def get_binding_value(var_label, throw = false)
  if !has_binding(var_label) && throw
    raise make_error('ReferenceError', "#{var_label} is not defined")
  end
  get(var_label)
end