From 746e9017b3b3989e501968c19f6fa82f831004c0 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 28 Dec 2017 17:39:09 +1100 Subject: src/loadlib.js: Add support for web worker global env --- package.json | 7 ++++--- src/loadlib.js | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6bbad0a..0936559 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,10 @@ }, "eslintConfig": { "env": { - "browser": true, - "es6": true, - "node": true + "browser": true, + "es6": true, + "node": true, + "worker": true }, "extends": "eslint:recommended", "rules": { diff --git a/src/loadlib.js b/src/loadlib.js index eb382c1..bb7792a 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -5,12 +5,16 @@ const lua = require('./lua.js'); const lauxlib = require('./lauxlib.js'); const global_env = (function() { + /* global WorkerGlobalScope */ /* see https://github.com/sindresorhus/globals/issues/127 */ if (typeof process !== "undefined") { /* node */ return global; } else if (typeof window !== "undefined") { /* browser window */ return window; + } else if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { + /* web worker */ + return self; } else { /* unknown global env */ return eval('this'); /* use non-strict mode to get global env */ -- cgit v1.2.3-70-g09d2