]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Get tester1.js working via an ES6 worker module and add that variant to the dist...
authorstephan <stephan@noemail.net>
Sat, 19 Nov 2022 16:16:40 +0000 (16:16 +0000)
committerstephan <stephan@noemail.net>
Sat, 19 Nov 2022 16:16:40 +0000 (16:16 +0000)
FossilOrigin-Name: 90480586f1b2ad82118e19536b095431b8457f294c0afaa9b4f883f184cc804c

ext/wasm/GNUmakefile
ext/wasm/dist.make
ext/wasm/index-dist.html
ext/wasm/index.html
ext/wasm/tester1-esm.html
ext/wasm/tester1-worker.html
ext/wasm/tester1.c-pp.js [moved from ext/wasm/tester1.js with 99% similarity]
manifest
manifest.uuid

index 03b7689f2df0a9fdd39e80bbadba0a02bc42c88f..3d952c2615662d181e721fcb29c0b74ec14f1092 100644 (file)
@@ -227,12 +227,13 @@ bin.c-pp := ./c-pp
 $(bin.c-pp): c-pp.c $(sqlite3.c) $(MAKEFILE)
        $(CC) -O0 -o $@ c-pp.c $(sqlite3.c) '-DCMPP_DEFAULT_DELIM="//#"' -I$(dir.top)
 define C-PP.JS
-# $1 c-pp -D... flags
-# $2 = c-pp -f X.js
-# $3 = c-pp -o X.js
-$(3): $(2) $$(MAKEFILE) $$(bin.c-pp)
-       $$(bin.c-pp) -f $(2) -o $$@ $(1)
-CLEAN_FILES += $(3)
+# Create $2 from $1 using $(bin.c-pp)
+# $1 = Input file: c-pp -f X.js
+# $2 = Output file: c-pp -o X.js
+# $3 = optional c-pp -D... flags
+$(2): $(1) $$(MAKEFILE) $$(bin.c-pp)
+       $$(bin.c-pp) -f $(1) -o $$@ $(3)
+CLEAN_FILES += $(2)
 endef
 c-pp.D.vanilla ?=
 c-pp.D.esm ?= -Dsqlite3-es6-module-build
@@ -300,8 +301,8 @@ $(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE)
 pre-js.js.in := $(dir.api)/pre-js.js
 pre-js.js.esm := $(dir.tmp)/pre-js.esm.js
 pre-js.js.vanilla := $(dir.tmp)/pre-js.vanilla.js
-$(eval $(call C-PP.JS,$(c-pp.D.vanilla),$(pre-js.js.in),$(pre-js.js.vanilla)))
-$(eval $(call C-PP.JS,$(c-pp.D.esm),$(pre-js.js.in),$(pre-js.js.esm)))
+$(eval $(call C-PP.JS,$(pre-js.js.in),$(pre-js.js.vanilla),$(c-pp.D.vanilla)))
+$(eval $(call C-PP.JS,$(pre-js.js.in),$(pre-js.js.esm),$(c-pp.D.esm)))
 post-js.js.in := $(dir.tmp)/post-js.js
 post-js.js.vanilla := $(dir.tmp)/post-js.vanilla.js
 post-js.js.esm := $(dir.tmp)/post-js.esm.js
@@ -316,14 +317,14 @@ $(post-js.js.in): $(post-jses.js) $(MAKEFILE)
                cat $$i; \
                echo "/* END FILE: $$i */"; \
        done > $@
-$(eval $(call C-PP.JS,$(c-pp.D.vanilla),$(post-js.js.in),$(post-js.js.vanilla)))
-$(eval $(call C-PP.JS,$(c-pp.D.esm),$(post-js.js.in),$(post-js.js.esm)))
+$(eval $(call C-PP.JS,$(post-js.js.in),$(post-js.js.vanilla),$(c-pp.D.vanilla)))
+$(eval $(call C-PP.JS,$(post-js.js.in),$(post-js.js.esm),$(c-pp.D.esm)))
 
 extern-post-js.js.in := $(dir.api)/extern-post-js.js
 extern-post-js.js.vanilla := $(dir.tmp)/extern-post-js.vanilla.js
 extern-post-js.js.esm := $(dir.tmp)/extern-post-js.esm.js
-$(eval $(call C-PP.JS,$(c-pp.D.vanilla),$(extern-post-js.js.in),$(extern-post-js.js.vanilla)))
-$(eval $(call C-PP.JS,$(c-pp.D.esm),$(extern-post-js.js.in),$(extern-post-js.js.esm)))
+$(eval $(call C-PP.JS,$(extern-post-js.js.in),$(extern-post-js.js.vanilla),$(c-pp.D.vanilla)))
+$(eval $(call C-PP.JS,$(extern-post-js.js.in),$(extern-post-js.js.esm),$(c-pp.D.esm)))
 extern-pre-js.js := $(dir.api)/extern-pre-js.js
 
 # Emscripten flags for --[extern-][pre|post]-js=...
