mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
script: Update indexeddb serialization (#38269)
- Dates are now serialized as f64s (like how firefox does it) - Array buffers are serialized with structured cloning (this is not the most correct/efficent way to serialize them, however it is currently better than not supporting array buffers at all) - Array types are still unimplemented. Testing: WPT Fixes: Some panicking --------- Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
parent
165ede59cd
commit
3f1e170410
11 changed files with 276 additions and 86 deletions
|
@ -24,6 +24,7 @@ use crate::dom::bindings::import::module::SafeJSContext;
|
|||
use crate::dom::bindings::structuredclone;
|
||||
use crate::dom::idbobjectstore::KeyPath;
|
||||
|
||||
// https://www.w3.org/TR/IndexedDB-2/#convert-key-to-value
|
||||
#[allow(unsafe_code)]
|
||||
pub fn key_type_to_jsval(
|
||||
cx: SafeJSContext,
|
||||
|
@ -92,9 +93,11 @@ pub fn convert_value_to_key(
|
|||
// as it does not implement PartialEq
|
||||
|
||||
// Step 3
|
||||
// FIXME:(arihant2math) Accept buffer, array and date as well
|
||||
// FIXME:(arihant2math) Accept array as well
|
||||
if input.is_number() {
|
||||
// FIXME:(arihant2math) check for NaN
|
||||
if input.to_number().is_nan() {
|
||||
return Err(Error::Data);
|
||||
}
|
||||
return Ok(IndexedDBKeyType::Number(input.to_number()));
|
||||
}
|
||||
|
||||
|
@ -114,20 +117,26 @@ pub fn convert_value_to_key(
|
|||
}
|
||||
|
||||
if let ESClass::Date = built_in_class {
|
||||
// FIXME:(arihant2math) implement it the correct way
|
||||
let key = structuredclone::write(cx, input, None).expect("Could not serialize key");
|
||||
return Ok(IndexedDBKeyType::Date(key.serialized.clone()));
|
||||
let mut f = f64::NAN;
|
||||
if !js::jsapi::DateGetMsecSinceEpoch(*cx, object.handle().into(), &mut f) {
|
||||
return Err(Error::Data);
|
||||
}
|
||||
if f.is_nan() {
|
||||
return Err(Error::Data);
|
||||
}
|
||||
return Ok(IndexedDBKeyType::Date(f));
|
||||
}
|
||||
|
||||
if IsArrayBufferObject(*object) || JS_IsArrayBufferViewObject(*object) {
|
||||
// FIXME:(arihant2math)
|
||||
error!("Array buffers as keys is currently unsupported");
|
||||
return Err(Error::NotSupported);
|
||||
// FIXME:(arihant2math) implement it the correct way (is this correct?)
|
||||
let key = structuredclone::write(cx, input, None).expect("Could not serialize key");
|
||||
return Ok(IndexedDBKeyType::Binary(key.serialized.clone()));
|
||||
}
|
||||
|
||||
if let ESClass::Array = built_in_class {
|
||||
// FIXME:(arihant2math)
|
||||
unimplemented!("Arrays as keys is currently unsupported");
|
||||
error!("Arrays as keys is currently unsupported");
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +214,7 @@ pub fn evaluate_key_path_on_value(
|
|||
has_prop = true;
|
||||
} else {
|
||||
// If we get here it means the object doesn't have the property or the
|
||||
// property is available throuch a getter. We don't want to call any
|
||||
// property is available through a getter. We don't want to call any
|
||||
// getters to avoid potential re-entrancy.
|
||||
// The blob object is special since its properties are available
|
||||
// only through getters but we still want to support them for key
|
||||
|
|
|
@ -22,8 +22,7 @@ pub enum IndexedDBKeyType {
|
|||
Number(f64),
|
||||
String(String),
|
||||
Binary(Vec<u8>),
|
||||
// FIXME:(arihant2math) Date should not be stored as a Vec<u8>
|
||||
Date(Vec<u8>),
|
||||
Date(f64),
|
||||
Array(Vec<IndexedDBKeyType>),
|
||||
// FIXME:(arihant2math) implment ArrayBuffer
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[idb-binary-key-roundtrip.any.worker.html]
|
||||
expected: CRASH
|
||||
[Binary keys can be supplied using the view type Uint8Array]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -49,6 +50,7 @@
|
|||
|
||||
|
||||
[idb-binary-key-roundtrip.any.html]
|
||||
expected: CRASH
|
||||
[Binary keys can be supplied using the view type Uint8Array]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -2,10 +2,26 @@
|
|||
expected: ERROR
|
||||
|
||||
[idbcursor-key.any.worker.html]
|
||||
expected: CRASH
|
||||
[IDBCursor.key]
|
||||
expected: FAIL
|
||||
|
||||
[IDBCursor.key 1]
|
||||
expected: FAIL
|
||||
|
||||
[IDBCursor.key 2]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbcursor-key.any.html]
|
||||
expected: CRASH
|
||||
[IDBCursor.key]
|
||||
expected: FAIL
|
||||
|
||||
[IDBCursor.key 1]
|
||||
expected: FAIL
|
||||
|
||||
[IDBCursor.key 2]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbcursor-key.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
|
|
@ -2,76 +2,26 @@
|
|||
expected: ERROR
|
||||
|
||||
[idbfactory_cmp.any.html]
|
||||
expected: CRASH
|
||||
[IDBFactory.cmp() - compared keys return correct value]
|
||||
expected: FAIL
|
||||
|
||||
[IDBFactory.cmp() - null]
|
||||
expected: FAIL
|
||||
|
||||
[IDBFactory.cmp() - NaN]
|
||||
expected: FAIL
|
||||
|
||||
[Array vs. Binary]
|
||||
expected: FAIL
|
||||
|
||||
[Binary vs. String]
|
||||
expected: FAIL
|
||||
|
||||
[String vs. Date]
|
||||
expected: FAIL
|
||||
|
||||
[Date vs. Number]
|
||||
expected: FAIL
|
||||
|
||||
[Compare in unsigned octet values (in the range [0, 255\])]
|
||||
expected: FAIL
|
||||
|
||||
[Compare values of the same length]
|
||||
expected: FAIL
|
||||
|
||||
[Compare values of different lengths]
|
||||
expected: FAIL
|
||||
|
||||
[Compare when values in the range of their minimal length are the same]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbfactory_cmp.any.worker.html]
|
||||
expected: CRASH
|
||||
[IDBFactory.cmp() - compared keys return correct value]
|
||||
expected: FAIL
|
||||
|
||||
[IDBFactory.cmp() - null]
|
||||
expected: FAIL
|
||||
|
||||
[IDBFactory.cmp() - NaN]
|
||||
expected: FAIL
|
||||
|
||||
[Array vs. Binary]
|
||||
expected: FAIL
|
||||
|
||||
[Binary vs. String]
|
||||
expected: FAIL
|
||||
|
||||
[String vs. Date]
|
||||
expected: FAIL
|
||||
|
||||
[Date vs. Number]
|
||||
expected: FAIL
|
||||
|
||||
[Compare in unsigned octet values (in the range [0, 255\])]
|
||||
expected: FAIL
|
||||
|
||||
[Compare values of the same length]
|
||||
expected: FAIL
|
||||
|
||||
[Compare values of different lengths]
|
||||
expected: FAIL
|
||||
|
||||
[Compare when values in the range of their minimal length are the same]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbfactory_cmp.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
[idbobjectstore-clear-exception-order.any.worker.html]
|
||||
expected: CRASH
|
||||
expected: TIMEOUT
|
||||
[IDBObjectStore.clear exception order: InvalidStateError vs. TransactionInactiveError]
|
||||
expected: TIMEOUT
|
||||
|
||||
[IDBObjectStore.clear exception order: TransactionInactiveError vs. ReadOnlyError]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbobjectstore-clear-exception-order.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[idbobjectstore-clear-exception-order.any.html]
|
||||
expected: CRASH
|
||||
expected: TIMEOUT
|
||||
[IDBObjectStore.clear exception order: InvalidStateError vs. TransactionInactiveError]
|
||||
expected: TIMEOUT
|
||||
|
||||
[IDBObjectStore.clear exception order: TransactionInactiveError vs. ReadOnlyError]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbobjectstore-clear-exception-order.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
|
|
@ -2,10 +2,21 @@
|
|||
expected: ERROR
|
||||
|
||||
[idbobjectstore-delete-exception-order.any.html]
|
||||
expected: CRASH
|
||||
expected: TIMEOUT
|
||||
[IDBObjectStore.delete exception order: InvalidStateError vs. TransactionInactiveError]
|
||||
expected: TIMEOUT
|
||||
|
||||
[IDBObjectStore.delete exception order: TransactionInactiveError vs. ReadOnlyError]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idbobjectstore-delete-exception-order.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[idbobjectstore-delete-exception-order.any.worker.html]
|
||||
expected: CRASH
|
||||
expected: TIMEOUT
|
||||
[IDBObjectStore.delete exception order: InvalidStateError vs. TransactionInactiveError]
|
||||
expected: TIMEOUT
|
||||
|
||||
[IDBObjectStore.delete exception order: TransactionInactiveError vs. ReadOnlyError]
|
||||
expected: FAIL
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
expected: ERROR
|
||||
|
||||
[key-conversion-exceptions.any.worker.html]
|
||||
expected: CRASH
|
||||
[IDBFactory cmp() static with throwing/invalid keys]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -20,7 +19,6 @@
|
|||
|
||||
|
||||
[key-conversion-exceptions.any.html]
|
||||
expected: CRASH
|
||||
[IDBFactory cmp() static with throwing/invalid keys]
|
||||
expected: FAIL
|
||||
|
||||
|
|
67
tests/wpt/meta/IndexedDB/key_invalid.any.js.ini
vendored
67
tests/wpt/meta/IndexedDB/key_invalid.any.js.ini
vendored
|
@ -2,10 +2,73 @@
|
|||
expected: ERROR
|
||||
|
||||
[key_invalid.any.worker.html]
|
||||
expected: CRASH
|
||||
[Invalid key - [{}\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [[\], [\], [\], [[ Date \]\]\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [undefined\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [,1\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - sparse array]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - sparse array 2]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [[1\], [3\], [7\], [[ sparse array \]\]\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [1,2,3,,\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - array directly contains self]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - array indirectly contains self]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - array member contains self]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[key_invalid.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[key_invalid.any.html]
|
||||
expected: CRASH
|
||||
[Invalid key - [{}\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [[\], [\], [\], [[ Date \]\]\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [undefined\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [,1\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - sparse array]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - sparse array 2]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [[1\], [3\], [7\], [[ sparse array \]\]\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - [1,2,3,,\]]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - array directly contains self]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - array indirectly contains self]
|
||||
expected: FAIL
|
||||
|
||||
[Invalid key - array member contains self]
|
||||
expected: FAIL
|
||||
|
|
146
tests/wpt/meta/IndexedDB/keyorder.any.js.ini
vendored
146
tests/wpt/meta/IndexedDB/keyorder.any.js.ini
vendored
|
@ -2,10 +2,152 @@
|
|||
expected: ERROR
|
||||
|
||||
[keyorder.any.worker.html]
|
||||
expected: CRASH
|
||||
[Database readback sort - String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - float < String]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - float < String]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - float < Date]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - float < Date]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - float < Date < String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - float < Date < String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - -1.1 < 1 < 1.01337 < 1.013373 < 2]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - -1.1 < 1 < 1.01337 < 1.013373 < 2]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - -Infinity < -0.01 < 0 < Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - -Infinity < -0.01 < 0 < Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - "" < "a" < "ab" < "b" < "ba"]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - "" < "a" < "ab" < "b" < "ba"]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Arrays]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Arrays]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Array.length: 10,000 < Array.length: 10,001]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Array.length: 10,000 < Array.length: 10,001]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Infinity inside arrays]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Infinity inside arrays]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Test different stuff at once]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Test different stuff at once]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[keyorder.any.html]
|
||||
expected: CRASH
|
||||
[Database readback sort - String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - float < String]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - float < String]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - float < Date]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - float < Date]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - float < Date < String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - float < Date < String < Array]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - -1.1 < 1 < 1.01337 < 1.013373 < 2]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - -1.1 < 1 < 1.01337 < 1.013373 < 2]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - -Infinity < -0.01 < 0 < Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - -Infinity < -0.01 < 0 < Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - "" < "a" < "ab" < "b" < "ba"]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - "" < "a" < "ab" < "b" < "ba"]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Arrays]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Arrays]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Array.length: 10,000 < Array.length: 10,001]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Array.length: 10,000 < Array.length: 10,001]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Infinity inside arrays]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Infinity inside arrays]
|
||||
expected: FAIL
|
||||
|
||||
[Database readback sort - Test different stuff at once]
|
||||
expected: FAIL
|
||||
|
||||
[IDBKey.cmp sort - Test different stuff at once]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[keyorder.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
|
12
tests/wpt/meta/IndexedDB/value.any.js.ini
vendored
12
tests/wpt/meta/IndexedDB/value.any.js.ini
vendored
|
@ -1,11 +1,5 @@
|
|||
[value.any.html]
|
||||
expected: TIMEOUT
|
||||
[BigInts as keys in IndexedDB - primitive BigInt]
|
||||
expected: FAIL
|
||||
|
||||
[BigInts as keys in IndexedDB - BigInt object]
|
||||
expected: FAIL
|
||||
|
||||
[Values - Array]
|
||||
expected: TIMEOUT
|
||||
|
||||
|
@ -15,12 +9,6 @@
|
|||
|
||||
[value.any.worker.html]
|
||||
expected: TIMEOUT
|
||||
[BigInts as keys in IndexedDB - primitive BigInt]
|
||||
expected: FAIL
|
||||
|
||||
[BigInts as keys in IndexedDB - BigInt object]
|
||||
expected: FAIL
|
||||
|
||||
[Values - Array]
|
||||
expected: TIMEOUT
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue