Class: Mustang::Context
- Defined in:
- lib/mustang/context.rb
Overview
Extended and more user-friendly version of Mustang::V8::Context
.
Instance Method Summary collapse
-
#errors ⇒ Object
Returns list of errors encountered within this context.
-
#evaluate(source, locals = {}, filename = "<eval>") ⇒ Object
(also: #eval)
Evaluates given javascript source.
-
#load(*files) ⇒ Object
Loads and evaluates given list of javascript files, eg:.
Instance Method Details
#errors ⇒ Object
Returns list of errors encountered within this context.
39 40 41 |
# File 'lib/mustang/context.rb', line 39 def errors @errors ||= [] end |
#evaluate(source, locals = {}, filename = "<eval>") ⇒ Object Also known as: eval
16 17 18 19 20 |
# File 'lib/mustang/context.rb', line 16 def evaluate(source, locals={}, filename="<eval>") res = super(source, filename) errors << res if res.v8? and res.error? return res end |
#load(*files) ⇒ Object
Loads and evaluates given list of javascript files, eg:
rt = Mustang::Runtime.new
rt.load("foo.js", "bar.js")
28 29 30 31 32 33 34 35 36 |
# File 'lib/mustang/context.rb', line 28 def load(*files) files.map { |filename| if File.exists?(filename) evaluate(File.read(filename), {}, filename) else raise ScriptNotFoundError, "Script `#{filename}' does not exts." end }.last end |