Implement AddToKeptObjects and add JS_ClearKeptObjects - #1606
Open
littledivy wants to merge 1 commit into
Open
Conversation
littledivy
force-pushed
the
add-clear-kept-objects
branch
4 times, most recently
from
July 26, 2026 04:37
1b2060f to
329255f
Compare
A WeakRef target must stay alive until the end of the current job
(AddToKeptObjects in the WeakRef constructor and in deref, cleared by
ClearKeptObjects when a job completes). Because quickjs reclaims by
reference counting, the violation is observable in plain JS:
let o = { x: 1 };
const w = new WeakRef(o);
o = null;
w.deref(); // undefined, spec says the object
Keep a list of retained targets on the runtime. JS_ExecutePendingJob
clears it on entry: the host calling it signals that the previous
script or job finished, and the usual drain loop's final call clears
the last job's set. Embedders that do not drain jobs can call the new
JS_ClearKeptObjects directly. V8 exposes the same operation as
v8::Isolate::ClearKeptObjects.
tests/bug652.js asserted the old behavior (it exists to check deref
does not throw); its expectation is updated.
littledivy
force-pushed
the
add-clear-kept-objects
branch
from
July 26, 2026 05:00
329255f to
027906d
Compare
Contributor
|
When is the public API used in general? |
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.
quickjs is missing AddToKeptObjects: a WeakRef target must survive until the end of the job. Refcounting makes it observable without gc:
Fix: the WeakRef constructor and
deref()hold a strong ref to the target on a runtime list.JS_ExecutePendingJobdrops the list on entry, so targets live exactly until the next job starts. Embedders that don't run jobs can drop it themselves with the newJS_ClearKeptObjects(ClearKeptObjects, same asv8::Isolate::ClearKeptObjects).Disclaimer: This is an AI-assisted patch from the v8x project.