Fix JsRpcPromise::Resolved context checking. - #2143
Merged
Merged
Conversation
`IoContext::WeakRef` is a KJ I/O object, so `kj::Own<IoContext::WeakRef>` is not safe to hold from a JSG object. Instead, it would need to be `kj::IoOwn<IoContext::WeakRef>`. But, at that point we don't even need the `WeakRef` anymore because dereferencing the `IoOwn` itself will do exactly the check that we were using the `WeakRef` to do. Actually, all we really need here is an `IoPtr<T>` (the type of `T` is irrelevant) which we can attempt to dereference in order to effect the context check we want.
kentonv
force-pushed
the
kenton/fix-jsrpc-context-check
branch
from
May 20, 2024 22:35
6c324b2 to
6a4d54c
Compare
jasnell
approved these changes
May 20, 2024
jasnell
left a comment
Collaborator
There was a problem hiding this comment.
Oh nice.. I kind of expected it would be something along these lines.
| // Dummy IoPtr to self, used only to verify that we're running in the correct context. | ||
| // (Dereferencing from the wrong context would throw an exception.) | ||
| // Note: Can't use IoContext::WeakRef here because it's not thread-safe (it's only intended to | ||
| // be helf from KJ I/O objects, but this is a JSG object). |
Collaborator
There was a problem hiding this comment.
Suggested change
| // be helf from KJ I/O objects, but this is a JSG object). | |
| // be held from KJ I/O objects, but this is a JSG object). |
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.
IoContext::WeakRefis a KJ I/O object, sokj::Own<IoContext::WeakRef>is not safe to hold from a JSG object. Instead, it would need to bekj::IoOwn<IoContext::WeakRef>. But, at that point we don't even need theWeakRefanymore because dereferencing theIoOwnitself will do exactly the check that we were using theWeakRefto do.Actually, all we really need here is an
IoPtr<T>(the type ofTis irrelevant) which we can attempt to dereference in order to effect the context check we want.