On Fri, Jul 23, 2021 at 2:07 AM Shivan <[email protected]> wrote:
>
> (might be better suited to v8-dev)
>
> For a research project, I'm trying to get the currently executing script's ID 
> from a microtask in V8 isolate.cc. I've thought of the following two 
> approaches:
>
> if (!this->context().is_null()) {
>     Handle<ScopeInfo> scope_info(this->context().scope_info(), this);
>     DeclarationScope* decl_scope = scope_info->GetScriptScope();
>     //but now how do I get to the currently executing script?
> }
>
> and:
>
> Handle<CallableTask> current_microtask = 
> Handle<CallableTask>::cast(this->factory()->current_microtask());
> JSReceiver receiver = current_microtask->callable();
> MaybeHandle<JSFunction> maybe_constructor = 
> JSReceiver::GetConstructor(handle(receiver, this));
> //but constructor->shared().script().IsScript() returns false.
>
> What am I doing wrong?

I think your second approach is on the right track but you assume a
microtask is always callable + JSReceiver/JSFunction, which I don't
think is true - it can be a C++ callback or a promise reaction job,
for instance, and those don't have scripts or function objects
associated with them.

You should probably start by checking that
current_microtask->map().is_callable() is true and then add more type
checks on top. If you're only interested in JSFunctions, you can
probably get away with checking just
InstanceTypeChecker::IsJSFunction(current_microtask->map()->instance_type()).

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAHQurc-fsQfS1zDjCbQsAmvg1%2BXBWiKFgf4%3DCwWwAn5fGWqZOw%40mail.gmail.com.

Reply via email to