René's URL Explorer Experiment


Title: feat(runtime): weak collections key Java objects in canary mode by edusperoni · Pull Request #2128 · NativeScript/android · GitHub

Open Graph Title: feat(runtime): weak collections key Java objects in canary mode by edusperoni · Pull Request #2128 · NativeScript/android

X Title: feat(runtime): weak collections key Java objects in canary mode by edusperoni · Pull Request #2128 · NativeScript/android

Description: Description Fourth of the stacked wrapper-lifetime series (on #2127), the Android port of NativeScript/ios#563. With #2127 alone, a Java object's canary dies with its JS references while the Java object lives on. A later wrapper for the same object is a new JS object, so WeakMap/WeakSet entries, WeakRef targets and FinalizationRegistry registrations keyed on the old wrapper are lost with it. New behavior In canary mode a builtin (js/weak-collections.js, the iOS file with comments adapted, run from WeakRef.cpp) replaces the four globals with subclasses: A Java object whose wrapper is a canary is keyed by an opaque per-object key: frozen, null-prototype, created on first use by set/add/getOrInsert/register/new WeakRef. Lookups (get, has, delete, unregister) never create it, and neither does a call the standard collection rejects: set, add, getOrInsert and register check their receiver first (a call that cannot insert anything, whose TypeError names has, or unregister for a registry), register leaves an invalid target or token to the native method, and getOrInsertComputed runs its callback before making the key, so a callback that throws leaves none. The object's state holds the key, so it lives exactly until Java collects the object; the key does not keep the Java object alive. getOrInsert and getOrInsertComputed are keyed the same way; the computed callback receives the key it was given. WeakRef.prototype.deref (and the get alias) returns the live canary, a new one with the object's state (a rebuilt JS-extended instance, or a plain wrapper made the usual way and hydrated), or undefined once Java collected the object. Like a native target, what it returns stays alive until the job ends (the subclass keeps it alive only when wrap replaced what the native deref returned; the native method already keeps a target it returns as is). After __releaseNativeCounterpart a canary is a plain JS object, and what weak collections keyed on its Java object stays keyed on it: before the record goes, the key moves onto the canary and a private on the key leads back to it, so WeakMap/WeakSet entries, WeakRef.deref and FinalizationRegistry behave as for a plain object while the released wrapper lives, and the key and wrapper die together. A Proxy around a Java object is a key of its own, as in every other mode. register(target, target) still throws, checked on the original values; register.length is 2 and a call the native method rejects gets its error (register(1, 1) reports the invalid target). Values that are not canaries (including plain wrappers under "extended") pass through unchanged. Other modes keep V8's built-ins. The key and its reverse lookup are internal (ObjectManager::UnwrapForWeakCollection/WrapForWeakCollection, privates on the state and the key) and not exported, as on iOS. Both natives have the exception boundary other V8 callbacks have (C++ exceptions are rethrown to V8) and find no object manager, rather than throwing, when the isolate has no runtime. The builtin captures the native methods at startup through primordials (which gains WeakMap and its methods and Symbol.keyFor) instead of resolving them through super at call time. Trade-off: a WeakMap value that references its own Java key keeps the key, its state and so the Java object alive for as long as the map lives. In canary mode an operation pays at least one native call for each object key, target or token it is given (primitives pay none), and one that can create the key also pays the receiver check. deref builds a canary, which holds the Java object strongly until it dies again, so a WeakRef to a Java object dereferenced on every frame or event may keep it from ever being collected. A state made only to hold a weak-collection key counts in canaryStates and in getWrapperClassCounts()'s states, though no JS property was written. iOS #563 also moved NSArray's per-instance Symbol.iterator to the prototype, because under canary that own property was state on every array. Android installs no per-instance properties on wrappers, so there is nothing to port. Testing New testWrapperLifetimeWeakCollections.js, which holds in every mode: WeakMap, WeakSet and getOrInsert/getOrInsertComputed across a wrapper change of a Java-held object; WeakRef deref (and get) while the object lives, with its state; WeakRef cleared and FinalizationRegistry callback after Java collected the object; unregister through a later wrapper of its token; the register(target, target) rejection; a Proxy key; lookups that create no state; other keys unaffected; the builtin installed only in canary mode. Also: a WeakMap entry and WeakRef target for a Java-held plain object across a wrapper change; entries given to the WeakMap and WeakSet constructors and set through a user subclass of WeakMap; no FinalizationRegistry callback while Java holds the object and its wrapper is dead; what was keyed on a canary kept after __releaseNativeCounterpart while the wrapper lives; no key made by a rejected call; the computed callback's key; register's length and errors. Full suite on an arm64 emulator, measured on the top of the stack (#2130): 0 failures in each of resurrecting/extended (1834 specs), canary/extended and canary/all (1832 each). Summary by CodeRabbit New Features Weak collections and weak-reference APIs now support canary-wrapped Java objects across wrapper changes. This includes WeakMap, WeakSet, WeakRef, and FinalizationRegistry. Weak-collection lookups do not create keys; insertions create keys as needed. Ordinary JavaScript values retain their existing behavior. Documentation Clarified weak-collection behavior for canary-wrapped objects, including effects on object lifetime. Tests Added coverage for weak collections and weak-reference behavior across wrapper-lifetime modes, including collection and finalization behavior.

Open Graph Description: Description Fourth of the stacked wrapper-lifetime series (on #2127), the Android port of NativeScript/ios#563. With #2127 alone, a Java object's canary dies with its JS references while the Ja...

X Description: Description Fourth of the stacked wrapper-lifetime series (on #2127), the Android port of NativeScript/ios#563. With #2127 alone, a Java object's canary dies with its JS references while th...

Opengraph URL: https://github.com/NativeScript/android/pull/2128

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:052a9739-b975-ca67-7abb-9c84eded7919
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id90E8:63875:148FADE:1B32DC2:6B012729
html-safe-nonce3c238ba4d57323a3b5d8fa3653e93c3206863897d17ec8ab3ce97d63104c9d8d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MEU4OjYzODc1OjE0OEZBREU6MUIzMkRDMjo2QjAxMjcyOSIsInZpc2l0b3JfaWQiOiI2NTYwMjYxNjE0MjMzOTQ2MDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac1a8a9430a94e7237f594cc564c41890951bfe7a804fa0ddba2fe1e1ce21c684c
hovercard-subject-tagpull_request:5417413795
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2128/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altDescription Fourth of the stacked wrapper-lifetime series (on #2127), the Android port of NativeScript/ios#563. With #2127 alone, a Java object's canary dies with its JS references while the Ja...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/android/pull/2128/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2128%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2128%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://github.com/NativeScript/android/pull/2128/files
Reloadhttps://github.com/NativeScript/android/pull/2128/files
Reloadhttps://github.com/NativeScript/android/pull/2128/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests24 (24)https://github.com/NativeScript/android/pulls
Actionshttps://github.com/NativeScript/android/actions
Projectshttps://github.com/NativeScript/android/projects
Wikihttps://github.com/NativeScript/android/wiki
Security and qualityhttps://github.com/NativeScript/android/security
Insightshttps://github.com/NativeScript/android/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
feat/wrapper-lifetime-canaryhttps://github.com/NativeScript/android/tree/feat/wrapper-lifetime-canary
feat/wrapper-lifetime-weak-collectionshttps://github.com/NativeScript/android/tree/feat/wrapper-lifetime-weak-collections
Conversation 4 https://github.com/NativeScript/android/pull/2128
Commits 8 https://github.com/NativeScript/android/pull/2128/commits
Checks 8 https://github.com/NativeScript/android/pull/2128/checks
Files changed 9 https://github.com/NativeScript/android/pull/2128/files
feat(runtime): weak collections key Java objects in canary mode https://github.com/NativeScript/android/pull/2128/files#top
Show all changes 8 commits https://github.com/NativeScript/android/pull/2128/files
0636f80 feat(runtime): weak collections key Java objects in canary mode edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/0636f80c3aab200749d4492bc915c1d14dd42796
728f3a0 test(runtime): weak collections across a real wrapper change, plain o… edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/728f3a0c696e156d64cb920f8f8e6404d4e6b9d6
1762844 test(runtime): give the polling weak collection specs a timeout past … edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/1762844dcc6b499e0331b12cba4f4951d7aa22d1
afeb6b9 refactor(runtime): keep the canary members in their original order edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/afeb6b95c386c0439cd0ff7f2caf916ca1239728
ac066db fix(runtime): a released canary keeps what weak collections keyed on it edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/ac066db507e81018ef9395eaf3e67e7a7bbf58b8
6421b80 fix(runtime): weak collections validate before they make a key edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/6421b801c9b9c6f0d7b355ab66c52d812308f769
6ec6580 docs(runtime): weak collections: released canaries, polled WeakRefs, … edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/6ec65807d923e06f0e5381ef03e8fc17591c13da
53e0d18 test(runtime): weak collection specs for constructors, subclasses, re… edusperoni Nov 20, 2026 https://github.com/NativeScript/android/pull/2128/commits/53e0d18ed0fb23be0cd6e05f68d1b34245241026
Clear filters https://github.com/NativeScript/android/pull/2128/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2128/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2128/files
ns-builtin-modules.md https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
mainpage.js https://github.com/NativeScript/android/pull/2128/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
testWrapperLifetimeWeakCollections.js https://github.com/NativeScript/android/pull/2128/files#diff-063014966520b0a527d980bf62110efbecc5b92fe196bb686fa124db83ecb636
CMakeLists.txt https://github.com/NativeScript/android/pull/2128/files#diff-9aa48152a82c07a60ab6e09923a9b266e2985f78e579653848df730cd8ec5e4c
ObjectManager.cpp https://github.com/NativeScript/android/pull/2128/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
ObjectManager.h https://github.com/NativeScript/android/pull/2128/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
WeakRef.cpp https://github.com/NativeScript/android/pull/2128/files#diff-778041b0edab39527fa328e75b85bf1b2fd40a6799bdc070157272cefcb7bec0
primordials.js https://github.com/NativeScript/android/pull/2128/files#diff-9b1f22214698543a37f4ef99bb7a3c87aa30de65ecd042dd7b9eec18501914fc
weak-collections.js https://github.com/NativeScript/android/pull/2128/files#diff-ed86210d947c292d765d279ade11f4556ccf5d5b7457240c992aaef502682645
docs/ns-builtin-modules.mdhttps://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
View file https://github.com/NativeScript/android/blob/53e0d18ed0fb23be0cd6e05f68d1b34245241026/docs/ns-builtin-modules.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2128/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
https://github.com/NativeScript/android/pull/2128/files#diff-f49fa83084691682143a83515d6be04f599ea5d1cc41aa8e262d0daf53ebc63d
test-app/app/src/main/assets/app/mainpage.jshttps://github.com/NativeScript/android/pull/2128/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
View file https://github.com/NativeScript/android/blob/53e0d18ed0fb23be0cd6e05f68d1b34245241026/test-app/app/src/main/assets/app/mainpage.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2128/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2128/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
https://github.com/NativeScript/android/pull/2128/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
Please reload this pagehttps://github.com/NativeScript/android/pull/2128/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.