-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
base: main
Are you sure you want to change the base?
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.15% 90.04% -0.12%
==========================================
Files 639 643 +4
Lines 188201 189311 +1110
Branches 36915 37139 +224
==========================================
+ Hits 169675 170463 +788
- Misses 11274 11506 +232
- Partials 7252 7342 +90
🚀 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
|
@jasnell I fixed all your comments in the last commit, can you take a look and rerun the CI? |
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
src/node_locks.cc
Outdated
Local<Promise> promise = callback_result.As<Promise>(); | ||
if (promise->Then(context, on_fulfilled_callback, on_rejected_callback) | ||
.IsEmpty()) { | ||
// Then() failed, reject both promises and return |
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.
If Then
returns an empty, then v8 will have already scheduled an error. You can probably use a v8::TryCatch
in here and reject the waiting_promise()
and released_promise()
with it's Exception()
, but you'd want to check CanContinue()
first.
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.
Done
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.
Just putting the red x on this since CI passed and it has sufficient sign off from others to land but there are still a few outstanding issues to resolve. I want to make sure it doesn't end up getting landed by the commit-queue while some comments are still pending.
// Called when the promise returned from the user's callback rejects | ||
static void OnIfAvailableReject(const FunctionCallbackInfo<Value>& info) { | ||
HandleScope handle_scope(info.GetIsolate()); | ||
auto* holder = static_cast<Global<Promise::Resolver>*>( |
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.
These's aren't correct here. You really should not be holding a v8::Global<T>
inside a v8::External
, then deleting it like this. It's fine to use indirection through another type... e.g. having the External
hold an instance of a struct that is holding the Global<T>
.
I still think there may be at least a few issues here relating to how you're using |
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