-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
src: add web locks api #58666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: add web locks api #58666
Conversation
Review requested:
|
370462f
to
ba53a01
Compare
ba53a01
to
5d52680
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58666 +/- ##
==========================================
- Coverage 90.09% 90.02% -0.07%
==========================================
Files 645 648 +3
Lines 189930 190815 +885
Branches 37217 37392 +175
==========================================
+ Hits 171125 171790 +665
- Misses 11512 11674 +162
- Partials 7293 7351 +58
🚀 New features to boost your workflow:
|
5d52680
to
6fdd577
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this lgtm. I looked through the WPT and other tests and they look all good. I reviewed the JS api to make sure it aligns with expectations and analyzed its source. All is good for a first implementation. I did a cursory review of the C++ part as I'm less experienced there, but in general it looks okay too. Nice work!
Adding
semver-major
|
4dcb027
to
83e7dc1
Compare
Commit Queue failed- Loading data for nodejs/node/pull/58666 ✔ Done loading data for nodejs/node/pull/58666 ----------------------------------- PR info ------------------------------------ Title src: add web locks api (#58666) Author Ilyas Shabi <[email protected]> (@IlyasShabi) Branch IlyasShabi:web-locks-api -> nodejs:main Labels semver-minor, lib / src, notable-change, needs-ci, commit-queue-squash, web-standards Commits 17 - worker: add web locks api - use WebIDL convertors - add lock and lockmanager to globals doc - remove lock and lockmanager from globals - attemp to atach catch on c++ by defering to next microtask - separate promise fulfillment and rejection handlers - add cjs/esm code in locks doc - add more tests and doc - update bootstrap modules - fix race condition in wpt and pr comments - mark held wpt test as flaky - better memory mngmt and error handling - fix linter - remove unnecessary external and global - fix js linter - use baseObject - fix jsdoc Committers 1 - ishabi <[email protected]> PR-URL: https://github.com/nodejs/node/pull/58666 Fixes: https://github.com/nodejs/node/pull/36502 Refs: https://w3c.github.io/web-locks Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/58666 Fixes: https://github.com/nodejs/node/pull/36502 Refs: https://w3c.github.io/web-locks Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 10 Jun 2025 19:40:42 GMT ✔ Approvals: 8 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/58666#pullrequestreview-2928334034 ✔ - Ethan Arrowood (@Ethan-Arrowood): https://github.com/nodejs/node/pull/58666#pullrequestreview-2932670431 ✔ - Filip Skokan (@panva) (TSC): https://github.com/nodejs/node/pull/58666#pullrequestreview-2935756262 ✔ - Marco Ippolito (@marco-ippolito) (TSC): https://github.com/nodejs/node/pull/58666#pullrequestreview-2962635799 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/58666#pullrequestreview-3033790815 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/58666#pullrequestreview-2952109057 ✔ - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/58666#pullrequestreview-2960196108 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/58666#pullrequestreview-3026973866 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-07-18T13:10:48Z: https://ci.nodejs.org/job/node-test-pull-request/68011/ - Querying data for job/node-test-pull-request/68011/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 58666 From https://github.com/nodejs/node * branch refs/pull/58666/merge -> FETCH_HEAD ✔ Fetched commits as 0629a175c0fa..214a58e6d7b8 -------------------------------------------------------------------------------- [main 5deb1f6bec] worker: add web locks api Author: ishabi <[email protected]> Date: Fri May 30 00:57:31 2025 +0200 70 files changed, 4611 insertions(+) create mode 100644 lib/internal/locks.js create mode 100644 src/node_locks.cc create mode 100644 src/node_locks.h create mode 100644 test/fixtures/wpt/interfaces/web-locks.idl create mode 100644 test/fixtures/wpt/web-locks/META.yml create mode 100644 test/fixtures/wpt/web-locks/README.md create mode 100644 test/fixtures/wpt/web-locks/WEB_FEATURES.yml create mode 100644 test/fixtures/wpt/web-locks/acquire.https.any.js create mode 100644 test/fixtures/wpt/web-locks/bfcache/abort.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/held.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/helpers.js create mode 100644 test/fixtures/wpt/web-locks/bfcache/release-across-thread.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/release.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/sharedworker-multiple.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/clientids.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/after-worker-termination.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/iframe-append-2.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/iframe-append.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/settle-after-steal.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/worker-termination.https.html create mode 100644 test/fixtures/wpt/web-locks/frames.https.html create mode 100644 test/fixtures/wpt/web-locks/held.https.any.js create mode 100644 test/fixtures/wpt/web-locks/idlharness.https.any.js create mode 100644 test/fixtures/wpt/web-locks/ifAvailable.https.any.js create mode 100644 test/fixtures/wpt/web-locks/lock-attributes.https.any.js create mode 100644 test/fixtures/wpt/web-locks/mode-exclusive.https.any.js create mode 100644 test/fixtures/wpt/web-locks/mode-mixed.https.any.js create mode 100644 test/fixtures/wpt/web-locks/mode-shared.https.any.js create mode 100644 test/fixtures/wpt/web-locks/non-fully-active.https.html create mode 100644 test/fixtures/wpt/web-locks/non-secure-context.any.js create mode 100644 test/fixtures/wpt/web-locks/opaque-origin.https.html create mode 100644 test/fixtures/wpt/web-locks/partitioned-web-locks.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/query-empty.https.any.js create mode 100644 test/fixtures/wpt/web-locks/query-ordering.https.html create mode 100644 test/fixtures/wpt/web-locks/query.https.any.js create mode 100644 test/fixtures/wpt/web-locks/resource-names.https.any.js create mode 100644 test/fixtures/wpt/web-locks/resources/helpers.js create mode 100644 test/fixtures/wpt/web-locks/resources/iframe-parent.html create mode 100644 test/fixtures/wpt/web-locks/resources/iframe.html create mode 100644 test/fixtures/wpt/web-locks/resources/parentworker.js create mode 100644 test/fixtures/wpt/web-locks/resources/partitioned-parent.html create mode 100644 test/fixtures/wpt/web-locks/resources/service-worker.js create mode 100644 test/fixtures/wpt/web-locks/resources/sw-controlled-iframe.html create mode 100644 test/fixtures/wpt/web-locks/resources/worker.js create mode 100644 test/fixtures/wpt/web-locks/secure-context.https.any.js create mode 100644 test/fixtures/wpt/web-locks/signal.https.any.js create mode 100644 test/fixtures/wpt/web-locks/steal.https.any.js create mode 100644 test/fixtures/wpt/web-locks/storage-buckets.tentative.https.any.js create mode 100644 test/fixtures/wpt/web-locks/workers.https.html create mode 100644 test/parallel/test-web-locks-query.js create mode 100644 test/parallel/test-web-locks.js create mode 100644 test/wpt/status/web-locks.json create mode 100644 test/wpt/test-web-locks.js create mode 100644 typings/internalBinding/locks.d.ts [main 62d5507b41] use WebIDL convertors Author: ishabi <[email protected]> Date: Wed Jun 11 21:10:41 2025 +0200 5 files changed, 212 insertions(+), 114 deletions(-) [main 0b4429422d] add lock and lockmanager to globals doc Author: ishabi <[email protected]> Date: Tue Jun 17 11:52:00 2025 +0200 1 file changed, 1 insertion(+) [main eadb345f96] remove lock and lockmanager from globals Author: ishabi <[email protected]> Date: Wed Jun 18 15:29:44 2025 +0200 3 files changed, 25 insertions(+), 4 deletions(-) [main d6c201a6ca] attemp to atach catch on c++ by defering to next microtask Author: ishabi <[email protected]> Date: Fri Jun 20 15:58:21 2025 +0200 1 file changed, 3 insertions(+), 1 deletion(-) [main c3d378b7f6] separate promise fulfillment and rejection handlers Author: ishabi <[email protected]> Date: Sat Jun 21 11:07:20 2025 +0200 3 files changed, 54 insertions(+), 38 deletions(-) [main 53528e74d9] add cjs/esm code in locks doc Author: ishabi <[email protected]> Date: Sun Jun 22 00:06:08 2025 +0200 1 file changed, 11 insertions(+), 1 deletion(-) [main 431cc7c24d] add more tests and doc Author: ishabi <[email protected]> Date: Sun Jun 22 20:31:50 2025 +0200 3 files changed, 63 insertions(+), 8 deletions(-) [main 4ab15d8719] update bootstrap modules Author: ishabi <[email protected]> Date: Mon Jun 23 17:59:46 2025 +0200 1 file changed, 2 insertions(+), 1 deletion(-) [main 16afe6d3ef] fix race condition in wpt and pr comments Author: ishabi <[email protected]> Date: Thu Jun 26 00:44:24 2025 +0200 1 file changed, 283 insertions(+), 120 deletions(-) [main 61a69288ac] mark held wpt test as flaky Author: ishabi <[email protected]> Date: Thu Jun 26 12:24:57 2025 +0200 3 files changed, 27 insertions(+), 36 deletions(-) [main b9c3601618] better memory mngmt and error handling Author: ishabi <[email protected]> Date: Sun Jun 29 21:38:07 2025 +0200 3 files changed, 112 insertions(+), 80 deletions(-) [main 8423174599] fix linter Author: ishabi <[email protected]> Date: Sun Jun 29 21:44:56 2025 +0200 1 file changed, 50 insertions(+), 36 deletions(-) [main eb60ba3cac] remove unnecessary external and global Author: ishabi <[email protected]> Date: Wed Jul 16 16:38:58 2025 +0200 1 file changed, 10 insertions(+), 35 deletions(-) [main 153e27db43] fix js linter Author: ishabi <[email protected]> Date: Wed Jul 16 16:51:28 2025 +0200 1 file changed, 1 insertion(+), 1 deletion(-) [main 4b7c781d09] use baseObject Author: ishabi <[email protected]> Date: Wed Jul 16 23:21:40 2025 +0200 3 files changed, 65 insertions(+), 25 deletions(-) [main 1acdfd57cb] fix jsdoc Author: ishabi <[email protected]> Date: Fri Jul 18 13:55:43 2025 +0200 1 file changed, 3 insertions(+), 3 deletions(-) ✔ Patches applied There are 17 commits in the PR. Attempting to fixup everything into first commit. [main 1304cbf740] worker: add web locks api Author: ishabi <[email protected]> Date: Fri May 30 00:57:31 2025 +0200 70 files changed, 5030 insertions(+) create mode 100644 lib/internal/locks.js create mode 100644 src/node_locks.cc create mode 100644 src/node_locks.h create mode 100644 test/fixtures/wpt/interfaces/web-locks.idl create mode 100644 test/fixtures/wpt/web-locks/META.yml create mode 100644 test/fixtures/wpt/web-locks/README.md create mode 100644 test/fixtures/wpt/web-locks/WEB_FEATURES.yml create mode 100644 test/fixtures/wpt/web-locks/acquire.https.any.js create mode 100644 test/fixtures/wpt/web-locks/bfcache/abort.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/held.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/helpers.js create mode 100644 test/fixtures/wpt/web-locks/bfcache/release-across-thread.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/release.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/bfcache/sharedworker-multiple.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/clientids.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/after-worker-termination.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/iframe-append-2.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/iframe-append.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/settle-after-steal.https.html create mode 100644 test/fixtures/wpt/web-locks/crashtests/worker-termination.https.html create mode 100644 test/fixtures/wpt/web-locks/frames.https.html create mode 100644 test/fixtures/wpt/web-locks/held.https.any.js create mode 100644 test/fixtures/wpt/web-locks/idlharness.https.any.js create mode 100644 test/fixtures/wpt/web-locks/ifAvailable.https.any.js create mode 100644 test/fixtures/wpt/web-locks/lock-attributes.https.any.js create mode 100644 test/fixtures/wpt/web-locks/mode-exclusive.https.any.js create mode 100644 test/fixtures/wpt/web-locks/mode-mixed.https.any.js create mode 100644 test/fixtures/wpt/web-locks/mode-shared.https.any.js create mode 100644 test/fixtures/wpt/web-locks/non-fully-active.https.html create mode 100644 test/fixtures/wpt/web-locks/non-secure-context.any.js create mode 100644 test/fixtures/wpt/web-locks/opaque-origin.https.html create mode 100644 test/fixtures/wpt/web-locks/partitioned-web-locks.tentative.https.html create mode 100644 test/fixtures/wpt/web-locks/query-empty.https.any.js create mode 100644 test/fixtures/wpt/web-locks/query-ordering.https.html create mode 100644 test/fixtures/wpt/web-locks/query.https.any.js create mode 100644 test/fixtures/wpt/web-locks/resource-names.https.any.js create mode 100644 test/fixtures/wpt/web-locks/resources/helpers.js create mode 100644 test/fixtures/wpt/web-locks/resources/iframe-parent.html create mode 100644 test/fixtures/wpt/web-locks/resources/iframe.html create mode 100644 test/fixtures/wpt/web-locks/resources/parentworker.js create mode 100644 test/fixtures/wpt/web-locks/resources/partitioned-parent.html create mode 100644 test/fixtures/wpt/web-locks/resources/service-worker.js create mode 100644 test/fixtures/wpt/web-locks/resources/sw-controlled-iframe.html create mode 100644 test/fixtures/wpt/web-locks/resources/worker.js create mode 100644 test/fixtures/wpt/web-locks/secure-context.https.any.js create mode 100644 test/fixtures/wpt/web-locks/signal.https.any.js create mode 100644 test/fixtures/wpt/web-locks/steal.https.any.js create mode 100644 test/fixtures/wpt/web-locks/storage-buckets.tentative.https.any.js create mode 100644 test/fixtures/wpt/web-locks/workers.https.html create mode 100644 test/parallel/test-web-locks-query.js create mode 100644 test/parallel/test-web-locks.js create mode 100644 test/wpt/status/web-locks.json create mode 100644 test/wpt/test-web-locks.js create mode 100644 typings/internalBinding/locks.d.ts --------------------------------- New Message ---------------------------------- worker: add web locks apihttps://github.com/nodejs/node/actions/runs/16373241092 |
PR-URL: #58666 Fixes: #36502 Refs: https://w3c.github.io/web-locks Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Landed in 062e8b5 |
This PR implements the Web Locks API, Locks are used to coordinate access to shared resources across multiple threads.
This implementation is based on previous work in #22719 and #36502, but takes a C++ native approach for better performance and reliability, this solution uses a singleton
LockManager
with thread-safe data structures to coordinate locks across all workers.exclusive
andshared
modessteal
optionifAvailable
optionsignal
optionquery.https.any.js
tests as unit testsCloses: #22702
Refs: https://w3c.github.io/web-locks