Anton,
Thanks for the reply. Perhaps it will make it clearer if I provide
some context. I'm asking in the context of The Ruby Racer, which
allows for embedding V8 into Ruby, and in particular what ruby classes
look like from javascript.
Currently, we model ruby instances reflected into javascript as
instances created off of a FunctionTemplate which corresponds to that
instance's class. The FunctionTemplate corresponding to the ruby class
has property interceptors which it sets via
FunctionTemplate::InstanceTemplate()->Set{Named/Indexed}
PropertyHandler.
The problem comes when we actually embed the ruby classes themselves
into javascript. This is done by having the class's FunctionTemplate's
CallHandler invoke the ruby constructor of the class, and then
associat it with a javascript instance created by calling
GetFunction().NewInstance(). That way, the constructor can be
(optionally) called directly from javascript, and the object's
'constructor' will point to the right place.
However, ruby classes (like javascript constructors) are objects too
with their own properties and methods and so I would like to be able
to intercept access to properties against the constructor function
itself in the same way that I intercept property access on objects. In
one sentence: I want to delegate Function object properties to a ruby
object in the same way that I delegate regular object properties to a
ruby object.
Perhaps a little code would shed some light.
class SomeClass
#instance method
def one
1
end
end
#a class method
def SomeClass.two
2
end
cxt = V8::Context.new
cxt['SomeClass'] = SomeClass
cxt.eval(<<--JS)
var s = new SomeClass()
s.one //=> 1
s.constructor == SomeClass //=> true
SomeClass.two //=> currently undefined, I would like this to invoke
SomeClass.two()
JS
It could be that there is an obvious solution which I've missed, but
does that help frame the question?
cheers,
Charles
On Aug 9, 11:18 am, Anton Muhin <[email protected]> wrote:
> Sorry, from the right address.
>
>
>
> On Mon, Aug 9, 2010 at 8:16 PM, Anton Muhin <[email protected]> wrote:
> > Charles, good day,
>
> > On Mon, Aug 9, 2010 at 7:56 PM, Charles Lowell <[email protected]>
> > wrote:
> >> While we're on the subject of property interceptors and API
> >> asymmetries, I can't figure out to add named and indexed getter/
> >> setter, etc.. to Function objects inside the javascript runtime. I've
> >> searched extensively for a way to do this, but nothing as reliable as
> >> ObjectTemplate::SetNamedPropertyHandler()
>
> > I don't quite understand what do you mean by 'inside the javascript
> > runtime'? Do you want to invoke JS function? Or add native
> > interceptor to JS function (to be invoked as a constructor)?
>
> > AFAIK currently one can only add interceptors (both named and indexed)
> > to FunctionTemplates.
>
> > BTW, what are you trying to achieve? If you could tell us, maybe
> > there could be found some way out.
>
> > yours,
> > anton.
>
> >> On Aug 6, 12:49 pm, Anton Muhin <[email protected]> wrote:
> >>> From the right address.
>
> >>> On Fri, Aug 6, 2010 at 9:39 PM, Anton Muhin <[email protected]> wrote:
> >>> > Charles,
>
> >>> > I just didn't have to time to implement the same functionality for
> >>> > indexed interceptor. Filing a bug and cc'ing you.
>
> >>> > I'll try to implement it, but it might require some time to roll in to
> >>> > make transition to new api smooth.
>
> >>> > yours,
> >>> > anton.
>
> >>> > On Fri, Aug 6, 2010 at 9:31 PM, Charles Lowell
> >>> > <[email protected]> wrote:
> >>> >> Hi,
>
> >>> >> I've noticed a small asymmetry in the interfaces for
> >>> >> IndexedPropertyQuery and NamedPropertyQuery. Specifically that the
> >>> >> indexed version returns just a Boolean instead of and Integer encoding
> >>> >> property attributes. Is this intentional? Rhino, for example allows
> >>> >> for specifying attributes for indexed values as well.
>
> >>> >> cheers,
> >>> >> Charles
>
> >>> >> --
> >>> >> v8-users mailing list
> >>> >> [email protected]
> >>> >>http://groups.google.com/group/v8-users
>
> >> --
> >> v8-users mailing list
> >> [email protected]
> >>http://groups.google.com/group/v8-users
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users