From 5e76c93f1b5e1ffd87a98e44df0e97b6b798764a Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 22 Feb 2018 19:19:08 +0100 Subject: Fix JavaScript wrapper to support import from non global scope The generated code wrapper used `this` assuming it was always imported from the global scoped but that breaks when you import the scripts using WebPack or similar tools that wraps the imports in its own functions --- cpp/src/slice2js/Gen.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cpp/src/slice2js/Gen.cpp') diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp index 69c88b0f513..8be0d6111af 100644 --- a/cpp/src/slice2js/Gen.cpp +++ b/cpp/src/slice2js/Gen.cpp @@ -441,8 +441,10 @@ Slice::Gen::generate(const UnitPtr& p) _out << eb; _out << nl << "(typeof(global) !== \"undefined\" && typeof(global.process) !== \"undefined\" ? module : undefined," - << nl << " typeof(global) !== \"undefined\" && typeof(global.process) !== \"undefined\" ? require : this.Ice._require," - << nl << " typeof(global) !== \"undefined\" && typeof(global.process) !== \"undefined\" ? exports : this));"; + << nl << " typeof(global) !== \"undefined\" && typeof(global.process) !== \"undefined\" ? require :" + << nl << " (typeof WorkerGlobalScope !== \"undefined\" && self instanceof WorkerGlobalScope) ? self.Ice._require : window.Ice._require," + << nl << " typeof(global) !== \"undefined\" && typeof(global.process) !== \"undefined\" ? exports :" + << nl << " (typeof WorkerGlobalScope !== \"undefined\" && self instanceof WorkerGlobalScope) ? self : window));"; if(icejs) { -- cgit v1.2.3