Class: Binding
- Defined in:
- opal/opal/corelib/binding.rb,
opal/opal/corelib/irb.rb
Overview
backtick_javascript: true
Instance Attribute Summary collapse
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
-
#source_location ⇒ Object
readonly
Returns the value of attribute source_location.
Instance Method Summary collapse
- #eval(str, file = nil, line = nil) ⇒ Object
-
#initialize(jseval, scope_variables = [], receiver = undefined, source_location = nil) ⇒ Binding
constructor
A new instance of Binding.
- #irb ⇒ Object
- #js_eval(*args) ⇒ Object
- #local_variable_defined?(value) ⇒ Boolean
- #local_variable_get(symbol) ⇒ Object
- #local_variable_set(symbol, value) ⇒ Object
- #local_variables ⇒ Object
Constructor Details
#initialize(jseval, scope_variables = [], receiver = undefined, source_location = nil) ⇒ Binding
Returns a new instance of Binding.
5 6 7 8 9 10 |
# File 'opal/opal/corelib/binding.rb', line 5 def initialize(jseval, scope_variables = [], receiver = undefined, source_location = nil) @jseval, @scope_variables, @receiver, @source_location = \ jseval, scope_variables, receiver, source_location receiver = js_eval('self') if `typeof receiver === "undefined"` end |
Instance Attribute Details
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
47 48 49 |
# File 'opal/opal/corelib/binding.rb', line 47 def receiver @receiver end |
#source_location ⇒ Object (readonly)
Returns the value of attribute source_location.
47 48 49 |
# File 'opal/opal/corelib/binding.rb', line 47 def source_location @source_location end |
Instance Method Details
#eval(str, file = nil, line = nil) ⇒ Object
41 42 43 44 45 |
# File 'opal/opal/corelib/binding.rb', line 41 def eval(str, file = nil, line = nil) return receiver if str == 'self' ::Kernel.eval(str, self, file, line) end |
#irb ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'opal/opal/corelib/irb.rb', line 110 def irb ::Opal::IRB.ensure_loaded('opal-replutils') silencer = ::Opal::IRB::Silencer.new ::Opal::IRB.prepare_console do loop do print '>> ' line = gets break unless line code = '' puts line if ::Opal::IRB.browser? if line.start_with? 'ls ' code = line[3..-1] mode = :ls elsif line == "ls\n" code = 'self' mode = :ls elsif line.start_with? 'show ' code = line[5..-1] mode = :show else code = line mode = :inspect end js_code = nil begin silencer.silence do js_code = `Opal.compile(code, {irb: true})` end rescue SyntaxError => e if ::Opal::IRB::LINEBREAKS.include?(e.) print '.. ' line = gets return unless line puts line if ::Opal::IRB.browser? code += line retry elsif silencer.warnings.empty? warn e. else # Most likely a parser error warn silencer.warnings end end if mode == :show puts js_code return end puts ::REPLUtils.eval_and_print(js_code, mode, false, self) end end end |
#js_eval(*args) ⇒ Object
12 13 14 15 16 17 18 |
# File 'opal/opal/corelib/binding.rb', line 12 def js_eval(*args) if @jseval @jseval.call(*args) else ::Kernel.raise 'Evaluation on a Proc#binding is not supported' end end |
#local_variable_defined?(value) ⇒ Boolean
37 38 39 |
# File 'opal/opal/corelib/binding.rb', line 37 def local_variable_defined?(value) @scope_variables.include?(value) end |
#local_variable_get(symbol) ⇒ Object
20 21 22 23 24 |
# File 'opal/opal/corelib/binding.rb', line 20 def local_variable_get(symbol) js_eval(symbol) rescue ::Exception ::Kernel.raise ::NameError, "local variable `#{symbol}' is not defined for #{inspect}" end |
#local_variable_set(symbol, value) ⇒ Object
26 27 28 29 30 31 |
# File 'opal/opal/corelib/binding.rb', line 26 def local_variable_set(symbol, value) `Opal.Binding.tmp_value = value` js_eval("#{symbol} = Opal.Binding.tmp_value") `delete Opal.Binding.tmp_value` value end |
#local_variables ⇒ Object
33 34 35 |
# File 'opal/opal/corelib/binding.rb', line 33 def local_variables @scope_variables end |