This is a very similar (perhaps identical) question to:
https://groups.google.com/forum/#!searchin/v8-users/SetAccessorProperty/v8-users/_u6dmOLAEnY/p3ErLIpoAAAJ,
but unfortunately I couldn't learn enough from that thread. (Also: The v8
embedder's guide is out of date, and I read all the uses of
Template::SetAccessorProperty in the v8 tests but found no help there.)
One used to be able to do the following:
Local<FunctionTemplate> ctor = FunctionTemplate::New(...); // make a
constructor
auto prototype = ctor->PrototypeTemplate();
prototype->Set(String::NewFromUtf8("functionName"),
FunctionTemplate::New(...)->GetFunction());
Now that Set is banned from accepting non-primitive values, we're directed
to use SetAccessorProperty for this sort of thing. My reading of the thread
that I linked above suggests that I should write the following:
Local<FunctionTemplate> ctor = FunctionTemplate::New(...); // make a
constructor
auto prototype = ctor->PrototypeTemplate();
prototype->SetAccessorProperty(String::NewFromUtf8("functionName"),
FunctionTemplate::New(...));
However, according to my reading of the API, this shouldn't work, because
we'd need to pass in a FunctionTemplate for a getter function that returns
the function I actually want to install. And indeed, this code doesn't seem
to work - the handler I provide for the FunctionTemplate is called with 0
arguments, just as if a getter were expected here.
Creating a FunctionTemplate for a getter that returns a function is, as far
as I can tell, impossible to do easily and efficiently in the v8 API (how
do you create the function in advance and make it available to the getter?
A lambda won't work.)
What's the right way to do this?
Thanks,
Mark
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.