Class: ExecJS::GraalJSRuntime::Context

Inherits:
Runtime::Context show all
Defined in:
lib/execjs/graaljs_runtime.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Context.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/execjs/graaljs_runtime.rb', line 6

def initialize(runtime, source = "", options = {})
  @context = Polyglot::InnerContext.new
  @context.eval('js', 'delete this.console')
  @js_object = @context.eval('js', 'Object')

  source = source.encode(Encoding::UTF_8)
  unless source.empty?
    translate do
      eval_in_context(source)
    end
  end
end

Instance Method Details

#call(source, *args) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/execjs/graaljs_runtime.rb', line 37

def call(source, *args)
  source = source.encode(Encoding::UTF_8)
  source = "(#{source})" if /\S/.match?(source)

  translate do
    function = eval_in_context(source)
    function.call(*convert_ruby_to_js(args))
  end
end

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



28
29
30
31
32
33
34
35
# File 'lib/execjs/graaljs_runtime.rb', line 28

def eval(source, options = {})
  source = source.encode(Encoding::UTF_8)
  source = "(#{source})" if /\S/.match?(source)

  translate do
    eval_in_context(source)
  end
end

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



19
20
21
22
23
24
25
26
# File 'lib/execjs/graaljs_runtime.rb', line 19

def exec(source, options = {})
  source = source.encode(Encoding::UTF_8)
  source = "(function(){#{source}})()" if /\S/.match?(source)

  translate do
    eval_in_context(source)
  end
end