@@ -642,6 +643,17 @@ CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
 # end speedtest1.js
 ########################################################################
 
+########################################################################
+# tester1 code:
+#  tester1.js: for main thread and worker thread
+#  tester1-esm.js: to be loaded from an ES6 Worker Module thread
+$(eval $(call C-PP.JS,tester1.c-pp.js,tester1.js))
+$(eval $(call C-PP.JS,tester1.c-pp.js,tester1-esm.js,-Dtester1-esm-worker))
+tester1.js: $(sqlite3.js)
+tester1-esm.js: $(sqlite3.mjs)
+tester1: tester1.js tester1-esm.js
+all: tester1
+
 ########################################################################
 # Convenience rules to rebuild with various -Ox levels. Much
 # experimentation shows -O2 to be the clear winner in terms of speed.
index 07d289ddbf81f6d7db9c869b4360abcc2fe972c9..f33711a19deef1c7004df031b43a40ab74875808 100644 (file)
@@ -42,7 +42,8 @@ dist-dir.jswasm := $(dist-dir.top)/$(notdir $(dir.dout))
 dist-dir.common := $(dist-dir.top)/common
 dist.top.extras := \
     demo-123.html demo-123-worker.html demo-123.js \
-    tester1.html tester1-worker.html tester1-esm.html tester1.js \
+    tester1.html tester1-worker.html tester1-esm.html \
+    tester1.js tester1-esm.js \
     demo-jsstorage.html demo-jsstorage.js \
     demo-worker1.html demo-worker1.js \
     demo-worker1-promiser.html demo-worker1-promiser.js
index 2333190d9510f904518c3027f174db9c24d396dc..29891c91e9c36b37893c71032feff4114b5a1415 100644 (file)
               utility code.</li>
             <li><a href='tester1-worker.html'>tester1-worker</a>: same thing
               but running in a Worker.</li>
-            <li><a href='tester1-esm.html'>tester1-esm</a>: same thing
-              but loaded in the main thread via an ES6 module. Note that
-              not all browsers permit loading modules in Worker threads.
+            <li><a href='tester1-esm.html'>tester1-esm</a>: same as
+              <code>tester1</code> but loads sqlite3 in the main thread via
+              an ES6 module.
+            </li>
+            <li><a href='tester1-worker.html?esm'>tester1-worker?esm</a>:
+              same as <code>tester1-esm</code> but loads a Worker Module which
+              then loads the sqlite3 API via an ES6 module. Note that
+              not all browsers permit loading modules in Worker
+              threads.
             </li>
           </ul>
         </li>
index 0aca0661c26610a00d886a10ed18bb2c81165203..0a6cd0a6203a57658d043da27317f942febc9312 100644 (file)
               utility code.</li>
             <li><a href='tester1-worker.html'>tester1-worker</a>: same thing
               but running in a Worker.</li>
-            <li><a href='tester1-esm.html'>tester1-esm</a>: same thing
-              but loaded in the main thread via an ES6 module. Note that
-              not all browsers permit loading modules in Worker threads.
+            <li><a href='tester1-esm.html'>tester1-esm</a>: same as
+              <code>tester1</code> but loads sqlite3 in the main thread via
+              an ES6 module.
+            </li>
+            <li><a href='tester1-worker.html?esm'>tester1-worker?esm</a>:
+              same as <code>tester1-esm</code> but loads a Worker Module which
+              then loads the sqlite3 API via an ES6 module. Note that
+              not all browsers permit loading modules in Worker
+              threads.
+            </li>
           </ul>
         </li>
         <li>High-level apps and demos...
index dc63f7cbe620121a5e318600674635b19b9f96a9..118ab676bde26b348738a3862b1f774f04f53c48 100644 (file)
@@ -6,7 +6,7 @@
     <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
     <link rel="stylesheet" href="common/emscripten.css"/>
     <link rel="stylesheet" href="common/testing.css"/>
