Sha256: 3e6248c26c3602333fde5a5701e959d58b5907dc095ca6b39537df70736c223e

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

class Binding
  # @private
  def initialize(jseval, scope_variables, receiver, source_location)
    @jseval, @scope_variables, @receiver, @source_location = \
      jseval, scope_variables, receiver, source_location
  end

  def js_eval(*args)
    if @jseval
      @jseval.call(*args)
    else
      raise 'Evaluation on a Proc#binding is not supported'
    end
  end

  def local_variable_get(symbol)
    js_eval(symbol)
  rescue Exception
    raise NameError, "local variable `#{symbol}' is not defined for #{inspect}"
  end

  def local_variable_set(symbol, value)
    js_eval(symbol, value)
  end

  def local_variables
    @scope_variables
  end

  def local_variable_defined?(value)
    @scope_variables.include?(value)
  end

  def eval(str, file = nil, line = nil)
    return receiver if str == 'self'

    Kernel.eval(str, self, file, line)
  end

  attr_reader :receiver, :source_location
end

module Kernel
  def binding
    raise "Opal doesn't support dynamic calls to binding"
  end
end

TOPLEVEL_BINDING = binding
`#{TOPLEVEL_BINDING}.source_location = ["<main>", 0]`

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opal-1.3.2 opal/corelib/binding.rb
opal-1.3.1 opal/corelib/binding.rb