Socket
Socket
Sign inDemoInstall

contextify

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contextify - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

.npmignore

31

lib/contextify.js
try {
module.exports = require('../build/Release/contextify').wrap;
var ContextifyContext = require('../build/Release/contextify').ContextifyContext;
} catch (e) {

@@ -10,1 +10,30 @@ console.log("Internal Contextify ERROR: Make sure Contextify is built " +

}
module.exports = function Contextify (sandbox) {
if (typeof sandbox != 'object') {
sandbox = {};
}
var ctx = new ContextifyContext(sandbox);
sandbox.run = function () {
return ctx.run.apply(ctx, arguments);
};
sandbox.getGlobal = function () {
return ctx.getGlobal();
}
sandbox.dispose = function () {
sandbox.run = function () {
throw new Error("Called run() after dispose().");
};
sandbox.getGlobal = function () {
throw new Error("Called getGlobal() after dispose().");
};
sandbox.dispose = function () {
throw new Error("Called dispose() after dispose().");
};
ctx = null;
}
return sandbox;
}

55

package.json
{
"author": "Brian McDaniel <brianmcd05@gmail.com>",
"name": "contextify",
"description": "Turn an object into a persistent execution context.",
"keywords": [
"context",
"vm"
],
"version": "0.0.7",
"repository": {
"type" : "git",
"url": "https://github.com/brianmcd/contextify.git"
},
"main": "./lib/contextify.js",
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">=0.4.0"
},
"licenses": [
{
"type" : "MIT",
"url" : "http://github.com/brianmcd/contextify/blob/master/LICENSE.txt"
"name": "contextify",
"version": "0.1.0",
"description": "Turn an object into a persistent execution context.",
"author": "Brian McDaniel <brianmcd05@gmail.com>",
"contributors": [
"Assaf Arkin <assaf@labnotes.org> (http://labnotes.org/)"
],
"keywords": ["context","vm"],
"repository": {
"type" : "git",
"url": "https://github.com/brianmcd/contextify.git"
},
"main": "./lib/contextify",
"scripts": {
"test": "nodeunit test/"
},
"engines": {
"node": ">=0.4.0"
},
"licenses": [
{
"type" : "MIT",
"url" : "http://github.com/brianmcd/contextify/blob/master/LICENSE.txt"
}
],
"devDependencies": {
"nodeunit" : ">=0.5.x"
}
],
"dependencies": {},
"devDependencies": {
"nodeunit" : ">=0.5.x"
}
}

@@ -114,5 +114,11 @@ var Contextify = require('../lib/contextify.js');

sandbox.dispose();
test.equal(sandbox.run, undefined);
test.equal(sandbox.getGlobal, undefined);
test.equal(sandbox.dispose, undefined);
test.throws(function () {
sandbox.run();
}, Error);
test.throws(function () {
sandbox.getGlobal();
}, Error);
test.throws(function () {
sandbox.dispose();
}, Error);
test.done();

@@ -316,5 +322,11 @@ }

// It's not safe to use the global after disposing.
test.equal(sandbox.run, undefined);
test.equal(sandbox.getGlobal, undefined);
test.equal(sandbox.dispose, undefined);
test.throws(function () {
sandbox.run();
}, Error);
test.throws(function () {
sandbox.getGlobal();
}, Error);
test.throws(function () {
sandbox.dispose();
}, Error);
test.done();

@@ -362,2 +374,28 @@ }

// Test eval scope.
exports['test eval'] = {
'basic test' : function (test) {
var sandbox = Contextify();
sandbox.run('eval("test1 = 1")');
test.equal(sandbox.test1, 1);
sandbox.run('(function() { eval("test2 = 2") })()');
test.equal(sandbox.test2, 2);
test.done();
},
'this test' : function (test) {
var sandbox = Contextify();
sandbox.run('e = eval ; e("test1 = 1")');
test.equal(sandbox.test1, 1);
sandbox.run('var t = 1 ; (function() { var t = 2; test2 = eval("t") })()');
test.equal(sandbox.test2, 2);
sandbox.run('t = 1 ; (function() { var t = 2; e = eval; test3 = e("t") })()');
test.equal(sandbox.test3, 1);
sandbox.run('var t = 1 ; global = this; (function() { var t = 2; e = eval; test4 = global.eval.call(global, "t") })()');
test.equal(sandbox.test4, 1);
test.done();
}
};
// Make sure exceptions get thrown for invalid scripts.

@@ -367,11 +405,14 @@ exports['test exceptions'] = {

var sandbox = Contextify();
// Exceptions thrown from "run" will be from the Contextified context.
var ReferenceError = sandbox.run('ReferenceError');
var SyntaxError = sandbox.run('SyntaxError');
test.throws(function () {
sandbox.run('doh');
});
}, ReferenceError);
test.throws(function () {
sandbox.run('x = y');
});
}, ReferenceError);
test.throws(function () {
sandbox.run('function ( { (( }{);');
});
}, SyntaxError);
test.done();

@@ -423,49 +464,3 @@ },

test.done();
},
'test global property getter after dispose()' : function (test) {
var sandbox = Contextify({prop1 : 'test'});
var global = sandbox.getGlobal();
test.doesNotThrow(function () {
sandbox.dispose();
});
test.throws(function () {
var x = global.prop1;
}, 'Tried to access global after dispose().');
test.done();
},
'test global property setter after dispose()' : function (test) {
var sandbox = Contextify();
var global = sandbox.getGlobal();
test.doesNotThrow(function () {
sandbox.dispose();
});
test.throws(function () {
global.x = 3;
}, 'Tried to set a property on global after dispose().');
test.done();
},
'test global property deleter after dispose()' : function (test) {
var sandbox = Contextify({prop1 : 'test'});
var global = sandbox.getGlobal();
test.doesNotThrow(function () {
sandbox.dispose();
});
test.throws(function () {
delete global.prop1;
}, 'Tried to delete a property on global after dispose().');
test.done();
}
};
exports['test global property enumerator after dispose()'] = function (test) {
var sandbox = Contextify({prop1 : 'test', prop2 : 'test'});
var global = sandbox.getGlobal();
sandbox.dispose();
var props = Object.keys(global);
test.equal(props.length, 0);
test.done();
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc