Class: V8::Portal::ConstructorAdapter
- Defined in:
- lib/v8/portal/constructor.rb
Instance Attribute Summary collapse
-
#exposed ⇒ Object
(also: #exposed?)
Returns the value of attribute exposed.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #allocate(object) ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #function ⇒ Object
-
#initialize(templates, class_id) ⇒ ConstructorAdapter
constructor
A new instance of ConstructorAdapter.
- #invoke(arguments) ⇒ Object
- #portal ⇒ Object
- #proxies ⇒ Object
- #ruby_class ⇒ Object
Constructor Details
#initialize(templates, class_id) ⇒ ConstructorAdapter
Returns a new instance of ConstructorAdapter.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/v8/portal/constructor.rb', line 8 def initialize(templates, class_id) @exposed = false @class_id = class_id @templates = templates @invoke = method(:invoke) @template = C::FunctionTemplate::New(@invoke) portal.interceptors.setup(@template.InstanceTemplate()) cls = self.ruby_class superclass = cls.superclass if cls != ::Object && superclass != ::Object && superclass != ::Class @template.Inherit(templates.to_constructor(superclass).template) end if cls.name && cls.name =~ /(::)?(\w+?)$/ template.SetClassName(C::String::NewSymbol("rb::" + $2)) else template.SetClassName("Ruby") end end |
Instance Attribute Details
#exposed ⇒ Object Also known as: exposed?
Returns the value of attribute exposed.
5 6 7 |
# File 'lib/v8/portal/constructor.rb', line 5 def exposed @exposed end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/v8/portal/constructor.rb', line 5 def template @template end |
Instance Method Details
#allocate(object) ⇒ Object
31 32 33 34 35 |
# File 'lib/v8/portal/constructor.rb', line 31 def allocate(object) arguments = C::Array::New(1) arguments.Set(0, C::External::New(object)) function.NewInstance(arguments) end |
#disable ⇒ Object
37 38 39 |
# File 'lib/v8/portal/constructor.rb', line 37 def disable @disabled = true end |
#enable ⇒ Object
41 42 43 |
# File 'lib/v8/portal/constructor.rb', line 41 def enable @disabled = nil end |
#function ⇒ Object
27 28 29 |
# File 'lib/v8/portal/constructor.rb', line 27 def function @template.GetFunction() end |
#invoke(arguments) ⇒ Object
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 |
# File 'lib/v8/portal/constructor.rb', line 45 def invoke(arguments) return if @disabled if !@exposed unless arguments.Length() == 1 && arguments[0].kind_of?(C::External) C::ThrowException(C::Exception::Error(C::String::New("cannot call native constructor from javascript"))) else object = arguments[0].Value() proxies.register_javascript_proxy arguments.This(), :for => object end else instance = nil if arguments.Length() > 0 && arguments[0].kind_of?(C::External) instance = arguments[0].Value() else = [] for i in 0..arguments.Length() - 1 << @templates.portal.rb(arguments[i]) end instance = portal.caller.raw do self.ruby_class.new(*) end end proxies.register_javascript_proxy arguments.This(), :for => instance end end |
#portal ⇒ Object
93 94 95 |
# File 'lib/v8/portal/constructor.rb', line 93 def portal @templates.portal end |
#proxies ⇒ Object
89 90 91 |
# File 'lib/v8/portal/constructor.rb', line 89 def proxies @templates.proxies end |
#ruby_class ⇒ Object
85 86 87 |
# File 'lib/v8/portal/constructor.rb', line 85 def ruby_class ObjectSpace._id2ref(@class_id) end |