From 3ff812aa94644dc60bda6933de8b4870d9f5cba6 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 6 Feb 2023 14:01:19 +0000 Subject: [PATCH] Add capability to override the JS's use of console.log/debug/warn/error() with client-provided versions via the bootstrap-time config object. FossilOrigin-Name: c54f29d8e55419eaa9168e799dab5030e89063b13d8390a50616606422d164dc --- ext/wasm/api/sqlite3-api-oo1.js | 12 ++++----- ext/wasm/api/sqlite3-api-prologue.js | 10 +++++++ ext/wasm/api/sqlite3-api-worker1.js | 4 +-- ext/wasm/api/sqlite3-opfs-async-proxy.js | 12 ++++----- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 20 +++++++------- ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 4 +-- ext/wasm/tester1.c-pp.js | 10 ++++++- manifest | 26 +++++++++---------- manifest.uuid | 2 +- 9 files changed, 59 insertions(+), 41 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index 26aa80f723..914497602e 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -136,7 +136,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ if(('string'!==typeof fn && 'number'!==typeof fn) || 'string'!==typeof flagsStr || (vfsName && ('string'!==typeof vfsName && 'number'!==typeof vfsName))){ - console.error("Invalid DB ctor args",opt,arguments); + sqlite3.config.error("Invalid DB ctor args",opt,arguments); toss3("Invalid arguments for DB constructor."); } let fnJs = ('number'===typeof fn) ? wasm.cstrToJs(fn) : fn; @@ -881,7 +881,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ stmt = null; } }/*catch(e){ - console.warn("DB.exec() is propagating exception",opt,e); + sqlite3.config.warn("DB.exec() is propagating exception",opt,e); throw e; }*/finally{ if(stmt){ @@ -1278,7 +1278,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ function returns that value, else it throws. */ const affirmSupportedBindType = function(v){ - //console.log('affirmSupportedBindType',v); + //sqlite3.config.log('affirmSupportedBindType',v); return isSupportedBindType(v) || toss3("Unsupported bind() argument type:",typeof v); }; @@ -1394,7 +1394,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ break; } default: - console.warn("Unsupported bind() argument type:",val); + sqlite3.config.warn("Unsupported bind() argument type:",val); toss3("Unsupported bind() argument type: "+(typeof val)); } if(rc) DB.checkRc(stmt.db.pointer, rc); @@ -1599,7 +1599,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ case capi.SQLITE_ROW: return this._mayGet = true; default: this._mayGet = false; - console.warn("sqlite3_step() rc=",rc, + sqlite3.config.warn("sqlite3_step() rc=",rc, capi.sqlite3_js_rc_str(rc), "SQL =", capi.sqlite3_sql(this.pointer)); DB.checkRc(this.db.pointer, rc); @@ -1722,7 +1722,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ hope for the best, as the C API would do. */ toss3("Integer is out of range for JS integer range: "+rc); } - //console.log("get integer rc=",rc,isInt32(rc)); + //sqlite3.config.log("get integer rc=",rc,isInt32(rc)); return util.isInt32(rc) ? (rc | 0) : rc; } } diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 137ab1ee78..b08ad7a7ce 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -82,6 +82,12 @@ the `realloc(3)`-compatible routine for the WASM environment. Defaults to `"sqlite3_realloc"`. + - `debug`, `log`, `warn`, and `error` may be functions equivalent + to the like-named methods of the global `console` object. By + default, these map directly to their `console` counterparts, but + can be replaced with (e.g.) empty functions to squelch all such + output. + - `wasmfsOpfsDir`[^1]: As of 2022-12-17, this feature does not currently work due to incompatible Emscripten-side changes made in the WASMFS+OPFS combination. This option is currently ignored. @@ -113,6 +119,10 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( } return !!self.BigInt64Array; })(), + debug: console.debug.bind(console), + warn: console.warn.bind(console), + error: console.error.bind(console), + log: console.log.bind(console), wasmfsOpfsDir: '/opfs', /** useStdAlloc is just for testing an allocator discrepancy. The diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js index 58b9b00918..f82be6cd09 100644 --- a/ext/wasm/api/sqlite3-api-worker1.js +++ b/ext/wasm/api/sqlite3-api-worker1.js @@ -612,8 +612,8 @@ sqlite3.initWorker1API = function(){ result.stack = ('string'===typeof err.stack) ? err.stack.split(/\n\s*/) : err.stack; } - if(0) console.warn("Worker is propagating an exception to main thread.", - "Reporting it _here_ for the stack trace:",err,result); + if(0) sqlite3.config.warn("Worker is propagating an exception to main thread.", + "Reporting it _here_ for the stack trace:",err,result); } if(!dbId){ dbId = result.dbId/*from 'open' cmd*/ diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js index 1456ae08d2..b1ad9152e7 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js @@ -74,9 +74,9 @@ const installAsyncProxy = function(self){ state.verbose = 1; const loggers = { - 0:console.error.bind(console), - 1:console.warn.bind(console), - 2:console.log.bind(console) + 0:sqlite3.config.error.bind(console), + 1:sqlite3.config.warn.bind(console), + 2:sqlite3.config.log.bind(console) }; const logImpl = (level,...args)=>{ if(state.verbose>level) loggers[level]("OPFS asyncer:",...args); @@ -106,12 +106,12 @@ const installAsyncProxy = function(self){ w += m.wait; m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0; } - console.log(self.location.href, + sqlite3.config.log(self.location.href, "metrics for",self.location.href,":\n", metrics, "\nTotal of",n,"op(s) for",t,"ms", "approx",w,"ms spent waiting on OPFS APIs."); - console.log("Serialization metrics:",metrics.s11n); + sqlite3.config.log("Serialization metrics:",metrics.s11n); }; /** @@ -272,7 +272,7 @@ const installAsyncProxy = function(self){ || (e.cause.name==='DOMException' && 0===e.cause.message.indexOf('Access Handles cannot'))) ) ? ( - /*console.warn("SQLITE_BUSY",e),*/ + /*sqlite3.config.warn("SQLITE_BUSY",e),*/ state.sq3Codes.SQLITE_BUSY ) : rc; }else{ diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index 451f0019c2..3e3255b0c8 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -112,16 +112,16 @@ const installOpfsVfs = function callee(options){ options.proxyUri = callee.defaultProxyUri; } - //console.warn("OPFS options =",options,self.location); + //sqlite3.config.warn("OPFS options =",options,self.location); if('function' === typeof options.proxyUri){ options.proxyUri = options.proxyUri(); } const thePromise = new Promise(function(promiseResolve, promiseReject_){ const loggers = { - 0:console.error.bind(console), - 1:console.warn.bind(console), - 2:console.log.bind(console) + 0:sqlite3.config.error.bind(console), + 1:sqlite3.config.warn.bind(console), + 2:sqlite3.config.log.bind(console) }; const logImpl = (level,...args)=>{ if(options.verbose>level) loggers[level]("OPFS syncer:",...args); @@ -171,11 +171,11 @@ const installOpfsVfs = function callee(options){ m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0; m.avgWait = (m.count && m.wait) ? (m.wait / m.count) : 0; } - console.log(self.location.href, + sqlite3.config.log(self.location.href, "metrics for",self.location.href,":",metrics, "\nTotal of",n,"op(s) for",t, "ms (incl. "+w+" ms of waiting on the async side)"); - console.log("Serialization metrics:",metrics.s11n); + sqlite3.config.log("Serialization metrics:",metrics.s11n); W.postMessage({type:'opfs-async-metrics'}); }, reset: function(){ @@ -945,7 +945,7 @@ const installOpfsVfs = function callee(options){ await opfsUtil.getDirForFilename(absDirName+"/filepart", true); return true; }catch(e){ - //console.warn("mkdir(",absDirName,") failed:",e); + //sqlite3.config.warn("mkdir(",absDirName,") failed:",e); return false; } }; @@ -1317,13 +1317,13 @@ self.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{ if(sqlite3.scriptInfo.sqlite3Dir){ installOpfsVfs.defaultProxyUri = sqlite3.scriptInfo.sqlite3Dir + proxyJs; - //console.warn("installOpfsVfs.defaultProxyUri =",installOpfsVfs.defaultProxyUri); + //sqlite3.config.warn("installOpfsVfs.defaultProxyUri =",installOpfsVfs.defaultProxyUri); } return installOpfsVfs().catch((e)=>{ - console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e.message); + sqlite3.config.warn("Ignoring inability to install OPFS sqlite3_vfs:",e.message); }); }catch(e){ - console.error("installOpfsVfs() exception:",e); + sqlite3.config.error("installOpfsVfs() exception:",e); throw e; } }); diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 1689d34802..0f1ae39eac 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -246,9 +246,9 @@ self.sqlite3Worker1Promiser.defaultConfig = { const src = this.currentScript.src.split('/'); src.pop(); theJs = src.join('/')+'/' + theJs; - //console.warn("promiser currentScript, theJs =",this.currentScript,theJs); + //sqlite3.config.warn("promiser currentScript, theJs =",this.currentScript,theJs); }else{ - //console.warn("promiser self.location =",self.location); + //sqlite3.config.warn("promiser self.location =",self.location); const urlParams = new URL(self.location.href).searchParams; if(urlParams.has('sqlite3.dir')){ theJs = urlParams.get('sqlite3.dir') + '/' + theJs; diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 2cc0d9ad20..42d1167b60 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -2972,6 +2972,14 @@ self.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////////// log("Loading and initializing sqlite3 WASM module..."); + if(0){ + self.sqlite3ApiConfig = { + debug: ()=>{}, + log: ()=>{}, + warn: ()=>{}, + error: ()=>{} + } + } if(!self.sqlite3InitModule && !isUIThread()){ /* Vanilla worker, as opposed to an ES6 module worker */ /* @@ -3004,7 +3012,7 @@ self.sqlite3InitModule = sqlite3InitModule; }).then(function(sqlite3){ //console.log('sqlite3 =',sqlite3); log("Done initializing WASM/JS bits. Running tests..."); - console.warn("Installing sqlite3 bits as global S for local dev/test purposes."); + sqlite3.config.warn("Installing sqlite3 bits as global S for local dev/test purposes."); self.S = sqlite3; capi = sqlite3.capi; wasm = sqlite3.wasm; diff --git a/manifest b/manifest index 486d560b32..b15f43a7ca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sformatting\sproblem\sin\sscanstatus2.test\sintroduced\sby\s[81c118d9]. -D 2023-02-06T13:36:34.584 +C Add\scapability\sto\soverride\sthe\sJS's\suse\sof\sconsole.log/debug/warn/error()\swith\sclient-provided\sversions\svia\sthe\sbootstrap-time\sconfig\sobject. +D 2023-02-06T14:01:19.637 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -480,16 +480,16 @@ F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b F ext/wasm/api/pre-js.c-pp.js 9ece5de1bb0509f0a8a360712fcc9c1291b9516c0be5bd66acedd6edbcec37a1 F ext/wasm/api/sqlite3-api-cleanup.js 2d63eb84267a1d15ce002e083d6396a521471da8af3afa76846d50f39a54d65e F ext/wasm/api/sqlite3-api-glue.js 0a93e58aabf52b32ddccbb107a1fd4552f2505e103ab63396c4d0a0743704785 -F ext/wasm/api/sqlite3-api-oo1.js f85f4f939f67217d75898e3a32944dd8ae17f11c9a357e78a116150d038c0377 -F ext/wasm/api/sqlite3-api-prologue.js 69a74f2777aaafafc07ad2c922674fe3197ef63c921a3262b4772f937e7eb14a -F ext/wasm/api/sqlite3-api-worker1.js c462199c40358f00f93e326206bddc756c52b93f2cb60ffb63f54fe4f9a9e977 +F ext/wasm/api/sqlite3-api-oo1.js 9b50c188513c70438a497914089cfeac79b6ac2d73501775538f9e467325ea15 +F ext/wasm/api/sqlite3-api-prologue.js 5cc817b67a774bfa3c47d4c2fa484b10b24b5529a66094b35546f3ebba1ef646 +F ext/wasm/api/sqlite3-api-worker1.js 9551f04cdfcde354e5a6ccb48951e007d618abb4e95758297b7fd44ccffdf89f F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 -F ext/wasm/api/sqlite3-opfs-async-proxy.js 7795b84b66a7a8dedc791340709b310bb497c3c72a80bef364fa2a58e2ddae3f +F ext/wasm/api/sqlite3-opfs-async-proxy.js 2bc6b2b68198467ff467cea9657df7a9b06dcd50adb78efc8c7d893394eb3010 F ext/wasm/api/sqlite3-v-helper.js 6f6c3e390a72e08b0a5b16a0d567d7af3c04d172831853a29d72a6f1dd40ff24 -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js a10bdc9695dcf453e120970a5de8a3e61db4e4047d0a7cc5a6d63dfe7ae87f4e +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js ca291837840b3eae3a60810721a7970c98f7c7cd3ee1c879acb7e91f1e3fe65a F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasm.c 76625a70937a8522d014ef686c32db5b53a3ee61850323f5c601d2ac39fe52fe -F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js f10c3ecd9df06f6320073c2ce230a7ed7c56034d8b88c1e57095f2a97faf423a +F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js c5ac33e39f21a3481812d7333ca6e18853640d423a01960ca8dbc6e7c5c3c21c F ext/wasm/api/sqlite3-worker1.c-pp.js 77b3835192469e9da23926ec8f78fb0b114a51d048dc54388709ac22b5c5f0a0 F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8 F ext/wasm/batch-runner.js 0dad6a02ad796f1003d3b7048947d275c4d6277f63767b8e685c27df8fdac93e @@ -531,7 +531,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js f09266873e1a34d9bdb6d3981ec8c9e382f31f215c9fd2f9016d2394b8ae9b7b F ext/wasm/tester1-worker.html 258d08f1ba9cc2d455958751e26be833893cf9ff7853e9436e593e1f778a386b F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 9d6252f7b9427fb936f855adf8cf9458049a1d39d440c74601284e1262689f70 +F ext/wasm/tester1.c-pp.js 9844c675bd1f2353deabd7847d10c4fa55ff78a5c773073a239197d186123de7 F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2048,8 +2048,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 d83ce01fe1f21edcc93ad4c6308026156f235bab75e16e15389e27ad388fb274 -R 39a16d3a5e7cf4d84cd459cb5f0880dc -U dan -Z 1400c8ad726f4da65e248264077f8a2f +P 928ab40edbf11c02b3f03e660051d9587243002b9220adc77f972c3758c12b19 +R 357101b9f1585033ab92b7f4bae0fe2d +U stephan +Z c9099f0b2bd5b3ed497942d434424773 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 84522498e2..be35f35fc5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -928ab40edbf11c02b3f03e660051d9587243002b9220adc77f972c3758c12b19 \ No newline at end of file +c54f29d8e55419eaa9168e799dab5030e89063b13d8390a50616606422d164dc \ No newline at end of file