Class: ExecJS::Runtime::Context

Inherits:
Object
  • Object
show all
Includes:
Encoding
Defined in:
lib/execjs/runtime.rb

Instance Method Summary collapse

Methods included from Encoding

#encode

Constructor Details

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

Returns a new instance of Context.



9
10
# File 'lib/execjs/runtime.rb', line 9

def initialize(runtime, source = "", options = {})
end

Instance Method Details

#call(source, *args) ⇒ Object

Evaluates source as an expression (which should be of type function), and calls the function with the given arguments. The function will be evaluated with the global object as this.

context.call("function(a, b) { return a + b }", 1, 1) # => 2
context.call("CoffeeScript.compile", "1 + 1")

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/execjs/runtime.rb', line 35

def call(source, *args)
  raise NotImplementedError
end

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

Evaluates the source as an expression and returns the result.

context.eval("1")        # => 1
context.eval("return 1") # => Raises SyntaxError

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/execjs/runtime.rb', line 25

def eval(source, options = {})
  raise NotImplementedError
end

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

Evaluates the source in the context of a function body and returns the returned value.

context.exec("return 1") # => 1
context.exec("1")        # => nil (nothing was returned)

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/execjs/runtime.rb', line 17

def exec(source, options = {})
  raise NotImplementedError
end