script: Re-implement evaluate_key_path_on_value in IndexedDB#38847
script: Re-implement evaluate_key_path_on_value in IndexedDB#38847jdm merged 14 commits intoservo:mainfrom
Conversation
|
cc @arihant2math (Overlapped with #38835) |
|
🔨 Triggering try run (#17163441907) for Linux (WPT) |
|
Test results for linux-wpt from try job (#17163441907): Flaky unexpected result (17)
Stable unexpected results that are known to be intermittent (20)
Stable unexpected results (4)
|
|
|
|
🔨 Triggering try run (#17170731753) for Linux (WPT) |
|
Test results for linux-wpt from try job (#17170731753): Flaky unexpected result (25)
Stable unexpected results that are known to be intermittent (20)
|
|
✨ Try run (#17170731753) succeeded. |
| @@ -1,5 +1,5 @@ | |||
| [idb-binary-key-detached.any.html] | |||
| expected: TIMEOUT | |||
| expected: CRASH | |||
There was a problem hiding this comment.
Do we know why these tests crash now?
There was a problem hiding this comment.
This test panics when we call structuredclone::write here:
servo/components/script/indexed_db.rs
Lines 146 to 150 in 0089e65
which is used to handle this part of the spec:
If input is a buffer source type
- Let octets be the result of running the steps to get a copy of the bytes held by the buffer source input. Rethrow any exceptions.
- Return a new key with type binary and value octets.
My guess is that we didn't run the get-a-copy-of-the-bytes-held-by-the-buffer-source algorithm in the first step, which help us check whether the key is a detached buffer. The WPT test file has a spec URL (https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy) directly pointing to this algorithm.
This PR only eliminates crashes caused by the previously unimplemented part of evaluate_key_path_on_value. This explains why this PR can't fix this test.
There was a problem hiding this comment.
Yes, it would be better to use ? instead of expect. However, since this PR isn't related to convert_value_to_key function, I'd suggest fixing it in a separate PR.
There was a problem hiding this comment.
I've done this in #39078. The expectations should be updated when you get a chance.
…ure (#39078) Related to failures in #38847 Testing: WPT --------- Signed-off-by: Ashwin Naren <[email protected]>
05259e8 to
1199449
Compare
|
Rebased on the |
|
🔨 Triggering try run (#17394153815) for Linux (WPT) |
|
Test results for linux-wpt from try job (#17394153815): Flaky unexpected result (22)
Stable unexpected results that are known to be intermittent (27)
|
|
✨ Try run (#17394153815) succeeded. |
|
@kkoyung there seem to be merge conflicts at the moment. |
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
1199449 to
7716c7b
Compare
Rebased to resolve the conflict. |
jdm
left a comment
There was a problem hiding this comment.
Looking good; we just have a few areas where we can get closer to the specification!
components/script/indexed_db.rs
Outdated
| // Step 1.3.6. Assert: status is true. | ||
| unsafe { | ||
| set_dictionary_property(*cx, result.handle(), &i.to_string(), key.handle()) | ||
| .map_err(|_| Error::Data)?; |
There was a problem hiding this comment.
This should be Error::JSFailed, since it's a failure inside the JS engine.
components/script/indexed_db.rs
Outdated
| unsafe { | ||
| let mut is_array = false; | ||
| if IsArrayObject(*cx, current_value.handle(), &mut is_array) { | ||
| return Err(Error::Data); |
components/script/indexed_db.rs
Outdated
| } | ||
| } // All tokens processed | ||
| // Otherwise | ||
| else { |
There was a problem hiding this comment.
The current structure means that any checks like root_from_handlevalue:: or root_from_handlevalue:: that fail will silently return an undefined value, rather than falling through to this else block. Can we use explicit returns for the successful branches and make this else block unconditional instead?
There was a problem hiding this comment.
Since these if-then-else blocks are inside a for loop, I simply took away else to break up the if-then-else, and call continue when we find a matched one.
components/script/indexed_db.rs
Outdated
| unsafe { | ||
| // If Type(value) is not Object, return failure. | ||
| if !current_value.is_object() { | ||
| return Err(Error::Data); |
There was a problem hiding this comment.
From the spec:
The result of these steps is an ECMAScript value or failure, or the steps may throw an exception.
We need to create a result enum like:
enum EvaluationResult {
Success,
Failure,
Error(Error),
}and this case should be EvaluationResult::Failure.
There was a problem hiding this comment.
How about only including Success and Failure in the enum, and making the function return Result<EvaluationResult, Error> so that the caller can easily rethrow the error? It's also more close to the spec.
There was a problem hiding this comment.
I found that the other functions in components/script/indexeddb_db.rs have the same issue. Since this PR only touches evaluate_key_path_on_value and extract_key functions, I fixed these two functions for now. We can fix the others separately.
components/script/indexed_db.rs
Outdated
| // Let hop be ! HasOwnProperty(value, identifier). | ||
| // If hop is false, return failure. |
There was a problem hiding this comment.
We're missing the HasOwnProperty check like
servo/components/script/webdriver_handlers.rs
Line 298 in aac6aa6
components/script/indexed_db.rs
Outdated
| // Let hop be ! HasOwnProperty(value, identifier). | ||
| // If hop is false, return failure. | ||
| // Let value be ! Get(value, identifier). | ||
| // If value is undefined, return failure. |
components/script/indexed_db.rs
Outdated
| *cx, | ||
| object.handle(), | ||
| identifier, | ||
| property.handle_mut(), |
There was a problem hiding this comment.
We can pass current_value.handle_mut() here directly.
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
Signed-off-by: Kingsley Yung <[email protected]>
|
We call the I merged the main branch to here, to get the new function signature, and then fixed the type mismatch. |
|
🔨 Triggering try run (#17486230829) for Linux (WPT) |
|
Test results for linux-wpt from try job (#17486230829): Flaky unexpected result (24)
Stable unexpected results that are known to be intermittent (28)
|
|
✨ Try run (#17486230829) succeeded. |
The current implementation of evaluate_key_path_on_value was translated from gecko, and it is incomplete. The unimplemented part occurs many crashes in WPT tests.
This PR re-implements it according to the spec. It should eliminate many crashed WPT tests, and increase the code readability.
Testing: Update WPT test expectation
Fixes: #38817 partially, and #25325