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 <[email protected]> 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 <[email protected]> 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
>>>
>> [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.
>>>
>> --
> --
> 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.
>

-- 
-- 
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.

Reply via email to