From b9c1cc707625473fa32bb4076f6f154a01786661 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 19 Feb 2015 17:57:44 -0800 Subject: [PATCH] Only copy ctx properties when `context` is defined Fixes #12. --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 644efd1..ac03554 100644 --- a/index.js +++ b/index.js @@ -109,9 +109,11 @@ Script.prototype.runInNewContext = function (context) { var ctx = Script.createContext(context); var res = this.runInContext(ctx); - forEach(Object_keys(ctx), function (key) { - context[key] = ctx[key]; - }); + if (context) { + forEach(Object_keys(ctx), function (key) { + context[key] = ctx[key]; + }); + } return res; };