Class: Nashorn::Ruby::AccessBase

Inherits:
Object
  • Object
show all
Defined in:
lib/nashorn/ruby/access.rb

Direct Known Subclasses

AttributeAccess, DefaultAccess

Instance Method Summary collapse

Instance Method Details

#get(object, name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nashorn/ruby/access.rb', line 20

def get(object, name)
  # try [](name) method :
  if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
    value = begin
      object[name]
    rescue LocalJumpError
      nil
    end unless internal?(name)
    return Nashorn.to_js(value) unless value.nil?
  end
  yield
end

#get_slot(object, index, &block) ⇒ Object



49
50
51
# File 'lib/nashorn/ruby/access.rb', line 49

def get_slot(object, index, &block)
  get(object, index, &block)
end

#has(object, name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/nashorn/ruby/access.rb', line 9

def has(object, name)
  # try [](name) method :
  if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
    unless internal?(name)
      value = object.[](name) { return true }
      return true unless value.nil?
    end
  end
  yield
end

#has_slot(object, index, &block) ⇒ Object



45
46
47
# File 'lib/nashorn/ruby/access.rb', line 45

def has_slot(object, index, &block)
  has(object, index, &block)
end

#set(object, name, value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nashorn/ruby/access.rb', line 33

def set(object, name, value)
  # try []=(name, value) method :
  if object.respond_to?(:'[]=') && object.method(:'[]=').arity == 2
    rb_value = Nashorn.to_rb(value)
    begin
      return object[name] = rb_value
    rescue LocalJumpError
    end unless internal?(name)
  end
  yield
end

#set_slot(object, index, value, &block) ⇒ Object



53
54
55
# File 'lib/nashorn/ruby/access.rb', line 53

def set_slot(object, index, value, &block)
  set(object, index, value, &block)
end