Skip to content

Implement Upsert methods for weakMap: getOrInsert and getOrInsertComputed - #4459

Merged
jedel1043 merged 3 commits into
boa-dev:mainfrom
rrogerc:main
Oct 14, 2025
Merged

jedel1043 merged 3 commits into
boa-dev:mainfrom
rrogerc:main

Conversation

@rrogerc

@rrogerc rrogerc commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

This Pull Request closes #4435, implementing the Upsert proposal for weak map

It changes the following:

  • Adds WeakMap.prototype.getOrInsert method.
  • Adds WeakMap.prototype.getOrInsertComputed method.
  • Enforces object-only keys and callable callbacks.
  • Includes new tests for both methods to ensure correct behavior and reentrancy.

@codecov

codecov Bot commented Oct 7, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.55%. Comparing base (6ddc2b4) to head (9358a81).
⚠️ Report is 556 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4459      +/-   ##
==========================================
+ Coverage   47.24%   51.55%   +4.30%     
==========================================
  Files         476      504      +28     
  Lines       46892    51454    +4562     
==========================================
+ Hits        22154    26525    +4371     
- Misses      24738    24929     +191     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jedel1043 jedel1043 added A-Enhancement New feature or request C-Builtins PRs and Issues related to builtins/intrinsics hacktoberfest-accepted PR accepted for Hacktoberfest labels Oct 8, 2025

@jedel1043 jedel1043 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks nice! I just have a couple of suggestions to improve the code.

Comment thread core/engine/src/builtins/weak_map/mod.rs Outdated
Comment thread core/engine/src/builtins/weak_map/mod.rs
@jedel1043 jedel1043 added the Waiting On Author Waiting on PR changes from the author label Oct 8, 2025
@github-actions

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 50,595 50,595 0
Passed 47,620 47,635 +15
Ignored 2,056 2,056 0
Failed 919 904 -15
Panics 0 0 0
Conformance 94.12% 94.15% +0.03%
Fixed tests (15):
test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-object-key.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/length.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/adds-object-element.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/adds-value-different-callbackfn.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/callbackfn-throws.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/not-a-constructor.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/getOrInsertComputed.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/overwrites-mutation-from-callbackfn.js (previously Failed)
test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js (previously Failed)
test/built-ins/WeakMap/prototype/getOrInsert/getOrInsert.js (previously Failed)
test/built-ins/WeakMap/prototype/getOrInsert/returns-value-if-key-is-present-object-key.js (previously Failed)
test/built-ins/WeakMap/prototype/getOrInsert/length.js (previously Failed)
test/built-ins/WeakMap/prototype/getOrInsert/adds-object-element.js (previously Failed)
test/built-ins/WeakMap/prototype/getOrInsert/not-a-constructor.js (previously Failed)
test/built-ins/WeakMap/prototype/getOrInsert/returns-value-if-key-is-not-present-object-key.js (previously Failed)

@jedel1043 jedel1043 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, it looks great!

You may need to rebase the PR though, but we can merge after that.

- Enforce object keys; callable callback; reentrancy-safe insert/update.
- Register methods, update constructor metadata, and add tests.
@jedel1043
jedel1043 added this pull request to the merge queue Oct 14, 2025
Merged via the queue into boa-dev:main with commit d3c6e04 Oct 14, 2025
16 checks passed
@jedel1043 jedel1043 removed the Waiting On Author Waiting on PR changes from the author label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Enhancement New feature or request C-Builtins PRs and Issues related to builtins/intrinsics hacktoberfest-accepted PR accepted for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add getOrInsert and getOrInsertCallable to map & weak_map

2 participants