Class: V8::Portal
- Defined in:
- lib/v8/portal.rb,
lib/v8/portal/caller.rb,
lib/v8/portal/proxies.rb,
lib/v8/portal/function.rb,
lib/v8/portal/templates.rb,
lib/v8/portal/constructor.rb,
lib/v8/portal/interceptors.rb
Defined Under Namespace
Classes: Caller, ConstructorAdapter, FunctionAdapter, Interceptors, Proxies, Templates
Instance Attribute Summary collapse
-
#access ⇒ Object
readonly
Returns the value of attribute access.
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#interceptors ⇒ Object
readonly
Returns the value of attribute interceptors.
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#initialize(context, access) ⇒ Portal
constructor
A new instance of Portal.
- #open ⇒ Object
- #rb(value) ⇒ Object
- #v8(value) ⇒ Object
Constructor Details
#initialize(context, access) ⇒ Portal
Returns a new instance of Portal.
6 7 8 9 10 11 12 |
# File 'lib/v8/portal.rb', line 6 def initialize(context, access) @context, @access = context, access @proxies = Proxies.new @templates = Templates.new(self) @interceptors = Interceptors.new(self) @caller = Caller.new(self) end |
Instance Attribute Details
#access ⇒ Object (readonly)
Returns the value of attribute access.
4 5 6 |
# File 'lib/v8/portal.rb', line 4 def access @access end |
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
4 5 6 |
# File 'lib/v8/portal.rb', line 4 def caller @caller end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/v8/portal.rb', line 4 def context @context end |
#interceptors ⇒ Object (readonly)
Returns the value of attribute interceptors.
4 5 6 |
# File 'lib/v8/portal.rb', line 4 def interceptors @interceptors end |
#proxies ⇒ Object (readonly)
Returns the value of attribute proxies.
4 5 6 |
# File 'lib/v8/portal.rb', line 4 def proxies @proxies end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
4 5 6 |
# File 'lib/v8/portal.rb', line 4 def templates @templates end |
Instance Method Details
#open ⇒ Object
14 15 16 17 18 |
# File 'lib/v8/portal.rb', line 14 def open @context.native.enter do yield(self) end if block_given? end |
#rb(value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/v8/portal.rb', line 20 def rb(value) @proxies.js2rb(value) do case value when V8::C::Function then V8::Function.new(value, self) when V8::C::Array then V8::Array.new(value, self) when V8::C::Object then V8::Object.new(value, self) when V8::C::String then value.Utf8Value.tap {|s| return s.respond_to?(:force_encoding) ? s.force_encoding("UTF-8") : s} when V8::C::Date then Time.at(value.NumberValue() / 1000) when V8::C::StackTrace then V8::StackTrace.new(self, value) when V8::C::Value then nil if value.IsEmpty() else value end end end |
#v8(value) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/v8/portal.rb', line 36 def v8(value) case value when V8::Object value.instance_eval {@native} when String C::String::New(value) when Symbol C::String::NewSymbol(value.to_s) when Proc,Method,UnboundMethod @proxies.rb2js(value) do @templates.to_function(value).function end when ::Array C::Array::New(value.length).tap do |a| value.each_with_index do |item, i| a.Set(i, v8(item)) end end when ::Hash C::Object::New().tap do |o| value.each do |key, val| o.Set(v8(key), v8(val)) end end when ::Time C::Date::New(value.to_f * 1000) when ::Class @proxies.rb2js(value) do constructor = @templates.to_constructor(value) constructor.exposed = true constructor.function end when nil,Numeric,TrueClass,FalseClass, C::Value value else @proxies.rb2js(value) do @templates.to_constructor(value.class).allocate(value) end end end |