Class: ExecJS::PCRuntime::ContextProcessRuntime::Context

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

Overview

implementation of ExecJS::Runtime::Context

Instance Method Summary collapse

Constructor Details

#initialize(runtime, source = '', options = {}) ⇒ Context

Returns a new instance of Context.

Parameters:

  • runtime (String)

    Instance of ContextProcessRuntime

  • source (String) (defaults to: '')

    JavaScript source code that Runtime load at startup

  • options (any) (defaults to: {})


19
20
21
22
23
24
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 19

def initialize(runtime, source = '', options = {})
  super

  # @type [JSRuntimeHandle]
  @runtime = runtime.create_runtime_handle source.encode('UTF-8')
end

Instance Method Details

#call(identifier, *args) ⇒ Object

implementation of ExecJS::Runtime:Context#call

Parameters:

  • identifier (String)
  • args (Array<_ToJson>)


45
46
47
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 45

def call(identifier, *args)
  @runtime.evaluate("(#{identifier}).apply(this, #{::JSON.generate(args)})")
end

#eval(source, _options = {}) ⇒ Object

implementation of ExecJS::Runtime::Context#eval

Parameters:

  • source (String)
  • _options (any) (defaults to: {})


29
30
31
32
33
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 29

def eval(source, _options = {})
  return unless /\S/.match?(source)

  @runtime.evaluate("(#{source.encode('UTF-8')})")
end

#exec(source, _options = {}) ⇒ Object

implementation of ExecJS::Runtime::Context#exec

Parameters:

  • source (String)
  • _options (any) (defaults to: {})


38
39
40
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 38

def exec(source, _options = {})
  @runtime.evaluate("(()=>{#{source.encode('UTF-8')}})()")
end