Haiyang-Sun / nodeprof.js

Instrumentation framework for Node.js compliant to ECMAScript 2020 based on GraalVM.
Apache License 2.0
53 stars 22 forks source link

newSource callback is not triggered for ES modules with top-level await #109

Closed BarrensZeppelin closed 1 year ago

BarrensZeppelin commented 1 year ago

Consider the following analysis.cjs:

//DO NOT INSTRUMENT
(function (sandbox) {
    function MyAnalysis() {
        this.newSource = function(sourceInfo, source) {
            console.log("newSource", sourceInfo);
        };
    }

    sandbox.addAnalysis(new MyAnalysis(), function filter(source) {
        return !source.internal || source.name.startsWith("file://");
    });
})(J$);

and analysis target a.mjs:

await Promise.resolve(42);

When I run

$GRAAL_HOME/bin/node --jvm --experimental-options --nodeprof $GRAAL_HOME/tools/nodeprof/jalangi.js --analysis analysis.cjs a.mjs

there is no output.

If I run the dynamic analysis on b.mjs:

(async () => await Promise.resolve(42))();

I get the output:

newSource { name: 'file:///path/to/b.mjs', internal: true }

Is there a way to have the newSource-callback triggered for ES modules that use top-level await?

BarrensZeppelin commented 1 year ago

I just tried to reproduce this issue on master without luck. The newSource-callback is now correctly triggered. :partying_face: