Getting currently executing script from microtask

10 views
Skip to first unread message

Shivan

unread,
Jul 22, 2021, 8:07:34 PM7/22/21
to v8-dev
(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?

Ben Noordhuis

unread,
Jul 28, 2021, 6:48:25 AM7/28/21
to v8-...@googlegroups.com
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()).
Reply all
Reply to author
Forward
0 new messages