Class: Dommy::Js::ConstructorResolver
- Inherits:
-
Object
- Object
- Dommy::Js::ConstructorResolver
- Defined in:
- lib/dommy/js/constructor_resolver.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.
A resolver, not a store: it holds no map and looks each name up live via the window. Named distinctly from Dommy::Bridge::ConstructorRegistry (the abstract name -> Bridge::Constructor map), which is a different thing.
Instance Attribute Summary collapse
-
#source ⇒ Object
writeonly
The window whose js_get exposes Event/CustomEvent/MouseEvent/… .
Instance Method Summary collapse
-
#initialize ⇒ ConstructorResolver
constructor
A new instance of ConstructorResolver.
-
#resolve(name) ⇒ Object
An object responding to js_new for
name, or nil ifnameisn't constructable (the bridge then makes the JS side throw).
Constructor Details
#initialize ⇒ ConstructorResolver
Returns a new instance of ConstructorResolver.
17 18 19 |
# File 'lib/dommy/js/constructor_resolver.rb', line 17 def initialize @source = nil end |
Instance Attribute Details
#source=(value) ⇒ Object (writeonly)
The window whose js_get exposes Event/CustomEvent/MouseEvent/… .
15 16 17 |
# File 'lib/dommy/js/constructor_resolver.rb', line 15 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).
23 24 25 26 27 28 29 |
# File 'lib/dommy/js/constructor_resolver.rb', line 23 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 |