Skip to content

Commit ad0ab1b

Browse files
committed
Add documentation for the Context methods
1 parent 5f78865 commit ad0ab1b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/execjs/runtime.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,30 @@ class Context
99
def initialize(runtime, source = "", options = {})
1010
end
1111

12+
# Evaluates the +source+ in the context of a function body and returns the
13+
# returned value.
14+
#
15+
# context.exec("return 1") # => 1
16+
# context.exec("1") # => nil (nothing was returned)
1217
def exec(source, options = {})
1318
raise NotImplementedError
1419
end
1520

21+
# Evaluates the +source+ as an expression and returns the result.
22+
#
23+
# context.eval("1") # => 1
24+
# context.eval("return 1") # => Raises SyntaxError
1625
def eval(source, options = {})
1726
raise NotImplementedError
1827
end
1928

20-
def call(properties, *args)
29+
# Evaluates +source+ as an expression (which should be of type
30+
# +function+), and calls the function with the given arguments.
31+
# The function will be evaluated with the global object as +this+.
32+
#
33+
# context.call("function(a, b) { return a + b }", 1, 1) # => 2
34+
# context.call("CoffeeScript.compile", "1 + 1")
35+
def call(source, *args)
2136
raise NotImplementedError
2237
end
2338
end

0 commit comments

Comments
 (0)