Skip to content

Commit 14dec52

Browse files
committed
Add list() function to HandleAllocator for listing valid ids
Since it is possible to build such a list by manually iterating over the `allocated` array, I think it is better to provide a function that does just that. Accessing the `allocated` member from outside the class should be avoided as it is more an implementation detail than a part of the class interface.
1 parent 7195173 commit 14dec52

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/lib/libcore.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,15 @@ addToLibrary({
22642264
this.allocated[id] = undefined;
22652265
this.freelist.push(id);
22662266
}
2267+
list() {
2268+
var valid_ids = [];
2269+
for (var i = 1; i < this.allocated.length; i++) {
2270+
if (this.allocated[i] !== undefined) {
2271+
valid_ids.push(i);
2272+
}
2273+
}
2274+
return valid_ids;
2275+
}
22672276
},
22682277

22692278
$wasmTable__docs: '/** @type {WebAssembly.Table} */',

src/lib/libwebsocket.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,10 @@ var LibraryWebSocket = {
415415
#if WEBSOCKET_DEBUG
416416
dbg('emscripten_websocket_deinitialize()');
417417
#endif
418-
for (var i in webSockets.allocated) {
419-
if (webSockets.has(i)) {
420-
var socket = webSockets.get(i);
421-
socket.close();
422-
_emscripten_websocket_delete(i);
423-
}
418+
for (let id of webSockets.list()) {
419+
let socket = webSockets.get(id);
420+
socket.close();
421+
_emscripten_websocket_delete(id);
424422
}
425423
}
426424
}

0 commit comments

Comments
 (0)