From d89a66ec36491c1d98a1bbeb04dac4e74d66f754 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 20 Oct 2022 04:00:05 +0000 Subject: Minor internal JS cleanups. FossilOrigin-Name: 818ef0b5c909e733b643455278f7cc45533178f1cc6617058c00ed64fa44896a --- ext/wasm/api/extern-post-js.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'ext/wasm/api/extern-post-js.js') diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js index 5f5f72d4b..768696508 100644 --- a/ext/wasm/api/extern-post-js.js +++ b/ext/wasm/api/extern-post-js.js @@ -23,19 +23,24 @@ https://github.com/emscripten-core/emscripten/issues/18071 - The only current workaround is to temporarily stash this state + The only(?) current workaround is to temporarily stash this state into the global scope and delete it when sqlite3InitModule() is called. */ const initModuleState = self.sqlite3InitModuleState = Object.assign(Object.create(null),{ moduleScript: self?.document?.currentScript, - isWorker: (!self.document && self.window !== self), + isWorker: ('undefined' !== typeof WorkerGlobalScope), location: self.location, urlParams: new URL(self.location.href).searchParams }); if(initModuleState.urlParams.has('sqlite3.dir')){ initModuleState.sqlite3Dir = initModuleState.urlParams.get('sqlite3.dir') +'/'; - }; + }else if(initModuleState.moduleScript){ + const li = initModuleState.moduleScript.src.split('/'); + li.pop(); + initModuleState.sqlite3Dir = li.join('/') + '/'; + } + //console.warn("initModuleState =",initModuleState); self.sqlite3InitModule = (...args)=>{ //console.warn("Using replaced sqlite3InitModule()",self.location); @@ -79,4 +84,12 @@ document?.currentScript?.src); } } + /* Replace the various module exports performed by the Emscripten + glue... */ + if (typeof exports === 'object' && typeof module === 'object') + module.exports = sqlite3InitModule; + else if (typeof exports === 'object') + exports["sqlite3InitModule"] = sqlite3InitModule; + /* AMD modules get injected in a way we cannot override, + so we can't handle those here. */ })(); -- cgit v1.2.3