Class: V8::Portal::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/v8/portal/templates.rb

Defined Under Namespace

Classes: Release

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(portal) ⇒ Templates

Returns a new instance of Templates.



8
9
10
11
12
13
14
# File 'lib/v8/portal/templates.rb', line 8

def initialize(portal)
  @portal = portal
  @constructors = {}
  @methods = {}
  @procs = {}
  @releases = {}
end

Instance Attribute Details

#portalObject (readonly)

Returns the value of attribute portal.



6
7
8
# File 'lib/v8/portal/templates.rb', line 6

def portal
  @portal
end

Instance Method Details

#proxiesObject



50
51
52
# File 'lib/v8/portal/templates.rb', line 50

def proxies
  @portal.proxies
end

#release(refs, id) ⇒ Object



54
55
56
57
58
# File 'lib/v8/portal/templates.rb', line 54

def release(refs, id)
  release = Release.new(@releases, refs, id)
  @releases[release] = true
  return release
end

#to_constructor(ruby_class) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/v8/portal/templates.rb', line 16

def to_constructor(ruby_class)
  class_id = ruby_class.object_id
  if constructor = @constructors[class_id]
    return constructor
  else
    constructor = @constructors[class_id] = ConstructorAdapter.new(self, class_id)
    ObjectSpace.define_finalizer(ruby_class, release(@constructors, class_id))
    return constructor
  end
end

#to_function(code) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/v8/portal/templates.rb', line 27

def to_function(code)
  case code
  when Method, UnboundMethod
    if fn = @methods[code.to_s]
      return fn
    else
      function = @methods[code.to_s] = FunctionAdapter.new(@portal, code)
      #TODO: test this weak behavior
      function.template.MakeWeak(0, release(@methods, code.to_s))
      return function
    end
  else
    if fn = @procs[code]
      return fn
    else
      function = @procs[code] = FunctionAdapter.new(@portal, code)
      #TODO: test this weak behavior
      function.template.MakeWeak(0, release(@procs, code))
      return function
    end
  end
end