hasharray / revaluate.js

non destructive code revaluation
https://revaluate.js.org
2 stars 0 forks source link

WIP: Use a temporary function to evaluate functions #9

Closed caspervonb closed 5 years ago

caspervonb commented 8 years ago

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.

caspervonb commented 8 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).

caspervonb commented 8 years ago

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);
caspervonb commented 8 years ago

Added a test which replicates this to master and rebased, which is currently failing so this is blocking on #1 for now.