Closed turkja closed 5 years ago
Dear Jarko, I could not reproduce your bug in the demo page. The code transformation looks fine as far as I can tell... As you can see below, _meta_20 is incremented inside the block. Plus in your code, ctx.traps.expression(str, ast.__min__)
disappeared, which would lead to the removal of (myKey = _meta_1[_meta_2]);
.
Are you sure it is not related to your analysis? Or am I missing something here?
_meta_.__global__ = _meta_.__global__ || (function() {
return this
}());
_meta_.__eval__ = _meta_.__eval__ || eval;
_meta_.__apply__ = _meta_.__apply__ || (typeof Reflect === 'object' ? Reflect.apply : function(f, t, xs) {
return f.apply(t, xs)
});
_meta_.__defineProperty__ = _meta_.__defineProperty__ || Object.defineProperty;
(ktest = function ktest(myObj) {
var _meta_1, _meta_2, _meta_3;
void 0; {
_meta_1 = (function(o) {
var ks = [];
for (var k in o) ks[ks.length] = k;
return ks;
}(myObj));
_meta_2 = 0;
while (_meta_2 < _meta_1.length) {
_meta_.__apply__((_meta_3 = console)["log"], _meta_3, [myObj[myKey]]);
(myKey = _meta_1[_meta_2]);
_meta_2++;
}
}
return void 0
});
void 0;
var ktest;
(ktest([1, "foo", {
"a": "bar"
}]));
Thanks for the reply!
Strange thing this cannot be reproduced with the demo. I cannot explain it!
Could you please try out this code in node.js (with npm install aran):
var Aran = require("aran");
global._meta_ = {};
global._meta_.apply = function (fct, ths, args, idx) {
var loc = aran.node(idx).loc.start;
return fct.apply(ths, args);
};
var aran = Aran({
namespace:"_meta_", traps:["apply"], loc:true });
var code = 'function ktest(myObj) {\n'+
' for (myKey in myObj) {\n'+
' console.log(myObj[myKey]);\n'+
' }\n'+
'}\n'+
'ktest([1, \"foo\", {\"a\":\"bar\"}]);\n';
global.eval(aran.instrument(code, "target.js"));
Works fine in aran@3.0.0
var Aran = require("aran");
const Acorn = require("Acorn");
global._meta_ = {};
global._meta_.apply = function (fct, ths, args, idx) {
var loc = aran.nodes[idx].loc.start;
return fct.apply(ths, args);
};
var aran = Aran({
namespace:"_meta_",
format: "script"
});
var code = 'function ktest(myObj) {\n'+
' for (myKey in myObj) {\n'+
' console.log(myObj[myKey]);\n'+
' }\n'+
'}\n'+
'ktest([1, \"foo\", {\"a\":\"bar\"}]);\n';
global.eval(aran.setup());
global.eval(aran.weave(Acorn.parse(code, {locations:true}), ["apply"]));
1
foo
{ undefined: 'bar' }
Solved in aran@3.0.1
Following simple code fails with unknown key when instrumented:
Seems like the problem is in instrument.js visitors.ForInStatement, where aran inserts the counter expression after the BlockExpression. I experimented changing the order like this:
Seems to work, but please check..