Class: Puppeteer::DOMWorld::BindingFunction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, proc:) ⇒ BindingFunction

Returns a new instance of BindingFunction.



8
9
10
11
# File 'lib/puppeteer/dom_world.rb', line 8

def initialize(name:, proc:)
  @name = name
  @proc = proc
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/puppeteer/dom_world.rb', line 17

def name
  @name
end

Instance Method Details

#call(*args) ⇒ Object



13
14
15
# File 'lib/puppeteer/dom_world.rb', line 13

def call(*args)
  @proc.call(*args)
end

#page_binding_init_stringObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppeteer/dom_world.rb', line 19

def page_binding_init_string
  "  (type, bindingName) => {\n    /* Cast window to any here as we're about to add properties to it\n     * via win[bindingName] which TypeScript doesn't like.\n     */\n    const win = window;\n    const binding = win[bindingName];\n\n    win[bindingName] = (...args) => {\n      const me = window[bindingName];\n      let callbacks = me.callbacks;\n      if (!callbacks) {\n        callbacks = new Map();\n        me.callbacks = callbacks;\n      }\n      const seq = (me.lastSeq || 0) + 1;\n      me.lastSeq = seq;\n      const promise = new Promise((resolve, reject) =>\n        callbacks.set(seq, { resolve, reject })\n      );\n      binding(JSON.stringify({ type, name: bindingName, seq, args }));\n      return promise;\n    };\n  }\n  JAVASCRIPT\nend\n"