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.



102
103
104
105
106
107
# File 'lib/twostroke/runtime/scope.rb', line 102

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.



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

def root_name
  @root_name
end

#root_objectObject (readonly)

Returns the value of attribute root_object.



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

def root_object
  @root_object
end

#vmObject (readonly)

Returns the value of attribute vm.



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

def vm
  @vm
end

Instance Method Details

#closeObject



129
130
131
# File 'lib/twostroke/runtime/scope.rb', line 129

def close
  Scope.new self
end

#declare(var) ⇒ Object



121
122
123
# File 'lib/twostroke/runtime/scope.rb', line 121

def declare(var)
  @root_object.put var.to_s, Types::Undefined.new
end

#delete(var) ⇒ Object



125
126
127
# File 'lib/twostroke/runtime/scope.rb', line 125

def delete(var)
  @root_object.delete var.to_s
end

#get_var(var) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/twostroke/runtime/scope.rb', line 109

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



137
138
139
# File 'lib/twostroke/runtime/scope.rb', line 137

def global_scope
  self
end

#has_var(var) ⇒ Object



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

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

#set_var(var, value) ⇒ Object



133
134
135
# File 'lib/twostroke/runtime/scope.rb', line 133

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