diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 3d952c2615..1c74531403 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -226,17 +226,17 @@ DISTCLEAN_FILES += $(bin.stripccomments) 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 +define C-PP.FILTER # Create $2 from $1 using $(bin.c-pp) -# $1 = Input file: c-pp -f X.js -# $2 = Output file: c-pp -o X.js +# $1 = Input file: c-pp -f $(1).js +# $2 = Output file: c-pp -o $(2).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 +c-pp.D.esm ?= -Dtarget=es6-module # /end CPP-of-JS bits ######################################################################## @@ -301,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,$(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))) +$(eval $(call C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.vanilla),$(c-pp.D.vanilla))) +$(eval $(call C-PP.FILTER,$(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 @@ -317,14 +317,14 @@ $(post-js.js.in): $(post-jses.js) $(MAKEFILE) cat $$i; \ echo "/* END FILE: $$i */"; \ done > $@ -$(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))) +$(eval $(call C-PP.FILTER,$(post-js.js.in),$(post-js.js.vanilla),$(c-pp.D.vanilla))) +$(eval $(call C-PP.FILTER,$(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,$(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))) +$(eval $(call C-PP.FILTER,$(extern-post-js.js.in),$(extern-post-js.js.vanilla),$(c-pp.D.vanilla))) +$(eval $(call C-PP.FILTER,$(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=... @@ -644,13 +644,22 @@ CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm) ######################################################################## ######################################################################## -# 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 is the main unit and regression test application and needs to +# be able to run in 4 separate modes to cover the primary use cases: +# +# 1) Load sqlite3 in the main UI thread of a conventional script. +# 2) Load sqlite3 in a conventional Worker thread. +# 3) Load sqlite3 as an ES6 module (ESM) in the main thread. +# 4) Load sqlite3 as an ESM worker. (Not all browsers support this.) +# +# To that end, we require two separate builds of tester1.js: +# +# tester1.js: cases 1 and 2 +# tester1-esm.js: cases 3 and 4 +# +# To create those, we filter tester1.c-pp.js with $(bin.c-pp)... +$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.js)) +$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1-esm.js,$(c-pp.D.esm))) tester1: tester1.js tester1-esm.js all: tester1 diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js index 3dc61ae050..acf7068fef 100644 --- a/ext/wasm/api/extern-post-js.js +++ b/ext/wasm/api/extern-post-js.js @@ -8,7 +8,7 @@ most of the associated JS code, runs outside of the Emscripten-generated module init scope, in the current global scope. */ -//#if sqlite3-es6-module-build +//#if target=es6-module const toExportForES6 = //#endif (function(){ @@ -110,10 +110,8 @@ const toExportForES6 = exports["sqlite3InitModule"] = sqlite3InitModule; /* AMD modules get injected in a way we cannot override, so we can't handle those here. */ -//#if sqlite3-es6-module-build - return self.sqlite3InitModule; -//#endif + return self.sqlite3InitModule /* required for ESM */; })(); -//#if sqlite3-es6-module-build +//#if target=es6-module export default toExportForES6; //#endif diff --git a/ext/wasm/api/pre-js.js b/ext/wasm/api/pre-js.js index 41d13d6853..2e2fe66bc9 100644 --- a/ext/wasm/api/pre-js.js +++ b/ext/wasm/api/pre-js.js @@ -29,7 +29,7 @@ sqlite3InitModuleState.debugModule('self.location =',self.location); 4) If none of the above apply, (prefix+path) is returned. */ Module['locateFile'] = function(path, prefix) { -//#if sqlite3-es6-module-build +//#if target=es6-module return new URL(path, import.meta.url).href; //#else 'use strict'; diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-api-opfs.js index 31fe45eda0..a3f73cc7b2 100644 --- a/ext/wasm/api/sqlite3-api-opfs.js +++ b/ext/wasm/api/sqlite3-api-opfs.js @@ -167,7 +167,7 @@ const installOpfsVfs = function callee(options){ return promiseReject_(err); }; const W = -//#if sqlite3-es6-module-build +//#if target=es6-module new Worker(new URL(options.proxyUri, import.meta.url)); //#else new Worker(options.proxyUri); diff --git a/ext/wasm/tester1-esm.html b/ext/wasm/tester1-esm.html index 118ab676bd..498a1ab6a7 100644 --- a/ext/wasm/tester1-esm.html +++ b/ext/wasm/tester1-esm.html @@ -20,11 +20,6 @@
- - +