Hiding the calling function

39 views
Skip to first unread message

Danny Dorfman

unread,
Sep 29, 2015, 9:46:25 AM9/29/15
to v8-users
Hi there,

I need to write an application that runs some mixed JavaScript code. What I mean by "mixed", is that some of the code is mine, and some is external.
My code will be calling some external code, but I would like to conceal the call stack. In other words, in a scenario like this:

// my code
function myFunc()
{
   extFunc();
}


// external code
function extFunc()
{
   if (arguments.callee.caller == null)
   {
        console.log("okay");
   }
}


I would like the last "if" to evaluate true. Can it be done via a wrapper in V8, or in plain JavaScript?

Regards,
D.

Ben Noordhuis

unread,
Sep 29, 2015, 12:14:48 PM9/29/15
to v8-u...@googlegroups.com
Code that is baked into the snapshot through the
v8_extra_library_files variable won't show up in stack traces but
apart from that there is no way to hide a caller.

If you're willing to hack on V8, I think it's as easy as
function->shared()->script()->set_type(Script::TYPE_NATIVE).

Andreas Rossberg

unread,
Sep 29, 2015, 1:39:38 PM9/29/15
to v8-u...@googlegroups.com
On 29 September 2015 at 15:41, Danny Dorfman <wilder...@gmail.com> wrote:
> Hi there,
>
> I need to write an application that run some mixed JavaScript code. What I
> mean by mixed, is that some of the code is mine, and some is external.
> My code will be calling some external code, but I would like to conceal the
> call stack.

If your function is in strict mode, it cannot be discovered via the
.caller property, nor does it have one itself. Any attempt to do so
will either throw or return undefined.

/Andreas

Danny Dorfman

unread,
Sep 30, 2015, 1:34:37 AM9/30/15
to v8-users
Hey Andreas. Your solution worked like magic. Very elegant. Thanks!
Reply all
Reply to author
Forward
0 new messages