From b196806eb2937e7ee56e42b482b7b3bd5e3c9d79 Mon Sep 17 00:00:00 2001 From: Azat Alimov <32402726+mkslanc@users.noreply.github.com> Date: Tue, 1 Aug 2023 15:29:53 +0400 Subject: [PATCH] fix: support more environments (#5266) --- Makefile.dryice.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 9f2b69986fe..890e05c7776 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -781,7 +781,7 @@ function namespace(ns) { function exportAce(ns, modules, requireBase, extModules) { requireBase = requireBase || "window"; return function(text) { - /*globals REQUIRE_NS, MODULES*/ + /*globals REQUIRE_NS, MODULES, self*/ var template = function() { (function() { REQUIRE_NS.require(MODULES, function(a) { @@ -789,13 +789,19 @@ function exportAce(ns, modules, requireBase, extModules) { a.config.init(true); a.define = REQUIRE_NS.define; } - if (!window.NS) - window.NS = a; + var global = (function () { + return this; + })(); + if (!global && typeof window != "undefined") global = window; // can happen in strict mode + if (!global && typeof self != "undefined") global = self; // can happen in webworker + + if (!global.NS) + global.NS = a; for (var key in a) if (a.hasOwnProperty(key)) - window.NS[key] = a[key]; - window.NS["default"] = window.NS; + global.NS[key] = a[key]; + global.NS["default"] = global.NS; if (typeof module == "object" && typeof exports == "object" && module) { - module.exports = window.NS; + module.exports = global.NS; } }); })();