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
- #delete(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.
98 99 100 101 102 103 |
# File 'lib/twostroke/runtime/scope.rb', line 98 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.
96 97 98 |
# File 'lib/twostroke/runtime/scope.rb', line 96 def root_name @root_name end |
#root_object ⇒ Object (readonly)
Returns the value of attribute root_object.
96 97 98 |
# File 'lib/twostroke/runtime/scope.rb', line 96 def root_object @root_object end |
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
96 97 98 |
# File 'lib/twostroke/runtime/scope.rb', line 96 def vm @vm end |
Instance Method Details
#close ⇒ Object
125 126 127 |
# File 'lib/twostroke/runtime/scope.rb', line 125 def close Scope.new self end |
#declare(var) ⇒ Object
117 118 119 |
# File 'lib/twostroke/runtime/scope.rb', line 117 def declare(var) @root_object.put var.to_s, Types::Undefined.new end |
#delete(var) ⇒ Object
121 122 123 |
# File 'lib/twostroke/runtime/scope.rb', line 121 def delete(var) @root_object.delete var.to_s end |
#get_var(var) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/twostroke/runtime/scope.rb', line 105 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
133 134 135 |
# File 'lib/twostroke/runtime/scope.rb', line 133 def global_scope self end |
#has_var(var) ⇒ Object
113 114 115 |
# File 'lib/twostroke/runtime/scope.rb', line 113 def has_var(var) @root_object.has_property var.to_s end |
#set_var(var, value) ⇒ Object
129 130 131 |
# File 'lib/twostroke/runtime/scope.rb', line 129 def set_var(var, value) @root_object.put var.to_s, value end |