Class: Twostroke::Runtime::GlobalScope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vm, root_name = "window", root_object = nil) ⇒ GlobalScope

Returns a new instance of GlobalScope.



86
87
88
89
90
91
# File 'lib/twostroke/runtime/scope.rb', line 86

def initialize(vm, root_name = "window", root_object = nil)
  @root_name = root_name
  @root_object = root_object || Types::Object.new
  @root_object.put root_name.to_s, @root_object
  @vm = vm
end

Instance Attribute Details

#root_nameObject (readonly)

Returns the value of attribute root_name.



84
85
86
# File 'lib/twostroke/runtime/scope.rb', line 84

def root_name
  @root_name
end

#root_objectObject (readonly)

Returns the value of attribute root_object.



84
85
86
# File 'lib/twostroke/runtime/scope.rb', line 84

def root_object
  @root_object
end

#vmObject (readonly)

Returns the value of attribute vm.



84
85
86
# File 'lib/twostroke/runtime/scope.rb', line 84

def vm
  @vm
end

Instance Method Details

#closeObject



108
109
110
# File 'lib/twostroke/runtime/scope.rb', line 108

def close
  Scope.new self
end

#declare(var) ⇒ Object



105
106
# File 'lib/twostroke/runtime/scope.rb', line 105

def declare(var)
end

#get_var(var) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/twostroke/runtime/scope.rb', line 93

def get_var(var)
  if @root_object.has_property var.to_s
    @root_object.get var.to_s
  else
    Lib.throw_reference_error "undefined variable #{var}"
  end
end

#global_scopeObject



116
117
118
# File 'lib/twostroke/runtime/scope.rb', line 116

def global_scope
  self
end

#has_var(var) ⇒ Object



101
102
103
# File 'lib/twostroke/runtime/scope.rb', line 101

def has_var(var)
  @root_object.has_property var.to_s
end

#set_var(var, value) ⇒ Object



112
113
114
# File 'lib/twostroke/runtime/scope.rb', line 112

def set_var(var, value)
  @root_object.put var.to_s, value
end