diff options
author | stephan <stephan@noemail.net> | 2023-03-07 19:12:06 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-03-07 19:12:06 +0000 |
commit | 4214cc32ba2082b90dde97495058c45920235bf4 (patch) | |
tree | 1728d17a0729bdbd450e11bf0eecb4c02ca06691 /ext/wasm/api/sqlite3-opfs-async-proxy.js | |
parent | 7272f6d64d88da451f18aa515db06ed6f2b459d4 (diff) | |
download | sqlite-4214cc32ba2082b90dde97495058c45920235bf4.tar.gz sqlite-4214cc32ba2082b90dde97495058c45920235bf4.zip |
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
Diffstat (limited to 'ext/wasm/api/sqlite3-opfs-async-proxy.js')
-rw-r--r-- | ext/wasm/api/sqlite3-opfs-async-proxy.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index 1456ae08d..ddcad8f61 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -50,10 +50,10 @@ const wPost = (type,...args)=>postMessage({type, payload:args}); const installAsyncProxy = function(self){ const toss = function(...args){throw new Error(args.join(' '))}; - if(self.window === self){ + if(globalThis.window === globalThis){ toss("This code cannot run from the main thread.", "Load it as a Worker from a separate Worker."); - }else if(!navigator.storage.getDirectory){ + }else if(!navigator?.storage?.getDirectory){ toss("This API requires navigator.storage.getDirectory."); } @@ -106,8 +106,8 @@ const installAsyncProxy = function(self){ w += m.wait; m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0; } - console.log(self.location.href, - "metrics for",self.location.href,":\n", + console.log(globalThis?.location?.href, + "metrics for",globalThis?.location?.href,":\n", metrics, "\nTotal of",n,"op(s) for",t,"ms", "approx",w,"ms spent waiting on OPFS APIs."); @@ -843,7 +843,7 @@ const installAsyncProxy = function(self){ navigator.storage.getDirectory().then(function(d){ state.rootDir = d; - self.onmessage = function({data}){ + globalThis.onmessage = function({data}){ switch(data.type){ case 'opfs-async-init':{ /* Receive shared state from synchronous partner */ @@ -880,17 +880,17 @@ const installAsyncProxy = function(self){ wPost('opfs-async-loaded'); }).catch((e)=>error("error initializing OPFS asyncer:",e)); }/*installAsyncProxy()*/; -if(!self.SharedArrayBuffer){ +if(!globalThis.SharedArrayBuffer){ wPost('opfs-unavailable', "Missing SharedArrayBuffer API.", "The server must emit the COOP/COEP response headers to enable that."); -}else if(!self.Atomics){ +}else if(!globalThis.Atomics){ wPost('opfs-unavailable', "Missing Atomics API.", "The server must emit the COOP/COEP response headers to enable that."); -}else if(!self.FileSystemHandle || - !self.FileSystemDirectoryHandle || - !self.FileSystemFileHandle || - !self.FileSystemFileHandle.prototype.createSyncAccessHandle || - !navigator.storage.getDirectory){ +}else if(!globalThis.FileSystemHandle || + !globalThis.FileSystemDirectoryHandle || + !globalThis.FileSystemFileHandle || + !globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle || + !navigator?.storage?.getDirectory){ wPost('opfs-unavailable',"Missing required OPFS APIs."); }else{ installAsyncProxy(self); |