From b929dfbf8d1e104c3d6054e895062532d820addb Mon Sep 17 00:00:00 2001 From: oroce Date: Thu, 5 Sep 2013 15:33:17 +0200 Subject: [PATCH 1/4] add parent to module constructor --- lib/sandboxed_module.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sandboxed_module.js b/lib/sandboxed_module.js index e641cd5..ed883b3 100644 --- a/lib/sandboxed_module.js +++ b/lib/sandboxed_module.js @@ -4,7 +4,7 @@ var Module = require('module'); var fs = require('fs'); var vm = require('vm'); var path = require('path'); - +var thisModule = module; module.exports = SandboxedModule; function SandboxedModule() { this.id = null; @@ -45,7 +45,7 @@ SandboxedModule.prototype._init = function(moduleId, trace, options) { this._options = options || {}; - var module = new Module(this.filename); + var module = new Module(this.filename, thisModule); module.filename = this.filename; this.module = module; From 3f3f482e4473d9d3839dff2bce1addb6120a8912 Mon Sep 17 00:00:00 2001 From: oroce Date: Thu, 5 Sep 2013 18:08:36 +0200 Subject: [PATCH 2/4] tests added --- test/fixture/parent.js | 1 + test/integration/test-parent.js | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 test/fixture/parent.js create mode 100644 test/integration/test-parent.js diff --git a/test/fixture/parent.js b/test/fixture/parent.js new file mode 100644 index 0000000..1153f8b --- /dev/null +++ b/test/fixture/parent.js @@ -0,0 +1 @@ +exports.dummy = true; diff --git a/test/integration/test-parent.js b/test/integration/test-parent.js new file mode 100644 index 0000000..93f64f9 --- /dev/null +++ b/test/integration/test-parent.js @@ -0,0 +1,6 @@ +var assert = require('assert'); +var SandboxedModule = require('../..'); + +var exports = SandboxedModule.load('../fixture/parent'); +console.log("exports", exports) +assert.ok(exports.module.parent); From 295ab846c81eadfcd4f25fe24fdb311c8acfb746 Mon Sep 17 00:00:00 2001 From: oroce Date: Thu, 5 Sep 2013 19:06:54 +0200 Subject: [PATCH 3/4] parent.filename should equal sandboxed-module --- test/integration/test-parent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/test-parent.js b/test/integration/test-parent.js index 93f64f9..c16e0dc 100644 --- a/test/integration/test-parent.js +++ b/test/integration/test-parent.js @@ -2,5 +2,5 @@ var assert = require('assert'); var SandboxedModule = require('../..'); var exports = SandboxedModule.load('../fixture/parent'); -console.log("exports", exports) assert.ok(exports.module.parent); +assert.equal(exports.module.parent.filename, require.resolve('../..')); From 0e59c0f0d72236de23e98b8705d4beb9b4bea848 Mon Sep 17 00:00:00 2001 From: oroce Date: Fri, 6 Sep 2013 10:57:05 +0200 Subject: [PATCH 4/4] module.parent should be the module which required sandboxed-module --- lib/sandboxed_module.js | 4 ++-- test/integration/test-parent.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sandboxed_module.js b/lib/sandboxed_module.js index ed883b3..1545cee 100644 --- a/lib/sandboxed_module.js +++ b/lib/sandboxed_module.js @@ -4,7 +4,7 @@ var Module = require('module'); var fs = require('fs'); var vm = require('vm'); var path = require('path'); -var thisModule = module; +var parent = module.parent; module.exports = SandboxedModule; function SandboxedModule() { this.id = null; @@ -45,7 +45,7 @@ SandboxedModule.prototype._init = function(moduleId, trace, options) { this._options = options || {}; - var module = new Module(this.filename, thisModule); + var module = new Module(this.filename, parent); module.filename = this.filename; this.module = module; diff --git a/test/integration/test-parent.js b/test/integration/test-parent.js index c16e0dc..b3985ae 100644 --- a/test/integration/test-parent.js +++ b/test/integration/test-parent.js @@ -3,4 +3,4 @@ var SandboxedModule = require('../..'); var exports = SandboxedModule.load('../fixture/parent'); assert.ok(exports.module.parent); -assert.equal(exports.module.parent.filename, require.resolve('../..')); +assert.equal(exports.module.parent.filename, module.filename);