-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for in/of support #31
Comments
Is there any update on this feature request? My team is hoping to use this feature soon. |
Sorry for the late reply! We are currently scoping how to provide the basic |
Any update on this feature? |
It's in progress. Currently, there is a workaround for |
Yes, the last missing bit is to be implemented on Graal.js -- I haven't had time to work on this recently, so perhaps @Haiyang-Sun can you prototype a patch to Graal.js and contribute that upstream directly (assuming you have time, of course) -- feel free to ping me on slack if you need guidance |
Ok, thanks for the work and the update! |
@eleinadani I found a workaround without changes to Graal.js. We simply keep track of the last expression's execution result that certainly would be the object being iterated. @mwaldrich Please check if it works for you. |
Thanks for the implementation! We can now easily see the object involved with the loop. My team was planning on tracking how data flows into the loop variable. However, I'm not sure this is possible with the current callbacks. Here's an example. ExampleCode to instrumentvar a = 1;
var b = [1, 2, a];
var z = 0;
for (var k of b) {
z = k;
} Analysis(function (sandbox) {
function MyAnalysis() {
let lastExprResult;
this.forObject = function (iid, isForIn) {
console.log(`forObject isForIn=${isForIn}, object=${lastExprResult}`);
};
this.endExpression = function (iid, type, result) {
lastExprResult = result;
};
/**
* These callbacks are called after a variable is read or written.
**/
this.read = function (iid, name, val, isGlobal, isScriptLocal) {
console.log(`read name=${name}, val=${val}`);
};
this.write = function (iid, name, val, lhs, isGlobal, isScriptLocal) {
console.log(`write name=${name}, val=${val}`);
};
this.literal = function (iid, val, hasGetterSetter, literalType) {
console.log(`literal val=${val}`);
if (typeof val === "object") {
console.log("object property names:");
for (prop in val) {
if (val.hasOwnProperty(prop)) {
console.log("- " + prop);
}
}
}
};
}
sandbox.analysis = new MyAnalysis();
})(J$); NodeProf outputAfter running this with NodeProf, the output is:
QuestionI don't think it's possible with the current callbacks to know where the value of Consider a single loop iteration from the example above:
These callbacks don't give you any information about where the value of ProposalThere are a few ways to make this possible to track. Emitting
|
#48 |
I am confused about how the new callbacks could be used to instrument this. What callbacks would be generated in a single iteration of a for of loop? Also, would it be possible for NodeProf to just generate the correct |
Regarding for-of loops, Graal.js does not expose the events we would need to provide a |
I'd like to separate issues for for-in and for-of and merge #48 if it sufficient to support for-in. @Haiyang-Sun can you please update #48 based on my comments and rebase/squash the commit. @mwaldrich is anything missing from #48 to support for-in? |
I proposed changes to the callbacks in #51. The instrumentation logic itself is unchanged. |
My team is interested in instrumenting
for...in
andfor...of
loops? There was aforinObject
callback in jalangi, but no callback forfor...of
loops since they weren't supported. Ideally, for our use case, we'd have an object read/write callback for every step of any loop, but having aforinObject
andforofObject
would be sufficient.Are there any plans to support these types of for loops?
The text was updated successfully, but these errors were encountered: