Skip to content

Instantly share code, notes, and snippets.

@shimondoodkin
Created October 24, 2010 01:23
Show Gist options
  • Save shimondoodkin/642943 to your computer and use it in GitHub Desktop.
Save shimondoodkin/642943 to your computer and use it in GitHub Desktop.
demonstrates that the contexts are not referenced in runInNewContext when running in same context
//licensed public domain
var sandbox = { setTimeout: setTimeout, console:console};
var myscript=0;
function run_scripts_in_same_context(text)
{
process.binding('evals').Script.runInNewContext(text,sandbox,'myfile'+(myscript++)+'.js');
}
run_scripts_in_same_context('var x="1"; function showx(){console.log("x="+x);} setTimeout(function(){showx();},100)');
run_scripts_in_same_context('x="5"; showx();');
console.log("the last x should be 5, if it is 1 so the contexts are not referenced");
@shimondoodkin
Copy link
Author

it is a bug and a future because it does exactly what it says. it does "run in a new context"

I have not found a solution for this for jsdom.
But solved it for myself by simply combining the scripts together.
but mysteriously when I also combined the jquery in it did not worked so I left it as a separate file

http://github.com/shimondoodkin/nodejs-waze/blob/master/index.js

@shimondoodkin
Copy link
Author

a follow up is here:

https://gist.github.com/752345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment