diff --git a/src/node_script.cc b/src/node_script.cc index 1e32b0f133..cbe8d12b5d 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -175,7 +175,7 @@ template sandbox; if (cFlag == newContext) { - sandbox = args.Length() > sbIndex ? args[sbIndex]->ToObject() : Object::New(); + sandbox = args[sbIndex]->IsObject() ? args[sbIndex]->ToObject() : Object::New(); } else if (cFlag == userContext) { sandbox = args[sbIndex]->ToObject(); } diff --git a/test/simple/test-script-context.js b/test/simple/test-script-context.js index 343eeabc62..40a46c7009 100644 --- a/test/simple/test-script-context.js +++ b/test/simple/test-script-context.js @@ -19,3 +19,7 @@ script = new Script('foo = 3;'); result = script.runInContext(context); assert.equal(3, context.foo); assert.equal('lala', context.thing); + + +// Issue GH-227: +Script.runInNewContext('', null, 'some.js');