1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Replace use of 'self' in JS code with 'globalThis', as that works in browsers and node environments. Avoid using globalThis.location if it's not set (e.g. in node). Based on feedback in [forum:ac7a94d4f77db235|forum post ac7a94d4f77db235]. Minor JS build tweaks.

FossilOrigin-Name: dbbe8f25e58738c10b6192d41f1e3886983871f17631cbc45ce626d3f05a6e26
This commit is contained in:
stephan
2023-03-07 19:12:06 +00:00
parent 7272f6d64d
commit 4214cc32ba
17 changed files with 134 additions and 129 deletions

View File

@ -132,7 +132,7 @@
https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker
*/
self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
// Inspired by: https://stackoverflow.com/a/52439530
if(1===arguments.length && 'function'===typeof arguments[0]){
const f = config;
@ -245,7 +245,7 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
return p;
};
}/*sqlite3Worker1Promiser()*/;
self.sqlite3Worker1Promiser.defaultConfig = {
globalThis.sqlite3Worker1Promiser.defaultConfig = {
worker: function(){
//#if target=es6-bundler-friendly
return new Worker("sqlite3-worker1-bundler-friendly.mjs",{
@ -259,17 +259,17 @@ self.sqlite3Worker1Promiser.defaultConfig = {
src.pop();
theJs = src.join('/')+'/' + theJs;
//sqlite3.config.warn("promiser currentScript, theJs =",this.currentScript,theJs);
}else{
//sqlite3.config.warn("promiser self.location =",self.location);
const urlParams = new URL(self.location.href).searchParams;
}else if(globalThis.location){
//sqlite3.config.warn("promiser globalThis.location =",globalThis.location);
const urlParams = new URL(globalThis.location.href).searchParams;
if(urlParams.has('sqlite3.dir')){
theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
}
}
return new Worker(theJs + self.location.search);
return new Worker(theJs + globalThis.location.search);
//#endif
}.bind({
currentScript: self?.document?.currentScript
currentScript: globalThis?.document?.currentScript
}),
onerror: (...args)=>console.error('worker1 promiser error',...args)
};