diff options
author | stephan <stephan@noemail.net> | 2023-01-28 04:20:46 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-01-28 04:20:46 +0000 |
commit | 65f7942d0678a56f788d54a636c9c30ed63b5ee6 (patch) | |
tree | d3d7ad55512c95b9ca137d605d7e0b760f8bf687 /ext/wasm/api | |
parent | cfd01014d0b5657a8b48d4c828405703cce9e941 (diff) | |
parent | 69141f52be6368d3510b551c74029e3600b6f4c2 (diff) | |
download | sqlite-65f7942d0678a56f788d54a636c9c30ed63b5ee6.tar.gz sqlite-65f7942d0678a56f788d54a636c9c30ed63b5ee6.zip |
Add JS bundler-friendly JS build. Minor test code cleanups.
FossilOrigin-Name: 24d3a53dea5e596230558e233cbbd9d0288b4c394cd5ea7b650fd99bff4cde2e
Diffstat (limited to 'ext/wasm/api')
-rw-r--r-- | ext/wasm/api/extern-post-js.c-pp.js | 13 | ||||
-rw-r--r-- | ext/wasm/api/pre-js.c-pp.js | 13 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-api-oo1.js | 5 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 4 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-worker1-promiser.js | 4 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-worker1.js | 4 |
6 files changed, 32 insertions, 11 deletions
diff --git a/ext/wasm/api/extern-post-js.c-pp.js b/ext/wasm/api/extern-post-js.c-pp.js index 225869794..a577a63e1 100644 --- a/ext/wasm/api/extern-post-js.c-pp.js +++ b/ext/wasm/api/extern-post-js.c-pp.js @@ -9,7 +9,7 @@ Emscripten-generated module init scope, in the current global scope. */ //#if target=es6-module -const toExportForES6 = +const toExportForESM = //#endif (function(){ /** @@ -45,10 +45,10 @@ const toExportForES6 = moduleScript: self?.document?.currentScript, isWorker: ('undefined' !== typeof WorkerGlobalScope), location: self.location, - urlParams: new URL(self.location.href).searchParams + urlParams: new URL(self.location.href).searchParams }); initModuleState.debugModule = - (new URL(self.location.href).searchParams).has('sqlite3.debugModule') + initModuleState.urlParams.has('sqlite3.debugModule') ? (...args)=>console.warn('sqlite3.debugModule:',...args) : ()=>{}; @@ -105,6 +105,10 @@ const toExportForES6 = document?.currentScript?.src); } } +//#ifnot target=es6-module +// Emscripten does not inject these module-loader bits in ES6 module +// builds and including them here breaks JS bundlers, so elide them +// from ESM builds. /* Replace the various module exports performed by the Emscripten glue... */ if (typeof exports === 'object' && typeof module === 'object'){ @@ -114,8 +118,9 @@ const toExportForES6 = } /* AMD modules get injected in a way we cannot override, so we can't handle those here. */ +//#endif // !target=es6-module return self.sqlite3InitModule /* required for ESM */; })(); //#if target=es6-module -export default toExportForES6; +export default toExportForESM; //#endif diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 5d8e58864..a25c7ce77 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -6,12 +6,14 @@ */ // See notes in extern-post-js.js -const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.assign(Object.create(null),{ - debugModule: ()=>{} -}); +const sqlite3InitModuleState = self.sqlite3InitModuleState + || Object.assign(Object.create(null),{ + debugModule: ()=>{} + }); delete self.sqlite3InitModuleState; sqlite3InitModuleState.debugModule('self.location =',self.location); +//#ifnot target=es6-bundler-friendly /** This custom locateFile() tries to figure out where to load `path` from. The intent is to provide a way for foo/bar/X.js loaded from a @@ -53,8 +55,9 @@ Module['locateFile'] = function(path, prefix) { "result =", theFile ); return theFile; -//#endif /* SQLITE_JS_EMS */ +//#endif target=es6-module }.bind(sqlite3InitModuleState); +//#endif ifnot target=es6-bundler-friendly /** Bug warning: a custom Module.instantiateWasm() does not work @@ -64,7 +67,7 @@ Module['locateFile'] = function(path, prefix) { In such builds we must disable this. */ -const xNameOfInstantiateWasm = true +const xNameOfInstantiateWasm = false ? 'instantiateWasm' : 'emscripten-bug-17951'; Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index ba210e7f9..fddd7b38e 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -183,7 +183,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ checkSqlite3Rc( pDb, capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0) ); - } + } }catch(e){ this.close(); throw e; @@ -791,6 +791,9 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ - `callback` and `resultRows`: permit an array entries with semantics similar to those described for `bind` above. + - If passed neither a callback nor returnValue but is passed a + rowMode, default to returning the result set. + */ exec: function(/*(sql [,obj]) || (obj)*/){ affirmDbOpen(this); diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 2ded905ad..451f0019c 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -198,7 +198,9 @@ const installOpfsVfs = function callee(options){ return promiseReject_(err); }; const W = -//#if target=es6-module +//#if target=es6-bundler-friendly + new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url)); +//#elif target=es6-module new Worker(new URL(options.proxyUri, import.meta.url)); //#else new Worker(options.proxyUri); diff --git a/ext/wasm/api/sqlite3-worker1-promiser.js b/ext/wasm/api/sqlite3-worker1-promiser.js index 7360512d4..1689d3480 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.js @@ -238,6 +238,9 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){ }/*sqlite3Worker1Promiser()*/; self.sqlite3Worker1Promiser.defaultConfig = { worker: function(){ +//#if target=es6-bundler-friendly + return new Worker("sqlite3-worker1.js"); +//#else let theJs = "sqlite3-worker1.js"; if(this.currentScript){ const src = this.currentScript.src.split('/'); @@ -252,6 +255,7 @@ self.sqlite3Worker1Promiser.defaultConfig = { } } return new Worker(theJs + self.location.search); +//#endif }.bind({ currentScript: self?.document?.currentScript }), diff --git a/ext/wasm/api/sqlite3-worker1.js b/ext/wasm/api/sqlite3-worker1.js index 4ff19b888..9e9c3ac42 100644 --- a/ext/wasm/api/sqlite3-worker1.js +++ b/ext/wasm/api/sqlite3-worker1.js @@ -33,6 +33,9 @@ */ "use strict"; (()=>{ +//#if target=es6-bundler-friendly + importScripts('sqlite3.js'); +//#else const urlParams = new URL(self.location.href).searchParams; let theJs = 'sqlite3.js'; if(urlParams.has('sqlite3.dir')){ @@ -40,6 +43,7 @@ } //console.warn("worker1 theJs =",theJs); importScripts(theJs); +//#endif sqlite3InitModule().then((sqlite3)=>{ sqlite3.initWorker1API(); }); |