Fix runtime injection in Web Worker.

Web Workers don't have `window` object but they have `self`
(which is available in regular windows as well).
This commit is contained in:
Ingvar Stepanyan
2014-11-22 14:14:42 +02:00
parent d50d4972a7
commit a69f095720
2 changed files with 4 additions and 6 deletions

View File

@@ -8,15 +8,13 @@ module.exports = function (namespace) {
namespace = t.identifier(t.toIdentifier(namespace || "to5Runtime"));
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body));
var tree = t.program([t.expressionStatement(t.callExpression(container, []))]);
body.push(util.template("self-global", true));
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(
namespace,
t.assignmentExpression("=", t.memberExpression(t.identifier("self"), namespace), t.objectExpression([]))
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
)
]));

View File

@@ -1 +1 @@
var self = typeof global === "undefined" ? window : global;
typeof global === "undefined" ? self : global