Class: Dommy::Js::ConstructorRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/js/constructor_registry.rb

Overview

Resolves a JS constructor by interface name for reverse construction (‘new Event(…)`, `new DOMException(…)`). The window object is the source for most constructors — it exposes them via js_get — while a few not on the window are provided directly. Engine-agnostic.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConstructorRegistry

Returns a new instance of ConstructorRegistry.



13
14
15
# File 'lib/dommy/js/constructor_registry.rb', line 13

def initialize
  @source = nil
end

Instance Attribute Details

#source=(value) ⇒ Object (writeonly)

The window whose js_get exposes Event/CustomEvent/MouseEvent/… .



11
12
13
# File 'lib/dommy/js/constructor_registry.rb', line 11

def source=(value)
  @source = value
end

Instance Method Details

#resolve(name) ⇒ Object

An object responding to js_new for ‘name`, or nil if `name` isn’t constructable (the bridge then makes the JS side throw).



19
20
21
22
23
24
25
# File 'lib/dommy/js/constructor_registry.rb', line 19

def resolve(name)
  if @source.respond_to?(:__js_get__)
    ctor = @source.__js_get__(name)
    return ctor if ctor.respond_to?(:__js_new__)
  end
  extra(name)
end