Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recursive sandboxing and JSON support.
Closes #11.
- Loading branch information
1 parent
ff9c9cd
commit 350321b
Showing
20 changed files
with
186 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports.path = require('path'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cross = require('./cross'); | ||
|
||
module.exports.cross = cross | ||
module.exports.value = 'criss value'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
criss = require('./criss'); | ||
|
||
module.exports.criss = criss | ||
module.exports.value = 'cross value'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module.exports.zap = 'zap'; | ||
module.exports.bar = require('../bar'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('./moreGlobal'); | ||
|
||
module.exports.worse = global.worse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var json =require('./json'); | ||
|
||
module.exports.json = json; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"value":"value from json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var Module = require('module'); | ||
|
||
var parentModule = new Module(require.resolve('./foo')); | ||
parentModule.filename = require.resolve('./foo'); | ||
module.exports.bar = Module._load('./bar',parentModule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.worse = 'worse'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports.bar = require(require.resolve('./bar')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var requireModule = SandboxedModule.load('../fixture/moduleModule', { | ||
requires: { './bar': 'fakeBar' } | ||
}); | ||
var exports = requireModule.exports; | ||
|
||
assert.strictEqual(exports.bar, 'fakeBar'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var fakeBar = 'fakeBar'; | ||
var requireModule = SandboxedModule.load('../fixture/coreModule'); | ||
var recursiveExports = requireModule.exports; | ||
assert.strictEqual(recursiveExports.path, require('path')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var fakeBar = 'fakeBar'; | ||
var requireModule = SandboxedModule.load('../fixture/criss'); | ||
var criss = requireModule.exports; | ||
var cross = criss.cross | ||
assert.strictEqual(criss.value, 'criss value'); | ||
assert.strictEqual(cross.value, 'cross value'); | ||
assert.strictEqual(criss.cross, cross); | ||
assert.strictEqual(cross.criss, criss); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var fakeBar = 'fakeBar'; | ||
var requireModule = SandboxedModule.load('../fixture/require', { | ||
requires: { './bar': fakeBar }, | ||
singleOnly:true | ||
}); | ||
var recursiveExports = requireModule.exports; | ||
assert.strictEqual(recursiveExports.bar, fakeBar); | ||
assert.strictEqual(recursiveExports.foo.bar, 'bar'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var requireModule = SandboxedModule.load('../fixture/globalVars'); | ||
var recursiveExports = requireModule.exports; | ||
assert.strictEqual(recursiveExports.worse, 'worse'); | ||
assert.equal(global.worse, undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var requireModule = SandboxedModule.load('../fixture/resolve'); | ||
var recursiveExports = requireModule.exports; | ||
assert.strictEqual(recursiveExports.bar, 'bar'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var fakeBar = 'fakeBar'; | ||
var requireModule = SandboxedModule.load('../fixture/includeJson'); | ||
var recursiveExports = requireModule.exports; | ||
assert.strictEqual(recursiveExports.json.value, 'value from json'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var assert = require('assert'); | ||
var SandboxedModule = require('../..'); | ||
|
||
var fakeBar = 'fakeBar'; | ||
var requireModule = SandboxedModule.load('../fixture/require', { | ||
requires: { './bar': fakeBar } | ||
}); | ||
var recursiveExports = requireModule.exports; | ||
assert.strictEqual(recursiveExports.bar, fakeBar); | ||
assert.strictEqual(recursiveExports.foo.bar, fakeBar); |