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:
@ -18,7 +18,7 @@
|
||||
after sqlite3-api-oo1.js and before sqlite3-api-cleanup.js.
|
||||
*/
|
||||
'use strict';
|
||||
self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
/**
|
||||
installOpfsVfs() returns a Promise which, on success, installs an
|
||||
sqlite3_vfs named "opfs", suitable for use with all sqlite3 APIs
|
||||
@ -76,23 +76,23 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
`opfs` property, containing several OPFS-specific utilities.
|
||||
*/
|
||||
const installOpfsVfs = function callee(options){
|
||||
if(!self.SharedArrayBuffer
|
||||
|| !self.Atomics){
|
||||
if(!globalThis.SharedArrayBuffer
|
||||
|| !globalThis.Atomics){
|
||||
return Promise.reject(
|
||||
new Error("Cannot install OPFS: Missing SharedArrayBuffer and/or Atomics. "+
|
||||
"The server must emit the COOP/COEP response headers to enable those. "+
|
||||
"See https://sqlite.org/wasm/doc/trunk/persistence.md#coop-coep")
|
||||
);
|
||||
}else if(self.window===self && self.document){
|
||||
}else if('undefined'===typeof WorkerGlobalScope){
|
||||
return Promise.reject(
|
||||
new Error("The OPFS sqlite3_vfs cannot run in the main thread "+
|
||||
"because it requires Atomics.wait().")
|
||||
);
|
||||
}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){
|
||||
return Promise.reject(
|
||||
new Error("Missing required OPFS APIs.")
|
||||
);
|
||||
@ -100,7 +100,7 @@ const installOpfsVfs = function callee(options){
|
||||
if(!options || 'object'!==typeof options){
|
||||
options = Object.create(null);
|
||||
}
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
const urlParams = new URL(globalThis.location.href).searchParams;
|
||||
if(undefined===options.verbose){
|
||||
options.verbose = urlParams.has('opfs-verbose')
|
||||
? (+urlParams.get('opfs-verbose') || 2) : 1;
|
||||
@ -112,7 +112,7 @@ const installOpfsVfs = function callee(options){
|
||||
options.proxyUri = callee.defaultProxyUri;
|
||||
}
|
||||
|
||||
//sqlite3.config.warn("OPFS options =",options,self.location);
|
||||
//sqlite3.config.warn("OPFS options =",options,globalThis.location);
|
||||
|
||||
if('function' === typeof options.proxyUri){
|
||||
options.proxyUri = options.proxyUri();
|
||||
@ -149,11 +149,11 @@ const installOpfsVfs = function callee(options){
|
||||
Returns true if _this_ thread has access to the OPFS APIs.
|
||||
*/
|
||||
const thisThreadHasOPFS = ()=>{
|
||||
return self.FileSystemHandle &&
|
||||
self.FileSystemDirectoryHandle &&
|
||||
self.FileSystemFileHandle &&
|
||||
self.FileSystemFileHandle.prototype.createSyncAccessHandle &&
|
||||
navigator.storage.getDirectory;
|
||||
return globalThis.FileSystemHandle &&
|
||||
globalThis.FileSystemDirectoryHandle &&
|
||||
globalThis.FileSystemFileHandle &&
|
||||
globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle &&
|
||||
navigator?.storage?.getDirectory;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -171,8 +171,8 @@ const installOpfsVfs = function callee(options){
|
||||
m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0;
|
||||
m.avgWait = (m.count && m.wait) ? (m.wait / m.count) : 0;
|
||||
}
|
||||
sqlite3.config.log(self.location.href,
|
||||
"metrics for",self.location.href,":",metrics,
|
||||
sqlite3.config.log(globalThis.location.href,
|
||||
"metrics for",globalThis.location.href,":",metrics,
|
||||
"\nTotal of",n,"op(s) for",t,
|
||||
"ms (incl. "+w+" ms of waiting on the async side)");
|
||||
sqlite3.config.log("Serialization metrics:",metrics.s11n);
|
||||
@ -1311,7 +1311,7 @@ const installOpfsVfs = function callee(options){
|
||||
}/*installOpfsVfs()*/;
|
||||
installOpfsVfs.defaultProxyUri =
|
||||
"sqlite3-opfs-async-proxy.js";
|
||||
self.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
|
||||
globalThis.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
|
||||
try{
|
||||
let proxyJs = installOpfsVfs.defaultProxyUri;
|
||||
if(sqlite3.scriptInfo.sqlite3Dir){
|
||||
|
Reference in New Issue
Block a user