From a69f095720a18fd2db2b796d5bf2c34a564cec07 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 22 Nov 2014 14:14:42 +0200 Subject: [PATCH] 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). --- lib/6to5/runtime.js | 8 +++----- lib/6to5/templates/self-global.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/6to5/runtime.js b/lib/6to5/runtime.js index 6c4fdbc9fd..c431bc96dc 100644 --- a/lib/6to5/runtime.js +++ b/lib/6to5/runtime.js @@ -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([])) ) ])); diff --git a/lib/6to5/templates/self-global.js b/lib/6to5/templates/self-global.js index 72f256e1f7..3e55600935 100644 --- a/lib/6to5/templates/self-global.js +++ b/lib/6to5/templates/self-global.js @@ -1 +1 @@ -var self = typeof global === "undefined" ? window : global; +typeof global === "undefined" ? self : global