context-eval
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -7,6 +7,5 @@ function Context(sandbox, parentElement) { | ||
var win = this.iframe.contentWindow; | ||
sandbox = sandbox || {}; | ||
Object.keys(sandbox).forEach(function (key) { | ||
win[key] = sandbox[key]; | ||
}); | ||
if (sandbox) { | ||
this.extend(sandbox); | ||
} | ||
} | ||
@@ -25,2 +24,13 @@ | ||
module.exports = Context; | ||
Context.prototype.getGlobal = function () { | ||
return this.iframe.contentWindow; | ||
}; | ||
Context.prototype.extend = function (sandbox) { | ||
var global = this.getGlobal(); | ||
Object.keys(sandbox).forEach(function (key) { | ||
global[key] = sandbox[key]; | ||
}); | ||
}; | ||
module.exports = Context; |
@@ -17,2 +17,12 @@ var vm = require('vm'); | ||
module.exports = Context; | ||
Context.prototype.getGlobal = function () { | ||
return this.context; | ||
}; | ||
Context.prototype.extend = function (obj) { | ||
Object.keys(obj).forEach(function(key) { | ||
this.context[key] = obj[key]; | ||
}, this); | ||
}; | ||
module.exports = Context; |
{ | ||
"name": "context-eval", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "JavaScript code execution context for the browser and wrapper around node vm module", | ||
"main": "index.js", | ||
"browser": "./lib/context-browser.js", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "test": "mocha tests/" |
@@ -36,5 +36,12 @@ # context-eval | ||
## Context#extend(obj) | ||
Extend the global object with `obj` | ||
## Context#getGlobal() | ||
Returns the global object | ||
### License | ||
MIT |
6382
142
46