browserify / vm-browserify

require('vm') like in node but for the browser
MIT License
201 stars 37 forks source link

Shouldn't dispose of iframe after run #6

Open amasad opened 10 years ago

amasad commented 10 years ago

In node vm:

var c = vm.createContext({});
vm.runInContext('Array.foo = 1', c);
assert(1 === vm.runInContext('Array.foo'));

And that's not the case in this module because it disposes of iframe (real context) after each run.

pluma commented 10 years ago

Interesting. Closer inspection of node's context objects reveals that upon running something in a context the context object receives its own (non-enumerable) copy of every global, which is not identical with the current global.

I think the problem is that vm-browserify only copies properties which were already on the context before the eval or were introduced by the eval'd code.

amasad commented 10 years ago

It seems very hard to match the exact behavior on both so I wrote a more simplified module: context-eval

tcql commented 9 years ago

it seems that the iframe disposal also prevents you from running async code inside a context, which breaks some stuff I wanted to do