Add EM_JS() impl for kvstorageRead().

FossilOrigin-Name: 06610314fcf644f323c2f7ae11d7f4349b195e66d0ebbee590438dd99d97eb96
This commit is contained in:
stephan 2022-09-11 04:49:29 +00:00
parent d15822965b
commit e99f742a32
5 changed files with 55 additions and 13 deletions

View File

@ -193,8 +193,9 @@ emcc.jsflags += -sSTRICT_JS
emcc.jsflags += -sDYNAMIC_EXECUTION=0
emcc.jsflags += -sNO_POLYFILL
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
emcc.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory
emcc.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
# wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY
# allocateUTF8OnStack => for kvvp internals
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
emcc.jsflags += -sIMPORTED_MEMORY
emcc.environment := -sENVIRONMENT=web

View File

@ -651,7 +651,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
["sqlite3_vfs_find", "*", "string"],
["sqlite3_vfs_register", "int", "*", "int"],
["sqlite3_wasm_vfs_unlink", "int", "string"],
["sqlite3_wasm__emjs_test", undefined, "int"]
["sqlite3_wasm__emjs_test", "int", "int"]
]/*capi.wasm.bindingSignatures*/;
if(false && capi.wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){

View File

@ -604,26 +604,67 @@ EM_JS(int, kvstorageDelete,
return 0;
});
EM_JS(int, kvstorageRead,
(const char *zClass, const char *zKey, char *zBuf, int nBuf),{
const stack = stackSave();
try {
const zXKey = stackAlloc(_sqlite3_wasm__kvvfsMakeKey(0,0,0));
_sqlite3_wasm__kvvfsMakeKey(zClass, zKey, zXKey);
const jKey = UTF8ToString(zXKey);
const storage = (115/*=='s'*/===getValue(zClass))
? sessionStorage : localStorage;
const jV = storage.getItem(jKey);
if(!jV) return -1;
const nV = jV.length /* Note that we are relying 100% on v being
ASCII so that jV.length is equal to the
C-string's byte length. */;
if(nBuf<=0) return nV;
else if(1===nBuf){
setValue(zBuf, 0);
return nV;
}
const zV = allocateUTF8OnStack(jV);
if(nBuf > nV + 1) nBuf = nV + 1;
HEAPU8.copyWithin(zBuf, zV, zV + nBuf - 1);
setValue( zBuf + nBuf - 1, 0 );
return nBuf - 1;
}catch(e){
console.error("kvstorageRead()",e);
return -1;
}finally{
stackRestore(stack);
}
});
/*
** This function exists for (1) WASM testing purposes and (2) as a
** hook to get Emscripten to export several EM_JS()-generated
** functions. It is not part of the public API and its signature
** and semantics may change at any time.
*/
void sqlite3_wasm__emjs_test(int whichOp){
int sqlite3_wasm__emjs_test(int whichOp){
const char * zClass = "session";
const char * zKey = "hello";
int rc = 0;
switch( whichOp ){
case 1:
kvstorageWrite(zClass, zKey, "world");
break;
case 2:
case 2: {
char buffer[128] = {0};
char * zBuf = &buffer[0];
rc = kvstorageRead(zClass, zKey, zBuf, (int)sizeof(buffer));
printf("kvstorageRead()=%d %s\n", rc, zBuf);
break;
}
case 3:
kvstorageDelete(zClass, zKey);
break;
default:
//kvstorageMakeKeyJS(0,0,0) /* force Emscripten to include this */;
break;
}
return rc;
}
#endif /* ifdef __EMSCRIPTEN__ */

View File

@ -1,5 +1,5 @@
C Initial\sprototype\simpls\sof\swrite/delete-key\sops\sfor\sthe\spending\skvvfs\swhich\suse\ssessionStorage\sor\slocalStorage\sfor\sdb\spage\sstorage.\sread-key\sop\sis\spending.
D 2022-09-11T02:43:08.758
C Add\sEM_JS()\simpl\sfor\skvstorageRead().
D 2022-09-11T04:49:29.771
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -474,7 +474,7 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
F ext/wasm/EXPORTED_FUNCTIONS.fiddle db7a4602f043cf4a5e4135be3609a487f9f1c83f05778bfbdf93766be4541b96
F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle a004bd5eeeda6d3b28d16779b7f1a80305bfe009dfc7f0721b042967f0d39d02
F ext/wasm/GNUmakefile e8dcbf6de96196158bbc583d5a990f542a7ab33ad3858ca6563388d04d22d38b
F ext/wasm/GNUmakefile 18b80a063c684b0ca44b96221fc2c23647d0196f757c83c7a572b853562d8ac9
F ext/wasm/README.md e1ee1e7c321c6a250bf78a84ca6f5882890a237a450ba5a0649c7a8399194c52
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6396db6405ecfc4d25ebee8c1fab29d4522c852fcf9011df8bbcd54da00c14a
F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
@ -485,10 +485,10 @@ F ext/wasm/api/sqlite3-api-cleanup.js 1a12e64060c2cb0defd34656a76a9b1d7ed58459c2
F ext/wasm/api/sqlite3-api-glue.js 67ca83974410961953eeaa1dfed3518530d68381729ed1d27f95122f5baeabd3
F ext/wasm/api/sqlite3-api-oo1.js b06a1ac982c7d433396b8304550ce1493a63671a3bf653c3b5646a9075e0ca41
F ext/wasm/api/sqlite3-api-opfs.js 011799db398157cbd254264b6ebae00d7234b93d0e9e810345f213a5774993c0
F ext/wasm/api/sqlite3-api-prologue.js 3cd4343698a8f9a9b9d62486c06a03d220b88588a08666964f378ae858622b54
F ext/wasm/api/sqlite3-api-prologue.js 88e58145b0c71b00cd523b656016193d6ce8cf22c7ece8225838625f9187e6d1
F ext/wasm/api/sqlite3-api-worker1.js 73579555563b789785ae83724014eaf31811073aad9be6596c8336ffb51edd71
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
F ext/wasm/api/sqlite3-wasm.c c9a1cbe67b7684d41a4235aa3b05aba9a6389ff4d4adfc4e35d73b7f797142a3
F ext/wasm/api/sqlite3-wasm.c af771ebd94f4c75bb99823d84667a47ecee1425a05b73f13a7c7ff2b368e439d
F ext/wasm/batch-runner.html 23209ade7981acce7ecd79d6eff9f4c5a4e8b14ae867ac27cd89b230be640fa6
F ext/wasm/batch-runner.js a727cbbffe63fd17fb5a590dc679f0b13bd51880e8f84b461d7df246417689e8
F ext/wasm/common/SqliteTestUtil.js 529161a624265ba84271a52db58da022649832fa1c71309fb1e02cc037327a2b
@ -2019,8 +2019,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 757ad69607201a26802a304839b8454b1634712458539d6aa8cf999ab2447e59
R 97007ca8c1155bdfa1827179882900c6
P a4bd96f5348e607d0fcb627b751f9d86a188173a4b3bfb2c95f92913a78bd31e
R 310c3e2e3269e2d647346b038874eb9d
U stephan
Z 611b03bde2a6634a4d1d6b501abe44cc
Z 24c87f794d1a08fdf28cff48f949d74b
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
a4bd96f5348e607d0fcb627b751f9d86a188173a4b3bfb2c95f92913a78bd31e
06610314fcf644f323c2f7ae11d7f4349b195e66d0ebbee590438dd99d97eb96