aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/pre-js.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-11-03 22:14:47 +0000
committerstephan <stephan@noemail.net>2022-11-03 22:14:47 +0000
commitb0ab21dee40144d8aec92df4a0c98eb069badeb3 (patch)
treedd60a8f10bef28cd2f0f8f18e75d057870e64d3a /ext/wasm/api/pre-js.js
parent4df2ab575facacd8987b65078202cc638e0252ae (diff)
downloadsqlite-b0ab21dee40144d8aec92df4a0c98eb069badeb3.tar.gz
sqlite-b0ab21dee40144d8aec92df4a0c98eb069badeb3.zip
Experimentally use clang's C preprocessor to filter #ifdef's out of the generated sqlite3-api.js, the goal being to see if we can feasibly use cpp to include ES6 module-specific code in the main code base and conditionally filter it out.
FossilOrigin-Name: 718a6d371e61359d73c8f80afdb248e3d9b4d8df4c4e5c122ac884344e31035b
Diffstat (limited to 'ext/wasm/api/pre-js.js')
-rw-r--r--ext/wasm/api/pre-js.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/ext/wasm/api/pre-js.js b/ext/wasm/api/pre-js.js
index f31dea179..f959c3307 100644
--- a/ext/wasm/api/pre-js.js
+++ b/ext/wasm/api/pre-js.js
@@ -29,6 +29,10 @@ sqlite3InitModuleState.debugModule('self.location =',self.location);
4) If none of the above apply, (prefix+path) is returned.
*/
Module['locateFile'] = function(path, prefix) {
+#ifdef SQLITE_JS_ESM
+ return new URL(path, import.meta.url).href;
+#else
+ 'use strict';
let theFile;
const up = this.urlParams;
if(up.has(path)){
@@ -47,6 +51,7 @@ Module['locateFile'] = function(path, prefix) {
"result =", theFile
);
return theFile;
+#endif /* SQLITE_JS_EMS */
}.bind(sqlite3InitModuleState);
/**
@@ -65,7 +70,7 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){
const uri = Module.locateFile(
callee.uri, (
('undefined'===typeof scriptDirectory/*var defined by Emscripten glue*/)
- ? '' : scriptDirectory)
+ ? "" : scriptDirectory)
);
sqlite3InitModuleState.debugModule(
"instantiateWasm() uri =", uri