Class: ExecJS::Runtime::Context
- Inherits:
-
Object
- Object
- ExecJS::Runtime::Context
- Defined in:
- lib/execjs/runtime.rb
Direct Known Subclasses
DuktapeRuntime::Context, ExternalRuntime::Context, GraalJSRuntime::Context, MiniRacerRuntime::Context, ExecJS::RubyRhinoRuntime::Context
Instance Method Summary collapse
-
#call(source, *args) ⇒ Object
Evaluates
source
as an expression (which should be of typefunction
), and calls the function with the given arguments. -
#eval(source, options = {}) ⇒ Object
Evaluates the
source
as an expression and returns the result. -
#exec(source, options = {}) ⇒ Object
Evaluates the
source
in the context of a function body and returns the returned value. -
#initialize(runtime, source = "", options = {}) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(runtime, source = "", options = {}) ⇒ Context
Returns a new instance of Context.
5 6 |
# File 'lib/execjs/runtime.rb', line 5 def initialize(runtime, source = "", = {}) 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")
31 32 33 |
# File 'lib/execjs/runtime.rb', line 31 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
21 22 23 |
# File 'lib/execjs/runtime.rb', line 21 def eval(source, = {}) 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)
13 14 15 |
# File 'lib/execjs/runtime.rb', line 13 def exec(source, = {}) raise NotImplementedError end |