Class: RubyRunJs::LocalScope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ScopeHelper

#create_and_set_binding, #create_bindings

Constructor Details

#initialize(parent, builtin) ⇒ LocalScope

Returns a new instance of LocalScope.



68
69
70
71
72
73
# File 'lib/ruby_run_js/scope.rb', line 68

def initialize(parent, builtin)
  @own = {}
  @parent = parent
  @stack = []
  @builtin = builtin
end

Instance Attribute Details

#builtinObject (readonly)

Returns the value of attribute builtin.



65
66
67
# File 'lib/ruby_run_js/scope.rb', line 65

def builtin
  @builtin
end

#ownObject (readonly)

Returns the value of attribute own.



65
66
67
# File 'lib/ruby_run_js/scope.rb', line 65

def own
  @own
end

#stackObject (readonly)

Returns the value of attribute stack.



65
66
67
# File 'lib/ruby_run_js/scope.rb', line 65

def stack
  @stack
end

#this_bindingObject

Returns the value of attribute this_binding.



66
67
68
# File 'lib/ruby_run_js/scope.rb', line 66

def this_binding
  @this_binding
end

Instance Method Details

#create_binding(var_label) ⇒ Object



79
80
81
82
83
# File 'lib/ruby_run_js/scope.rb', line 79

def create_binding(var_label)
  unless @own.key?(var_label)
    @own[var_label] = undefined
  end
end

#delete_binding(var_label) ⇒ Object



97
98
99
# File 'lib/ruby_run_js/scope.rb', line 97

def delete_binding(var_label)
  @own.key?(var_label) ? @own.delete(var_label) : @parent.delete_binding(var_label)
end

#get_binding_value(var_label, throw = false) ⇒ Object



93
94
95
# File 'lib/ruby_run_js/scope.rb', line 93

def get_binding_value(var_label,throw = false)
  @own.key?(var_label) ? @own[var_label] : @parent.get_binding_value(var_label,throw)
end

#has_binding(var_label) ⇒ Object



75
76
77
# File 'lib/ruby_run_js/scope.rb', line 75

def has_binding(var_label)
  @own.key?(var_label)
end

#set_binding(var_label, var_value, throw = false) ⇒ Object



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

def set_binding(var_label,var_value,throw = false)
  if @own.key?(var_label)
    @own[var_label] = var_label
  else
    @parent.set_binding(var_label,var_value,throw)
  end
end