title: Isolate execution of JavaScript
body: <p>One of the limitation of JS that bugs me the most is the poor ability to isolate code's execution. </p>
  
  <p>I want to be able to control the context in which the code is executed, Something that achieve a similar effect to what <code>Script.createContext</code> &amp; <code>Script.runInContext</code> in node.js does (node is using binding to the V8 engine, so i can't emulate their implementation). </p>
  
  <p>Here is the some reason why I want to isolate code execution:</p>
  
  <ol>
  <li>Isolate the code from the global namespace (the <code>window</code> object and the also the <code>DOM</code>) , but I however need to be able reference function call on objects exposed in the context which must be executed synchronous which makes it almost impossible using a <code>WebWorker</code> for isolation.</li>
  <li>By isolate the execution of code it would possible also be able to deallocate its definitions when no longer needed (memory management). </li>
  </ol>
  
  <p>I know one may achieve partly isolated execution by loading script into a <code>iframe</code>, this approach is however very heavy and uses a lot memory for a second instance of the DOM which isn't needed for what I'm trying to do. </p>
  
  <p>I need to share constructor definition and also definitions of object which are shared between the isolated containers/contexts which both must run on the main UI thread. Mainly i want to use these isolated containers to host plugins/modules (mini-applications) which each presents and dynamically updates a viewport by calling drawing commands on their own <code>Context2D</code> object. </p>
  
  <p>If these containers are not running on the main UI thread it wold be painfully hard to proxy calls such as <code>ctx.measureText()</code> and <code>ctx.drawImage()</code> would be all useless as image objects can't be created in a <code>Worker</code>.</p>
  
  <p><em>Does someone know of future specification that would make this possible?</em>  </p>
  
  <p><em>Are there any current (hidden) browser-side APIs that could be used to achieve this?</em></p>
  
  <p><em>Would it be better utilize a virtual machine like Goggle's Dart VM and also re-implement my current codebase?</em>
  My current codebase is slightly above 20 000 lines of code.</p>
  
  <p>Would it be better to re-implement the framework in  *</p>