Module: V8::Conversion::Identity

Included in:
V8::Conversion
Defined in:
lib/v8/conversion/indentity.rb

Instance Method Summary collapse

Instance Method Details

#equate(ruby_object, v8_object) ⇒ Object


18
19
20
21
# File 'lib/v8/conversion/indentity.rb', line 18

def equate(ruby_object, v8_object)
  v8_idmap[v8_object.GetIdentityHash()] = ruby_object
  rb_idmap[ruby_object.object_id] = v8_object
end

#rb_idmapObject


27
28
29
# File 'lib/v8/conversion/indentity.rb', line 27

def rb_idmap
  @ruby_idmap ||= V8::Weak::WeakValueMap.new
end

#to_ruby(v8_object) ⇒ Object


5
6
7
8
9
10
11
# File 'lib/v8/conversion/indentity.rb', line 5

def to_ruby(v8_object)
  if v8_object.class <= V8::C::Object
    v8_idmap[v8_object.GetIdentityHash()] || super(v8_object)
  else
    super(v8_object)
  end
end

#to_v8(ruby_object) ⇒ Object


13
14
15
16
# File 'lib/v8/conversion/indentity.rb', line 13

def to_v8(ruby_object)
  return super(ruby_object) if ruby_object.is_a?(String) || ruby_object.is_a?(Primitive)
  rb_idmap[ruby_object.object_id] || super(ruby_object)
end

#v8_idmapObject


23
24
25
# File 'lib/v8/conversion/indentity.rb', line 23

def v8_idmap
  @v8_idmap ||= V8::Weak::WeakValueMap.new
end