Function literals won't have a different script id, but `eval` will. This
is considered to be a different "script" from a JavaScript semantics point
of view,
<http://www.ecma-international.org/ecma-262/9.0/index.html#sec-eval-x> though
not necessarily a different "<script>" tag.

If you want the top-level script jumping over evals, you could use
script.eval_from_shared() to get and eval's parent SFI, and recursively
walk up from there.

On Mon, May 6, 2019 at 5:19 PM psnyder via v8-dev <[email protected]>
wrote:
>
> Hi Leszek,
>
> Thank you for your reply.  However, I believe the code examples you gave
are not correct, as the same script unit will result in multiple script ids
(e.g. one for the ScriptContext, others for top level function literals,
etc).
>
> Is there some way of tying all the code compiled from a single script
unit / <script> to a single identifier?
>
> Apologies if Im missing something here too
>
> On Monday, May 6, 2019 at 1:58:22 AM UTC-7, Leszek Swirski wrote:
>>
>> `Script::cast(function->shared()->script()).id()` is your best bet for
>> a straight-up unique ID for a script -- otherwise, you probably want
>> to look at some combination of
>> `String::cast(Script::cast(function->shared()->script()).source())`
>> and line/column offset.
>>
>> On Sun, Apr 28, 2019 at 4:52 PM psnyder via v8-dev
>> <[email protected]> wrote:
>> >
>> > I'm looking to determine what the top level code unit is that created
a JSFunction object.
>> >
>> > Something like `Script::cast(function->shared()->script()).id()`
returns unexpectedly high values (I'm guessing for reasons related to
partial and / or streaming and / or eval parsing).
>> >
>> > Is there a way, given a `JSFunction` instance, to trace it back to a
script id for the complete originating script's id?
>> >
>> > The overall goal is to attribute every function call to a unique
identifier for every `<script>` (and similar) that defines it.  So there'd
be the same number of script id's as sources of code in blink, etc.
>> >
>> > Any suggestions / pointers would be greatly appreciated.  Thanks!
>> >
>> > --
>> > --
>> > v8-dev mailing list
>> > [email protected]
>> > http://groups.google.com/group/v8-dev
>> > ---
>> > You received this message because you are subscribed to the Google
Groups "v8-dev" 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-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
"v8-dev" 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-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" 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