Closed caspervonb closed 5 years ago
Won't merge this yet, while it introduces no breakage I'm not confident there is enough coverage at the moment.
In particular, I'm wondering if this will break some, if not all closures. It's still viable, but depends on what we are doing with closure bindings in (#1).
As anticipated, the closure is lost
var code = [
'function() {',
' return value;',
'}',
].join('\n');
var __function = function() {
__function = eval('(' + code + ')');
__function.apply(this, arguments);
};
var fn = function() {
__function.apply(this, arguments);
};
var result = eval([
'var value = 0;',
'fn()',
].join('\n'));
console.assert(result == 0);
Added a test which replicates this to master and rebased, which is currently failing so this is blocking on #1 for now.
This fixes #5 by using a temporary function to do the evaluation, which is assigned on every update. After which it assigns it back to the real function which allows runtimes to do their normal optimisations.
As a bonus, we also get rid of the conditional update checking.