Skip to content

Commit

Permalink
Set module.parent correctly inside sandboxed modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
oroce authored and domenic committed Sep 8, 2013
1 parent b4c982f commit c3df0b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sandboxed_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Module = require('module');
var fs = require('fs');
var vm = require('vm');
var path = require('path');

var parent = module.parent;
module.exports = SandboxedModule;
function SandboxedModule() {
this.id = null;
Expand Down Expand Up @@ -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, parent);
module.filename = this.filename;

this.module = module;
Expand Down
1 change: 1 addition & 0 deletions test/fixture/parent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.myParent = module.parent;
6 changes: 6 additions & 0 deletions test/integration/test-parent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var assert = require('assert');
var SandboxedModule = require('../..');

var fixture = SandboxedModule.require('../fixture/parent');
assert.strictEqual(fixture.myParent.filename, module.filename);
assert.strictEqual(fixture.myParent, module);

0 comments on commit c3df0b5

Please sign in to comment.