Class: Mustang::Context
- Inherits:
-
V8::Context
- Object
- V8::Context
- Mustang::Context
- Defined in:
- lib/mustang/context.rb
Overview
Extended and more user-friendly version of Mustang::V8::Context
.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from 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.
-
#global? ⇒ Boolean
Returns
true
when it is global (immortal) context. -
#load(*files) ⇒ Object
Loads and evaluates given list of javascript files, eg:.
Methods inherited from V8::Context
#enter, #entered?, #exit, #get, #global, new, #prototype, #set
Instance Method Details
#errors ⇒ Object
Returns list of errors encountered within this context.
43 44 45 |
# File 'lib/mustang/context.rb', line 43 def errors @errors ||= [] end |
#evaluate(source, locals = {}, filename = "<eval>") ⇒ Object Also known as: eval
20 21 22 23 24 |
# File 'lib/mustang/context.rb', line 20 def evaluate(source, locals={}, filename="<eval>") res = super(source, filename) errors << res if res.v8? and res.error? return res end |
#global? ⇒ Boolean
Returns true
when it is global (immortal) context.
48 49 50 |
# File 'lib/mustang/context.rb', line 48 def global? false end |
#load(*files) ⇒ Object
Loads and evaluates given list of javascript files, eg:
rt = Mustang::Runtime.new
rt.load("foo.js", "bar.js")
32 33 34 35 36 37 38 39 40 |
# File 'lib/mustang/context.rb', line 32 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 |