Ok, now I see: Template::Set() still accepts templates, so Template::Set() can still be used, just not with a function instance. I read the earlier thread I referenced as saying we should use SetAccessorProperty() with the template, as I did in my second code snippet, which of course doesn't work.
Thanks! On Sunday, June 5, 2016 at 8:14:30 PM UTC-7, Toon Verwaest wrote: > > If you want the value to be an instance of a template, you should just Set > the value to the template itself rather than the result of instantiating > the template. (So drop GetFunction()) > > Regards, > Toon > > On Mon, Jun 6, 2016, 02:13 Mark Logan <[email protected] <javascript:>> > wrote: > >> 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] <javascript:> >> 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] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- -- 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.
