Class: RunJS::SystemRuntime

Inherits:
Runtime
  • Object
show all
Defined in:
lib/runjs/system_runtime.rb

Direct Known Subclasses

D8, JScript, JavaScriptCore, Node, SpiderMonkey, V8

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runtime

#apply, #call, class_name, deprecated?, #eval

Methods included from Encoding

#encode

Constructor Details

#initializeSystemRuntime

Returns a new instance of SystemRuntime.



13
14
15
# File 'lib/runjs/system_runtime.rb', line 13

def initialize
  @context = []
end

Class Attribute Details

.cmdObject

Returns the value of attribute cmd.



6
7
8
# File 'lib/runjs/system_runtime.rb', line 6

def cmd
  @cmd
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/runjs/system_runtime.rb', line 9

def self.available?
  OS.which(@cmd)
end

Instance Method Details

#context(js) ⇒ Object



17
18
19
20
# File 'lib/runjs/system_runtime.rb', line 17

def context(js)
  @context << encode(js, 'UTF-8')
  self
end

#run(js) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/runjs/system_runtime.rb', line 22

def run(js)
  js = encode(js, 'UTF-8')
  js = merge_context(js)
  js = merge_runner(js)
  result = popen(js)
  parse_json(result, js)
end