You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// CommonJS - sloppy modeeval('var x = 123; let livepack_tracker;');assert(typeofx==='number');
In original code, assertion passes. In instrumented code, it fails.
Due to usage of a var livepack_tracker in the eval()-ed code, Livepack's instrumentation wraps the eval code in an arrow function to populate internal livepack_tracker1 var. The code which is executed in eval() is:
((livepack1_tracker,livepack1_getScopeId)=>eval('var x = 123; let livepack_tracker;'))(livepack_tracker,livepack_getScopeId)
This means var x is added to the scope of the arrow function, not the outer scope.
Only a occurs if:
eval() code is sloppy mode. In strict mode var declarations are bound within the eval script scope.
eval()-ed code uses vars which could clash with Livepack's internal vars in outer scope (very uncommon case)
Solution
Can avoid the arrow function wrapper, by instead transforming eval()-ed code to:
constlivepack1_tracker=livepack_tracker,livepack1_getScopeId=livepack_getScopeId;eval('var x = 123; let livepack_tracker;');
NB Indirect eval also has similar problems, but solution is more complex. Will open separate issue for that.
The text was updated successfully, but these errors were encountered:
Actually, this problem occurs even if no internal vars are used.
Input:
// CommonJS - sloppy modeeval('var x = 123;');assert(typeofx==='number');
This is instrumented as:
livepack_tracker.evalDirect('var x = 123',eval,livepack_temp_3=>eval(livepack_temp_3),livepack_temp_3=>eval(...livepack_temp_3),[[1,"index",livepack_scopeId_2,["module"],["exports"],["this",1],["new.target",1]]],false);
So eval() is still called within an arrow function.
To solve it, would need to convert to something like:
eval(livepack_tracker.instrumentEval('var x = 123',eval,[/* ... */]))
Previously took this approach (function was called livepack_preval) but later changed it, but can't remember why.
Problem
Input:
In original code, assertion passes. In instrumented code, it fails.
Due to usage of a var
livepack_tracker
in theeval()
-ed code, Livepack's instrumentation wraps the eval code in an arrow function to populate internallivepack_tracker1
var. The code which is executed ineval()
is:This means
var x
is added to the scope of the arrow function, not the outer scope.Only a occurs if:
eval()
code is sloppy mode. In strict modevar
declarations are bound within the eval script scope.eval()
-ed code uses vars which could clash with Livepack's internal vars in outer scope (very uncommon case)Solution
Can avoid the arrow function wrapper, by instead transforming
eval()
-ed code to:NB Indirect
eval
also has similar problems, but solution is more complex. Will open separate issue for that.The text was updated successfully, but these errors were encountered: