Class: Johnson::Runtime
Overview
JavaScript interface DOM emulation ###
Constant Summary collapse
Instance Attribute Summary collapse
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
Class Method Summary collapse
- .new_browser(jq = false) ⇒ Object
- .runtime_set?(opts) ⇒ Boolean
-
.set_browser_for_curl(opts) ⇒ Object
CarierThread breaks if Multi has no work && CarierThread is joined so itwon’t last forever.
Instance Method Summary collapse
Instance Attribute Details
#thread_id ⇒ Object
Returns the value of attribute thread_id.
17 18 19 |
# File 'lib/rhack/js/johnson.rb', line 17 def thread_id @thread_id end |
Class Method Details
.new_browser(jq = false) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/rhack/js/johnson.rb', line 53 def new_browser(jq=false) rt = new %w{xmlw3cdom_1 xmlw3cdom_2 xmlsax env}.concat(jq ? ['jquery'] : []).each {|f| path = "#{BROWSER_PATH}/#{f}.js" rt.evaluate IO.read(path), path, 1 } rt.document = '' rt end |
.runtime_set?(opts) ⇒ Boolean
22 23 24 |
# File 'lib/rhack/js/johnson.rb', line 22 def runtime_set?(opts) !opts[:eval].b or (@@browser and @@browser.thread_id == Curl.carier_thread.object_id) end |
.set_browser_for_curl(opts) ⇒ Object
CarierThread breaks if Multi has no work && CarierThread is joined so itwon’t last forever.
Johnson is not thread safe => Runtime created in this thread will become unusable after CarierThread dies.
So we don’t use Curl.wait until Carier haven’t got whole request for this Runtime.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rhack/js/johnson.rb', line 35 def set_browser_for_curl(opts) unless runtime_set? opts if Curl.status Curl.recall Curl.debug 'recalled' end if opts[:thread_safe].b @@browser = new_browser(opts[:jq]) L.debug "#@@browser initialized in #{Thread.current}\nmain: #{Thread.main}; carier: #{Curl.carier_thread}" else L.debug 'about to run carier' Curl.execute {@@browser = new_browser(opts[:jq]) L.debug "#@@browser initialized in #{Thread.current}\nmain: #{Thread.main}; carier: #{Curl.carier_thread}"} sleep 0.01 until runtime_set? opts end end end |
Instance Method Details
#document=(html) ⇒ Object
65 66 67 |
# File 'lib/rhack/js/johnson.rb', line 65 def document=(html) evaluate "var document = new DOMDocument(#{html.to_doc.to_xhtml.inspect})" end |