Class: Twostroke::Runtime::GlobalScope
- Inherits:
-
Object
- Object
- Twostroke::Runtime::GlobalScope
- Defined in:
- lib/twostroke/runtime/scope.rb
Instance Attribute Summary collapse
-
#root_name ⇒ Object
readonly
Returns the value of attribute root_name.
-
#root_object ⇒ Object
readonly
Returns the value of attribute root_object.
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Instance Method Summary collapse
- #close ⇒ Object
- #declare(var) ⇒ Object
- #get_var(var) ⇒ Object
- #global_scope ⇒ Object
- #has_var(var) ⇒ Object
-
#initialize(vm, root_name = "window", root_object = nil) ⇒ GlobalScope
constructor
A new instance of GlobalScope.
- #set_var(var, value) ⇒ Object
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_name ⇒ Object (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_object ⇒ Object (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 |
#vm ⇒ Object (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
#close ⇒ Object
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_scope ⇒ Object
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 |