react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / contextify / lib / contextify.js
81143 viewsvar binding = require('bindings')('contextify');1var ContextifyContext = binding.ContextifyContext;2var ContextifyScript = binding.ContextifyScript;34function Contextify (sandbox) {5if (typeof sandbox != 'object') {6sandbox = {};7}8var ctx = new ContextifyContext(sandbox);910sandbox.run = function () {11return ctx.run.apply(ctx, arguments);12};1314sandbox.getGlobal = function () {15return ctx.getGlobal();16}1718sandbox.dispose = function () {19sandbox.run = function () {20throw new Error("Called run() after dispose().");21};22sandbox.getGlobal = function () {23throw new Error("Called getGlobal() after dispose().");24};25sandbox.dispose = function () {26throw new Error("Called dispose() after dispose().");27};28ctx = null;29}30return sandbox;31}3233Contextify.createContext = function (sandbox) {34if (typeof sandbox != 'object') {35sandbox = {};36}37return new ContextifyContext(sandbox);38};3940Contextify.createScript = function (code, filename) {41if (typeof code != 'string') {42throw new TypeError('Code argument is required');43}44return new ContextifyScript(code, filename);45};4647module.exports = Contextify;484950