aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-cleanup.js
blob: a2f921a5d7bb94113d077201739e92f0e4dcb978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);