const binding = require('bindings')('contextify');
const ContextifyContext = binding.ContextifyContext;
const ContextifyScript = binding.ContextifyScript;

function Contextify (sandbox) {
    if (typeof sandbox != 'object') {
        sandbox = {};
    }
    let 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;
}

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;

const binding = require('bindings')('contextify');
const ContextifyContext = binding.ContextifyContext;
const ContextifyScript = binding.ContextifyScript;

function Contextify (sandbox) {
    if (typeof sandbox != 'object') {
        sandbox = {};
    }
    let 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;
}

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;

Fix to use single quotes instead of double quotes
Fix to use single quotes instead of double quotes
