From ad0ab1bdded9e02f7bc92ed089b5553bbfb91f68 Mon Sep 17 00:00:00 2001 From: Magnus Holm Date: Sat, 2 Jun 2018 21:51:55 +0200 Subject: [PATCH] Add documentation for the Context methods --- lib/execjs/runtime.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/execjs/runtime.rb b/lib/execjs/runtime.rb index eba424c..822bf5a 100644 --- a/lib/execjs/runtime.rb +++ b/lib/execjs/runtime.rb @@ -9,15 +9,30 @@ module ExecJS def initialize(runtime, source = "", options = {}) end + # 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) def exec(source, options = {}) raise NotImplementedError end + # Evaluates the +source+ as an expression and returns the result. + # + # context.eval("1") # => 1 + # context.eval("return 1") # => Raises SyntaxError def eval(source, options = {}) raise NotImplementedError end - def call(properties, *args) + # 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") + def call(source, *args) raise NotImplementedError end end