gf3 / sandbox

A nifty JavaScript sandbox for Node.js
ISC License
844 stars 123 forks source link

onmessage function is not being called, causing timeout when defined. #37

Open ijonas opened 9 years ago

ijonas commented 9 years ago

Hi,

I've been playing with Sandbox on node 0.10.33 on OSX. I can send message from inside the Sandbox out the host environment. When I try and postMessage() into the Sandbox and with an onmessage function defined, the run() method times out.

Here's my code

var Sandbox = require('sandbox');

sb = new Sandbox();
sb.on('message', function (message) { 
  console.log("outer message handler: "+message); 
});
sb.on('ready', function() { 
  console.log('ready. posting...'); 
  sb.postMessage("calling when ready"); 
});
sb.run("postMessage('message from inside'); 10 + 10;", function(output) { 
  console.log(output) 
});

sb = new Sandbox();
sb.on('message', function (message) { 
  console.log("outer message handler: "+message); 
});
sb.on('ready', function() { 
  console.log('ready. posting...'); 
  sb.postMessage("calling when ready"); 
});
sb.run("onmessage = function (msg) { console.log(msg); };", function(output) { 
  console.log(output) 
});

Producing the following output:

outer message handler: message from inside
ready. posting...
{ result: '20', console: [] }
ready. posting...
{ result: 'TimeoutError', console: [] }    

Is anyone else seeing this problem? I've run the test code and it passes on my machine. If I modify the test code by removing the spies, then the same timeout problem occurs.

A little help appreciated, Ijonas.

yoavprat commented 8 years ago

Same for me, when running the example getting this TimeoutError (OS X as well)