aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-cleanup.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-08-10 11:26:08 +0000
committerstephan <stephan@noemail.net>2022-08-10 11:26:08 +0000
commit3961b2636329819f16b1f32739274f3a1d3273de (patch)
treeb363bc8081c45b6e16ffe1d9a55862dd0bda4036 /ext/wasm/api/sqlite3-api-cleanup.js
parent8c3b7501af8fa321a1cdf3194d91603d0cbc6394 (diff)
downloadsqlite-3961b2636329819f16b1f32739274f3a1d3273de.tar.gz
sqlite-3961b2636329819f16b1f32739274f3a1d3273de.zip
wasm refactoring part 2 of (apparently) 2: moved ext/fiddle/... into ext/wasm and restructured the core API-related parts of the JS/WASM considerably.
FossilOrigin-Name: 27f9da4eaaff39d1d58e9ffef7ddccf1e41b3726914f754b920e3e1fb572cba6
Diffstat (limited to 'ext/wasm/api/sqlite3-api-cleanup.js')
-rw-r--r--ext/wasm/api/sqlite3-api-cleanup.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js
new file mode 100644
index 000000000..a2f921a5d
--- /dev/null
+++ b/ext/wasm/api/sqlite3-api-cleanup.js
@@ -0,0 +1,44 @@
+/*
+ 2022-07-22
+
+ The author disclaims copyright to this source code. In place of a
+ legal notice, here is a blessing:
+
+ * May you do good and not evil.
+ * May you find forgiveness for yourself and forgive others.
+ * May you share freely, never taking more than you give.
+
+ ***********************************************************************
+
+ This file is the tail end of the sqlite3-api.js constellation,
+ intended to be appended after all other files so that it can clean
+ up any global systems temporarily used for setting up the API's
+ various subsystems.
+*/
+'use strict';
+self.sqlite3.postInit.forEach(
+ self.importScripts/*global is a Worker*/
+ ? function(f){
+ /** We try/catch/report for the sake of failures which happen in
+ a Worker, as those exceptions can otherwise get completely
+ swallowed, leading to confusing downstream errors which have
+ nothing to do with this failure. */
+ try{ f(self, self.sqlite3) }
+ catch(e){
+ console.error("Error in postInit() function:",e);
+ throw e;
+ }
+ }
+ : (f)=>f(self, self.sqlite3)
+);
+delete self.sqlite3.postInit;
+if(self.location && +self.location.port > 1024){
+ console.warn("Installing sqlite3 bits as global S for dev-testing purposes.");
+ self.S = self.sqlite3;
+}
+/* Clean up temporary global-scope references to our APIs... */
+self.sqlite3.config.Module.sqlite3 = self.sqlite3
+/* ^^^^ Currently needed by test code and Worker API setup */;
+delete self.sqlite3.capi.util /* arguable, but these are (currently) internal-use APIs */;
+delete self.sqlite3 /* clean up our global-scope reference */;
+//console.warn("Module.sqlite3 =",Module.sqlite3);