Class: Spade::Runtime::Context
- Inherits:
-
V8::Context
- Object
- V8::Context
- Spade::Runtime::Context
- Defined in:
- lib/spade/runtime/context.rb
Overview
Creates a basic context suitable for running modules. The environments setup in this context will mimic a browser worker thread context, including timeouts and a console. A navigator object is also defined that provides some general information about the context.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#reactor ⇒ Object
readonly
Returns the value of attribute reactor.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Context
constructor
Load the spade and racer-loader.
- #require(mod_name) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Context
Load the spade and racer-loader.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/spade/runtime/context.rb', line 29 def initialize(opts={}) @reactor = opts[:reactor] @verbose = opts[:verbose] super(opts) do |ctx| ctx['reactor'] = @reactor ctx['console'] = Console.new ctx['window'] = ctx.scope ctx.eval %[ (function() { var r = reactor; setTimeout = function(c,i) { return r.set_timeout(c,i); }; setInterval = function(c,i) { return r.set_interval(c,i); }; clearTimeout = function(t) { return r.clear_timeout(t); }; clearInterval = function(t) { return r.clear_interval(t); }; navigator = { appName: 'spade', appVersion: "#{Spade::Runtime::VERSION}", platform: "#{RUBY_PLATFORM}", userAgent: 'spade #{Spade::Runtime::VERSION}; #{RUBY_PLATFORM}' } exit = function(status) { return r.exit(status || 0); }; })(); ] ctx['reactor'] = nil yield(ctx) if block_given? end end |
Instance Attribute Details
#reactor ⇒ Object (readonly)
Returns the value of attribute reactor.
21 22 23 |
# File 'lib/spade/runtime/context.rb', line 21 def reactor @reactor end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
22 23 24 |
# File 'lib/spade/runtime/context.rb', line 22 def verbose @verbose end |
Instance Method Details
#require(mod_name) ⇒ Object
24 25 26 |
# File 'lib/spade/runtime/context.rb', line 24 def require(mod_name) self.eval("require('#{mod_name}');"); end |