-    <title>sqlite3 tester ESM #1 (UI thread)</title>
+    <title>sqlite3 tester #1: ES6 Module in UI thread</title>
     <style>
       body {
           font-family: monospace;
@@ -14,7 +14,7 @@
     </style>
   </head>
   <body>
-    <h1 id='color-target'>sqlite3 WASM/JS tester ESM #1 (UI thread)</h1>
+    <h1 id='color-target'>sqlite3 tester #1: ES6 Module in UI thread</h1>
     <div class='input-wrapper'>
       <input type='checkbox' id='cb-log-reverse'>
       <label for='cb-log-reverse'>Reverse log order?</label>
index 4d2df0c8d1429a7e5d45cc005e0404548793da5a..b750df9169320ac4c9aade786a0e37b00bcf8dc0 100644 (file)
@@ -6,7 +6,7 @@
     <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
     <link rel="stylesheet" href="../common/emscripten.css"/>
     <link rel="stylesheet" href="../common/testing.css"/>
-    <title>sqlite3 tester #1 (Worker thread)</title>
+    <title>sqlite3 tester #1: Worker thread</title>
     <style>
       body {
           font-family: monospace;
@@ -14,7 +14,7 @@
     </style>
   </head>
   <body>
-    <h1 id='color-target'>sqlite3 WASM/JS tester #1 (Worker thread)</h1>
+    <h1 id='color-target'>sqlite3 tester #1: Worker thread</h1>
     <div>See <a href='tester1.html' target='tester1.html'>tester1.html</a>
       for the UI-thread variant.</div>
     <div class='input-wrapper'>
       };
       cbReverse.addEventListener('change',cbReverseIt,true);
       cbReverseIt();
-      const w = new Worker("tester1.js?sqlite3.dir=jswasm");
+      const urlParams = new URL(self.location.href).searchParams;
+      const workerArgs = [];
+      if(urlParams.has('esm')){
+          logHtml('warning',"Attempting to run an ES6 Worker Module, "+
+                  "which is not supported by all browsers! "+
+                  "e.g. Firefox (as of 2022-11) cannot do this.");
+        workerArgs.push("tester1-esm.js",{type:"module"});
+        document.querySelectorAll('title,#color-target').forEach((e)=>{
+          e.innerText = "sqlite3 tester #1: ES6 Worker Module";
+        });
+      }else{
+        workerArgs.push("tester1.js?sqlite3.dir=jswasm");
+      }
+      const w = new Worker(...workerArgs);
       w.onmessage = function({data}){
         switch(data.type){
             case 'log':
similarity index 99%
rename from ext/wasm/tester1.js
rename to ext/wasm/tester1.c-pp.js
index 99fb5b31848ae1659d94a0ddd091d99009ceb2db..7aa8ba4a65985ed4d75593bcb65e169cc0f94ede 100644 (file)
   a db in an early test and close it in a later test. Each test gets
   passed the sqlite3 namespace object as its only argument.
 */
+/*
+   This file is intended to be processed by c-pp to inject (or not)
+   code specific to ES6 modules which is illegal in non-module code.
+
+   Non-ES6 module build and ES6 module for the main-thread:
+
+     ./c-pp -f tester1.c-pp.js -o tester1.js
+
+   ES6 worker module build:
+
+     ./c-pp -f tester1.c-pp.js -o tester1-esm.js -Dtester1-esm-worker
+*/
+//#if tester1-esm-worker
+import {default as sqlite3InitModule} from './jswasm/sqlite3.mjs';
+self.sqlite3InitModule = sqlite3InitModule;
+//#else
 'use strict';
-(function(){
+//#endif
+(function(self){
   /**
      Set up our output channel differently depending
      on whether we are running in a worker thread or
 
   ////////////////////////////////////////////////////////////////////////
   log("Loading and initializing sqlite3 WASM module...");
-  if(!isUIThread()){
+  if(!self.sqlite3InitModule && !isUIThread()){
+    /* Vanilla worker, as opposed to an ES6 module worker */
     /*
       If sqlite3.js is in a directory other than this script, in order
       to get sqlite3.js to resolve sqlite3.wasm properly, we have to
     }
     TestUtil.runTests(sqlite3);
   });
-})();
+})(self);
+
index 9d1924cb8e6df4c1e834c15a4f677a217dc7fa3f..40a5b2d04c6d8ecb37539e0aafabaa05770578b2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improved\scomments\son\sthe\spageFreeArray()\sroutine\sof\sbtree.c.\s\sNo\schanges\sto\ncode.
-D 2022-11-19T14:18:48.226
+C Get\stester1.js\sworking\svia\san\sES6\sworker\smodule\sand\sadd\sthat\svariant\sto\sthe\sdist\szipfile.
+D 2022-11-19T16:16:40.998
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -488,7 +488,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
 F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
-F ext/wasm/GNUmakefile 1e38a4f7147d621bd2138d13938ef34157bcf47908325baa6b06cd02c5e3ef89
+F ext/wasm/GNUmakefile 616c2a3e944483f6f5f66a6f77885eb7a7d3fef1a599014d746a792b6ef7b6b6
 F ext/wasm/README-dist.txt 2d670b426fc7c613b90a7d2f2b05b433088fe65181abead970980f0a4a75ea20
 F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9
 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 9120c2f8f51fa85f46dcf4dcb6b12f4a807d428f6089b99cdb08d8ddfcfd88b2
@@ -527,14 +527,14 @@ F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98
 F ext/wasm/demo-worker1-promiser.js b85a2bb1b918db4f09dfa24419241cb3edad7791389425c2505092e9b715017d
 F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d
 F ext/wasm/demo-worker1.js a619adffc98b75b66c633b00f747b856449a134a9a0357909287d80a182d70fa
-F ext/wasm/dist.make 4b55c8a7926bbab4936adab6a08eca524085fc47bc3b08f41918df5b4665da3d
+F ext/wasm/dist.make d00562b499096704304d9879f834a76475c8dd7ac58aaa3f039625ecc299aa3d
 F ext/wasm/fiddle.make 2812c44c9bafb5be9c8767963d1b9f374d77af7795fcaa06483c03e7059dea74
 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
 F ext/wasm/fiddle/fiddle-worker.js b4a0c8ab6c0983218543ca771c45f6075449f63a1dcf290ae5a681b2cba8800d
 F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715
 F ext/wasm/fiddle/index.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2
-F ext/wasm/index-dist.html 6bfb3591e40f7c23626730df587f533e983e996d4d1fb67244fb6a88fe6cf9a6
-F ext/wasm/index.html 49f58dddc29f6394b6e8a93e42768de59380c258454b68b9182e1946d13a4a4b
+F ext/wasm/index-dist.html c4337617c4d6d4d0796827cec28ac81d128c6f911dcf888a290a32ad50890408
+F ext/wasm/index.html 8289252ca8b25a4a76b8e5a86e84c42f5c7ca3302f2b5b1dbdf269fa96c28d84
 F ext/wasm/jaccwabyt/jaccwabyt.js 95f573de1826474c9605dda620ee622fcb1673ae74f191eb324c0853aa4dcb66
 F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708f63ba0cf917cb5b68e
 F ext/wasm/module-symbols.html b8eebafef8e536624bbe5f7a3da40c07a9062b843dfd3161a0bb72cbb6763dc5
@@ -549,10 +549,10 @@ F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d826
 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
 F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555e685bce3da8c3f
 F ext/wasm/test-opfs-vfs.js 44363db07b2a20e73b0eb1808de4400ca71b703af718d0fa6d962f15e73bf2ac
-F ext/wasm/tester1-esm.html 8d226a21b20707dbd66d68a3990141f0392fc781a281291d3dc59f38a3555887
-F ext/wasm/tester1-worker.html 51bf39e2b87f974ae3d5bc3086e2fb36d258f3698c54f6e21ba4b3b99636fa27
+F ext/wasm/tester1-esm.html 821c7a38b4eb753f6f3d7b5cbfda5b36f85466763977f96bff8372621b6b9eb2
+F ext/wasm/tester1-worker.html 84d56db05bcea2b294a89ca13c21b76fa0521ca4ac240f0055f1819934c713fc
+F ext/wasm/tester1.c-pp.js f4b96977a48cdfc13d477ede6d2f754865e9bcd1a23ce09359c31de41b24ba0d w ext/wasm/tester1.js
 F ext/wasm/tester1.html 624ec41cd9f78a1f2b6d7df70aaa7a6394396b1f2455ecbd6de5775c1275b121
-F ext/wasm/tester1.js bff806de454de115922d78c056f11d523ec7ed9ed3839d4e21433a9f72558b88
 F ext/wasm/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd72273503ae7d5
 F ext/wasm/wasmfs.make 8aa7565f9de8dd3c291ad8c3ceb1a2c67a3eb31a8e531070b25c6c6b1f0278bf
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
@@ -2057,8 +2057,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 4cb285210b4a2b14c80962bf2ecb35be310d3444c329c15d86b3073096455704
-R 08dfc1f1d36db05c00bfb06ac1037121
-U drh
-Z 7815819acfb2ddb8c0f5e3f3b0dc41f8
+P 0c2adc6d3547b07e950ae49f07f688f71a21b3ad5a51f16f0e8d49ab91564582
+R 22f7660d86bcdb1d5d00005b75d1164a
+U stephan
+Z 9963e0b4fa0faa6cb28eaed2062c3627
 # Remove this line to create a well-formed Fossil manifest.
index b2733321bccaf8699688c0f4411916ea504c4038..5f460cd81571cf70329bb20acd240360210c3aa0 100644 (file)
@@ -1 +1 @@
-0c2adc6d3547b07e950ae49f07f688f71a21b3ad5a51f16f0e8d49ab91564582
\ No newline at end of file
+90480586f1b2ad82118e19536b095431b8457f294c0afaa9b4f883f184cc804c
\ No newline at end of file