Farewell Callee

246 views
Skip to first unread message

Alex Kodat

unread,
Dec 10, 2015, 2:59:53 PM12/10/15
to v8-users
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

Toon Verwaest

unread,
Dec 10, 2015, 4:25:38 PM12/10/15
to v8-users, Enrico Pertoso

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


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

Alex Kodat

unread,
Dec 10, 2015, 5:25:45 PM12/10/15
to v8-users, eper...@chromium.org
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?    

Toon Verwaest

unread,
Dec 11, 2015, 2:41:26 AM12/11/15
to v8-users, eper...@chromium.org

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

Jochen Eisinger

unread,
Dec 11, 2015, 2:48:22 AM12/11/15
to v8-users, eper...@chromium.org

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?

Enrico Pertoso

unread,
Dec 11, 2015, 4:57:46 AM12/11/15
to v8-users, eper...@chromium.org
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)?

Toon Verwaest

unread,
Dec 11, 2015, 5:16:01 AM12/11/15
to v8-users, eper...@chromium.org
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.

Toon Verwaest

unread,
Dec 11, 2015, 5:19:56 AM12/11/15
to Toon Verwaest, v8-users, eper...@chromium.org
Mmh, it doesn't seem possible to instantiated non-caching function-templates multiple times. Nevermind then ;)
Message has been deleted

Jochen Eisinger

unread,
Dec 11, 2015, 5:23:26 AM12/11/15
to v8-u...@googlegroups.com, Toon Verwaest
I just saw that node.js/nan also uses Callee() so we should try to figure out a way to keep it

On Fri, Dec 11, 2015 at 11:20 AM Enrico Pertoso <eper...@chromium.org> wrote:
I'm reverting in the meantime.

Enrico Pertoso

Software Engineer

eper...@google.com

Google Germany GmbH

Dienerstraße 12

80331 München


Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen Sie die E-Mail und alle Anhänge. Vielen Dank.

      

This e-mail is confidential. If you are not the right addressee please do not forward it, please inform the sender, and please erase this e-mail including any attachments. Thanks.

Ben Noordhuis

unread,
Dec 11, 2015, 5:55:07 AM12/11/15
to v8-u...@googlegroups.com, Toon Verwaest
On Fri, Dec 11, 2015 at 11:23 AM, Jochen Eisinger <joc...@chromium.org> wrote:
> I just saw that node.js/nan also uses Callee() so we should try to figure out a way to keep it

FWIW, node.js core doesn't use .Callee() and I don't think there are
many (if any) add-ons that use the nan wrapper.

Enrico Pertoso

unread,
Dec 11, 2015, 8:21:42 AM12/11/15
to v8-users, verw...@chromium.org
Update: we reverted the cl for now, so Callee() is back.

Alex Kodat

unread,
Dec 12, 2015, 1:44:19 AM12/12/15
to v8-users, verw...@chromium.org
First, I'm really impressed with this group's responsiveness. Awesome!

Second, I apologize if I gave folks extra work to do -- my intent was simply to give a heads up to other embedders. As it turns out, I was able to get rid of my two Callee uses. Jochen's suggestion caused a neuron to fire and I realized that I could just use the FunctionTemplate constructor data parameter to pass whatever I needed to args.Data(). In the cases where I just needed the function name, I simply set data to reference a String with the name. In the cases where I needed a name and constructor, I simply set data to reference an object with property "name" and property "constructor", the latter set after the function was instantiated (so the FunctionTemplate had an indirect forward reference to its Function).

Dunno if similar techniques could be used to compensate for the loss of Callee out in the wild but it took all of two hours to get rid of mine, anyway. And now that *I* don't need Callee any more, I can argue for reducing the weight of FunctionCallbackInfo. ;-)

Toon Verwaest

unread,
Dec 12, 2015, 12:37:08 PM12/12/15
to Alex Kodat, v8-users, verw...@chromium.org

So it sounds like we can move forward with this change without too much hassle for embedders anyway. Awesome.

Rom Grk

unread,
Jun 12, 2018, 10:02:01 PM6/12/18
to v8-users
So there's no way to get the .Callee() anymore?
Reply all
Reply to author
Forward
0 new messages