If embedders don't want to have multiple Callees instantiated from the same FunctionTemplate, Jochen's solution works. If that's the case, they could also just mark the function-template as caching, and "reinstantiate the template" in the context. That will return the cached function without needing to install it on data.
On Fri, Dec 11, 2015 at 10:57 AM Enrico Pertoso <epert...@chromium.org> wrote: > I think Jochen's solution would be better in the long term. Keeping > Callee() and instantiating a FunctionTemplate if it gets called seems > slightly more complex. > > In the meantime, should I revert the change (marking Callee as deprecated > or deprecate soon)? > > On Friday, December 11, 2015 at 8:48:22 AM UTC+1, Jochen Eisinger wrote: > >> One alternative to using Callee for functions you created yourself is >> specifying the data parameter which is passed via FunctionCallbackInfo::Data >> >> Data could be an External that points to a data structure holding a weak >> Global pointing back at the function. >> >> Would that work for you? >> >> On Fri, Dec 11, 2015, 8:41 AM Toon Verwaest <verw...@chromium.org> wrote: >> > The difference is that FunctionTemplates are (supposedly) unique for the >>> entire isolate, whereas JSFunctions are instantiated per native context. So >>> if you use multiple realms (iframes in a browser setting), you'd be getting >>> multiple Callees (jsfunction) for the same callback (FunctionTemplate). >>> >>> Preallocating all of those is expensive memory-wise and in terms of >>> context-initialization. Getting to all-can-read accessors (jsfunction from >>> the accessing context rather than the installed accessor) is either >>> expensive performance-wise while accessing; or makes the memory and >>> initialization issues even worse. >>> >>> My thinking now is that we could hide the cost inside of info.Callee(), >>> by instantiating the FunctionTemplate in the current (accessing) context if >>> the value passed in was null or some other sentinel. That makes it slightly >>> more expensive for regular templates (the null check), and quite a bit more >>> for lazy instantiated templates that access Callee. The latter should just >>> not be used in that scenario... >>> >>> On Thu, Dec 10, 2015, 23:25 Alex Kodat <alex...@gmail.com> wrote: >>> >>>> That makes great sense to me and would be much appreciated. Though I'll >>>> admit I don't really understand what it means to call a FunctionTemplate. I >>>> guess for C++ code there really isn't any containing JS scope so the >>>> distinction between Function and FunctionTemplate is kinda (largely?) >>>> meaningless? >>>> >>>> >>>> On Thursday, December 10, 2015 at 1:25:38 PM UTC-8, Toon Verwaest wrote: >>>> >>>>> The reasoning behind this change is that in the future we'll have >>>>> FunctionTemplates that can be called through accessors without even >>>>> allocating the JSFunction. Registering the last called value isn't >>>>> possible >>>>> in that case... >>>>> >>>>> Perhaps rather than fully getting rid of the parameter we should >>>>> change the API to pass undefined if there is no closure. In that case the >>>>> FunctionTemplate would need to be instantiated manually through the API to >>>>> get to the callee. >>>>> >>>>> Wdyt Enrico? >>>>> Toon >>>>> >>>>> On Thu, Dec 10, 2015, 20:59 Alex Kodat <alex...@gmail.com> wrote: >>>>> >>>> Sorry if this would have been more appropriate on v8-dev but just >>>>>> downloaded the latest and greatest 4.9 commit and discovered that Callee >>>>>> is >>>>>> no longer available in FunctionCallBackInfo. While I'm sure there was a >>>>>> good reason for this, my sample size of one embedder registers one >>>>>> "ouch". >>>>>> Dunno if this affects any other embedders but I guess this is a head's up >>>>>> in case anyone wants to check. >>>>>> >>>>>> I currently use Callee as a convenience when passing around >>>>>> FunctionCallBackInfo: for adding the function name to a Throw or as >>>>>> debugging information it's very convenient. Callee is also very useful in >>>>>> the common pattern of allowing a constructor to be called without a New >>>>>> and >>>>>> invoking it as a constructor under the covers: >>>>>> args.Callee()->NewInstance(argc, argsForConstructor). >>>>>> >>>>>> The former use is easy to work around but painful as I now need to >>>>>> add an extra parameter to a ton of internal C++ methods. The latter is >>>>>> more >>>>>> challenging as I now need to add a persistent reference to all my C++ >>>>>> constructors. >>>>>> >>>>>> I guess I'll just suck it up but if this affects anyone else one way >>>>>> to help people deal with this would be to keep a weak reference in the >>>>>> Isolate to last C++ function called that's made available via something >>>>>> like isolate->LastCallee(). I'd be happy to submit a project to add such >>>>>> a >>>>>> call (obviously on purely selfish grounds) but I suspect it would be >>>>>> (justifiably) rejected if I'm the world's only user of Callee. >>>>>> >>>>>> So are there any others out there? >>>>>> >>>>>> Thanks >>>>>> >>>>>> -- >>>>>> -- >>>>>> v8-users mailing list >>>>>> >>>>> v8-u...@googlegroups.com >>>>> >>>>> >>>>>> 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 v8-users+u...@googlegroups.com. >>>>> >>>>> >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> -- >>>> -- >>>> v8-users mailing list >>>> v8-u...@googlegroups.com >>>> 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 v8-users+u...@googlegroups.com. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >>> -- >>> v8-users mailing list >>> v8-u...@googlegroups.com >>> 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 v8-users+u...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > -- > v8-users mailing list > v8-users@googlegroups.com > 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 v8-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list v8-users@googlegroups.com 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 v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.