🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

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

to
0.1.4

22

lib/contextify.js

@@ -1,4 +0,6 @@

var ContextifyContext = require('bindings')('contextify').ContextifyContext;
var binding = require('bindings')('contextify');
var ContextifyContext = binding.ContextifyContext;
var ContextifyScript = binding.ContextifyScript;
module.exports = function Contextify (sandbox) {
function Contextify (sandbox) {
if (typeof sandbox != 'object') {

@@ -31,1 +33,17 @@ sandbox = {};

}
Contextify.createContext = function (sandbox) {
if (typeof sandbox != 'object') {
sandbox = {};
}
return new ContextifyContext(sandbox);
};
Contextify.createScript = function (code, filename) {
if (typeof code != 'string') {
throw new TypeError('Code argument is required');
}
return new ContextifyScript(code, filename);
};
module.exports = Contextify;

2

package.json
{
"name": "contextify",
"version": "0.1.3",
"version": "0.1.4",
"description": "Turn an object into a persistent execution context.",

@@ -5,0 +5,0 @@ "author": "Brian McDaniel <brianmcd05@gmail.com>",

@@ -25,2 +25,13 @@ var Contextify = require('../lib/contextify.js');

'basic createContext' : function (test) {
var sandbox = {
prop1: 'prop1',
prop2: 'prop2'
};
var context = Contextify.createContext(sandbox);
test.equal(sandbox.prop1, 'prop1');
test.equal(sandbox.prop2, 'prop2');
test.done();
},
// Ensure that the correct properties exist on a wrapped sandbox.

@@ -35,2 +46,11 @@ 'test contextified object extra properties' : function (test) {

'createContext should not modify the sandbox' : function (test) {
var sandbox = {};
Contextify.createContext(sandbox);
test.equal(sandbox.run, undefined);
test.equal(sandbox.getGlobal, undefined);
test.equal(sandbox.dispose, undefined);
test.done();
},
// Passing undefined should create an empty context.

@@ -70,2 +90,10 @@ 'test undefined sandbox' : function (test) {

'test for "undefined" properties with createContext' : function (test) {
var sandbox = { x: undefined };
var context = Contextify.createContext(sandbox);
context.run("_x = x");
test.equal(sandbox._x, undefined);
test.done();
},
'test for "undefined" variables' : function (test) {

@@ -94,2 +122,11 @@ var sandbox = { };

// Make sure run can be called on a context
'test run with createContext' : function (test) {
var sandbox = {};
var context = Contextify.createContext(sandbox);
context.run('var x = 3', "test.js");
test.equal(sandbox.x, 3);
test.done();
},
// Make sure getters/setters on the sandbox object are used.

@@ -199,2 +236,24 @@ 'test accessors on sandbox' : function (test) {

}, 0);
},
// Asynchronous context script execution:
// Ensure that sandbox properties can be accessed as global variables.
'createContext: sandbox properties should be globals' : function (test) {
var sandbox = {
setTimeout : setTimeout,
prop1 : 'prop1',
prop2 : 'prop2'
};
var context = Contextify.createContext(sandbox);
context.run("setTimeout(function () {" +
"test1 = (prop1 == 'prop1');" +
"test2 = (prop2 == 'prop2');" +
"}, 0)");
test.equal(sandbox.test1, undefined);
test.equal(sandbox.test2, undefined);
setTimeout(function () {
test.ok(sandbox.test1);
test.ok(sandbox.test2);
test.done();
}, 0);
}

@@ -309,3 +368,3 @@ };

},
// Make sure global can be a receiver for getGlobal().

@@ -445,3 +504,3 @@ 'test global.getGlobal()' : function (test) {

},
'test run() after dispose()' : function (test) {

@@ -469,1 +528,34 @@ var sandbox = Contextify();

};
exports['test scripts'] = {
'test createScript()' : function (test) {
var script = Contextify.createScript('var x = 3', 'test.js');
test.equal(typeof script.runInContext, 'function');
test.done();
},
'test createScript() without code' : function (test) {
test.throws(function () {
Contextify.createScript();
});
test.throws(function () {
Contextify.createScript(true);
});
test.throws(function () {
Contextify.createScript(null);
});
test.throws(function () {
Contextify.createScript(1);
});
test.done();
},
'test runInContext' : function (test) {
var sandbox = {};
var script = Contextify.createScript('var x = 3', 'test.js');
var context = Contextify.createContext(sandbox);
script.runInContext(context);
test.equal(sandbox.x, 3);
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