Class: Opal::CliRunners::Chrome

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/cli_runners/chrome.rb

Constant Summary

SCRIPT_PATH =
File.expand_path('../chrome.js', __FILE__).freeze
DEFAULT_CHROME_HOST =
'localhost'.freeze
DEFAULT_CHROME_PORT =
9222.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Chrome

Returns a new instance of Chrome



14
15
16
# File 'opal/lib/opal/cli_runners/chrome.rb', line 14

def initialize(options)
  @output = options.fetch(:output, $stdout)
end

Instance Attribute Details

#exit_statusObject (readonly)

Returns the value of attribute exit_status



17
18
19
# File 'opal/lib/opal/cli_runners/chrome.rb', line 17

def exit_status
  @exit_status
end

#outputObject (readonly)

Returns the value of attribute output



17
18
19
# File 'opal/lib/opal/cli_runners/chrome.rb', line 17

def output
  @output
end

Instance Method Details

#run(code, argv) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'opal/lib/opal/cli_runners/chrome.rb', line 19

def run(code, argv)
  with_chrome_server do
    cmd = [
      'env',
      "CHROME_HOST=#{chrome_host}",
      "CHROME_PORT=#{chrome_port}",
      'node',
      SCRIPT_PATH,
    ]

    IO.popen(cmd, 'w', out: output) do |io|
      io.write(code)
    end

    @exit_status = $?.exitstatus
  end
end