Skip to content

Commit 4a3f93e

Browse files
authored
Fix idbstore.js with -sSTRICT + --closure (#23888)
Fixes: #23886
1 parent 741d0f9 commit 4a3f93e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/IDBStore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ var IDBStore = {
99
if (typeof indexedDB != 'undefined') return indexedDB;
1010
var ret = null;
1111
if (typeof window == 'object') ret = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
12+
#if ASSERTIONS
1213
assert(ret, 'IDBStore used, but indexedDB not supported');
14+
#endif
1315
return ret;
1416
},
1517
DB_VERSION: 22,

src/lib/libidbstore.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,44 @@ var LibraryIDBStore = {
112112
emscripten_idb_store__async: true,
113113
emscripten_idb_store: (db, id, ptr, num, perror) => Asyncify.handleSleep((wakeUp) => {
114114
IDBStore.setFile(UTF8ToString(db), UTF8ToString(id), new Uint8Array(HEAPU8.subarray(ptr, ptr+num)), (error) => {
115+
// Closure warns about storing booleans in TypedArrays.
116+
/** @suppress{checkTypes} */
115117
{{{ makeSetValue('perror', 0, '!!error', 'i32') }}};
116118
wakeUp();
117119
});
118120
}),
119121
emscripten_idb_delete__async: true,
120122
emscripten_idb_delete: (db, id, perror) => Asyncify.handleSleep((wakeUp) => {
121123
IDBStore.deleteFile(UTF8ToString(db), UTF8ToString(id), (error) => {
124+
/** @suppress{checkTypes} */
122125
{{{ makeSetValue('perror', 0, '!!error', 'i32') }}};
123126
wakeUp();
124127
});
125128
}),
126129
emscripten_idb_exists__async: true,
127130
emscripten_idb_exists: (db, id, pexists, perror) => Asyncify.handleSleep((wakeUp) => {
128131
IDBStore.existsFile(UTF8ToString(db), UTF8ToString(id), (error, exists) => {
132+
/** @suppress{checkTypes} */
129133
{{{ makeSetValue('pexists', 0, '!!exists', 'i32') }}};
134+
/** @suppress{checkTypes} */
130135
{{{ makeSetValue('perror', 0, '!!error', 'i32') }}};
131136
wakeUp();
132137
});
133138
}),
134139
emscripten_idb_clear__async: true,
135140
emscripten_idb_clear: (db, perror) => Asyncify.handleSleep((wakeUp) => {
136141
IDBStore.clearStore(UTF8ToString(db), (error) => {
142+
/** @suppress{checkTypes} */
137143
{{{ makeSetValue('perror', 0, '!!error', 'i32') }}};
138144
wakeUp();
139145
});
140146
}),
141147
// extra worker methods - proxied
142148
emscripten_idb_load_blob__async: true,
143149
emscripten_idb_load_blob: (db, id, pblob, perror) => Asyncify.handleSleep((wakeUp) => {
150+
#if ASSERTIONS
144151
assert(!IDBStore.pending);
152+
#endif
145153
IDBStore.pending = (msg) => {
146154
IDBStore.pending = null;
147155
var blob = msg.blob;
@@ -150,7 +158,9 @@ var LibraryIDBStore = {
150158
wakeUp();
151159
return;
152160
}
161+
#if ASSERTIONS
153162
assert(blob instanceof Blob);
163+
#endif
154164
var blobId = IDBStore.blobs.length;
155165
IDBStore.blobs.push(blob);
156166
{{{ makeSetValue('pblob', 0, 'blobId', 'i32') }}};
@@ -165,7 +175,9 @@ var LibraryIDBStore = {
165175
}),
166176
emscripten_idb_store_blob__async: true,
167177
emscripten_idb_store_blob: (db, id, ptr, num, perror) => Asyncify.handleSleep((wakeUp) => {
178+
#if ASSERTIONS
168179
assert(!IDBStore.pending);
180+
#endif
169181
IDBStore.pending = (msg) => {
170182
IDBStore.pending = null;
171183
{{{ makeSetValue('perror', 0, '!!msg.error', 'i32') }}};
@@ -188,7 +200,9 @@ var LibraryIDBStore = {
188200
return 0;
189201
},
190202
emscripten_idb_free_blob: (blobId) => {
203+
#if ASSERTIONS
191204
assert(IDBStore.blobs[blobId]);
205+
#endif
192206
IDBStore.blobs[blobId] = null;
193207
},
194208
#else

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ def test_idbstore_sync(self, asyncify):
14841484
if asyncify == 2:
14851485
self.require_jspi()
14861486
secret = str(time.time())
1487-
self.btest('test_idbstore_sync.c', '8', emcc_args=['-lidbstore.js', f'-DSECRET="{secret}"', '-O3', '-g2', f'-sASYNCIFY={asyncify}'])
1487+
self.btest('test_idbstore_sync.c', '8', emcc_args=['-sSTRICT', '-lidbstore.js', f'-DSECRET="{secret}"', '-O3', '--closure=1', f'-sASYNCIFY={asyncify}'])
14881488

14891489
def test_idbstore_sync_worker(self):
14901490
secret = str(time.time())

0 commit comments

Comments
 (0)