Repository navigation
Conversation
When Emscripten's WASM memory grows (due to -sALLOW_MEMORY_GROWTH), all existing TypedArray views become detached because the underlying ArrayBuffer is replaced. This caused bugs where reading from views after FFI calls returned undefined values if memory had grown. The fix introduces RefreshableTypedArray, a wrapper that lazily recreates the TypedArray view when HEAPU8.buffer changes. This is a simple reference comparison that only triggers view recreation when actually needed. Affected call sites: - runtime.ts: executePendingJobs - reads ctxPtrOut after QTS_ExecutePendingJob - context.ts: newPromise - reads resolve/reject handles after QTS_NewPromiseCapability - context.ts: getLength - reads uint32Out after QTS_GetLength - context.ts: getOwnPropertyNames - reads outPtr and uint32Out after QTS_GetOwnPropertyNames Also fixed: getOwnPropertyNames was using HEAP8.buffer instead of HEAPU8.buffer Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- getArrayBuffer returned a HEAPU8.subarray view that is detached by the next WASM memory growth; return a copy instead. - consumeJSCharPointer / consumeHeapCharPointer leaked the C string when UTF8ToString threw (e.g. strings longer than V8's max string length). - newArrayBuffer leaked the host buffer (and returned an exception-tagged handle) when QuickJS failed to create the ArrayBuffer. It now frees the buffer and throws. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…reelist - ModuleMemory helpers now throw on a null _malloc instead of writing at address 0. - getOwnPropertyNames freed a plain-malloc'd array with js_free (QTS_FreeVoidPointer), unbalancing QuickJS allocation counters; free it with the module's free. - HostRefMap: FIFO freelist used Array#shift (quadratic when draining); use a head index. Deleting an already-deleted id in a non-empty group no longer queues it for reuse twice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Oct 16, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Layer: TypeScript wrapper (the
getOwnPropertyNamesfix relies onc/interface.callocating that array with plainmalloc; verified in the source and by test)Review just this PR: jackkav/quickjs-emscripten@fix-views-and-leaks...fix-oom-and-hostref
Stack: #248 → #276 → #277 → (#278 | #279 → #280 → #281 → #282). Issues: #274, #275.
What
ModuleMemoryhelpers throw on a null_mallocinstead of writing at address 0.getOwnPropertyNamesfrees its output array with the module's_free, notjs_free(which skewed QuickJS'smalloc_count).HostRefMap: dropArray#shift(quadratic drain), and a double delete in a non-empty group no longer queues the id twice.Test: Each fails without its fix: null malloc (stubbed
_malloc→ 0),malloc_countunchanged bygetOwnPropertyNames, double-delete id uniqueness. TheHostRefMapcompaction test is a regression guard for the new code and also passes on the old code.Verified on: All variants in the test matrix, TS-only so published 0.32.0 wasm is representative; the same tests also pass on freshly built wasm at the top of the stack (751 passed, 0 failed).
Behavior change: Null malloc now throws. Deleting an already-deleted
HostRefMapid in a non-empty group now throws (it used to corrupt the freelist).Overlap: #207 changes
computeMemoryUsage()to return a plain object; themalloc_counttest here reads it viavm.dump(handle)and would need a one-line change if #207 lands first.🤖 Generated with Claude Code