Class: ExecJS::PCRuntime::ContextProcessRuntime

Inherits:
Runtime
  • Object
show all
Defined in:
lib/execjs/pcruntime/context_process_runtime.rb

Overview

implementation of ExecJS::Runtime

Defined Under Namespace

Classes: Context, JSRuntimeHandle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, command, runner_path = File.expand_path('runner.js', __dir__), deprecated: false) ⇒ ContextProcessRuntime

Returns a new instance of ContextProcessRuntime.

Parameters:

  • name (String)

    name of Runtime

  • command (Array<String>)

    candidates for JavaScript Runtime commands such as [‘deno run’, ‘node’]

  • runner_path (String) (defaults to: File.expand_path('runner.js', __dir__))

    path of the .js file to run in the Runtime



247
248
249
250
251
252
253
254
255
256
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 247

def initialize(name, command, runner_path = File.expand_path('runner.js', __dir__), deprecated: false)
  super()
  @name = name
  @command = command
  @runner_path = runner_path
  @binary = nil
  @deprecated = deprecated
  # limit number of threads 128 to avoid Errno::ECONNREFUSED
  @semaphore = Semaphore.new 128
end

Instance Attribute Details

#nameObject (readonly)

rubocop:enable Metrics/ClassLength



242
243
244
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 242

def name
  @name
end

Instance Method Details

#available?Boolean

implementation of ExecJS::Runtime#available?

Returns:

  • (Boolean)


259
260
261
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 259

def available?
  binary ? true : false
end

#create_runtime_handle(compile_source) ⇒ JSRuntimeHandle

Launch JavaScript Runtime and return its handle.

Returns:



270
271
272
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 270

def create_runtime_handle(compile_source)
  JSRuntimeHandle.new(binary, @runner_path, compile_source, @semaphore)
end

#deprecated?Boolean

override ExecJS::Runtime#deprecated?

Returns:

  • (Boolean)


264
265
266
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 264

def deprecated?
  @deprecated
end