Class: Jscall::Imported

Inherits:
Object
  • Object
show all
Defined in:
lib/jscall.rb

Overview

outbound references from Ruby to Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeImported

Returns a new instance of Imported.



137
138
139
140
141
# File 'lib/jscall.rb', line 137

def initialize
    ary = Array.new(Jscall::TableSize, nil)
    @objects = HiddenRef.new(ary)
    @canary = WeakRef.new(RemoteRef.new(-1))
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



135
136
137
# File 'lib/jscall.rb', line 135

def objects
  @objects
end

Instance Method Details

#dead_referencesObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/jscall.rb', line 160

def dead_references()
    if @canary&.weakref_alive?
        return []
    else
        @canary = WeakRef.new(RemoteRef.new(-1))
    end
    deads = []
    objects = @objects.__getobj__
    objects.each_index do |index|
        wref = objects[index]
        if !wref.nil? && !wref.weakref_alive?
            objects[index] = nil
            deads << index
        end
    end
    deads
end

#import(index) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/jscall.rb', line 143

def import(index)
    objects = @objects.__getobj__
    wref = objects[index]
    if  wref&.weakref_alive?
        wref.__getobj__
    else
        rref = RemoteRef.new(index)
        objects[index] = WeakRef.new(rref)
        rref
    end
end

#kill_canaryObject

forces dead_references() to check the liveness of references.



156
157
158
# File 'lib/jscall.rb', line 156

def kill_canary
    @canary = nil
end