diff --git a/components/script/indexed_db.rs b/components/script/indexed_db.rs index e5cfd4459d3..d9538eb8548 100644 --- a/components/script/indexed_db.rs +++ b/components/script/indexed_db.rs @@ -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 diff --git a/components/shared/net/indexeddb_thread.rs b/components/shared/net/indexeddb_thread.rs index e6cd5d1c427..c943ea08199 100644 --- a/components/shared/net/indexeddb_thread.rs +++ b/components/shared/net/indexeddb_thread.rs @@ -22,8 +22,7 @@ pub enum IndexedDBKeyType { Number(f64), String(String), Binary(Vec), - // FIXME:(arihant2math) Date should not be stored as a Vec - Date(Vec), + Date(f64), Array(Vec), // FIXME:(arihant2math) implment ArrayBuffer } diff --git a/tests/wpt/meta/IndexedDB/idb-binary-key-roundtrip.any.js.ini b/tests/wpt/meta/IndexedDB/idb-binary-key-roundtrip.any.js.ini index 16cbe83f675..4b95c2e6c76 100644 --- a/tests/wpt/meta/IndexedDB/idb-binary-key-roundtrip.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idb-binary-key-roundtrip.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/idbcursor-key.any.js.ini b/tests/wpt/meta/IndexedDB/idbcursor-key.any.js.ini index 7691d259876..55628adf510 100644 --- a/tests/wpt/meta/IndexedDB/idbcursor-key.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbcursor-key.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini b/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini index 4c1a61f2c78..1a1d9fbb3f2 100644 --- a/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/idbobjectstore-clear-exception-order.any.js.ini b/tests/wpt/meta/IndexedDB/idbobjectstore-clear-exception-order.any.js.ini index 7ebf79cc115..6ca4c42f282 100644 --- a/tests/wpt/meta/IndexedDB/idbobjectstore-clear-exception-order.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbobjectstore-clear-exception-order.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/idbobjectstore-delete-exception-order.any.js.ini b/tests/wpt/meta/IndexedDB/idbobjectstore-delete-exception-order.any.js.ini index 225e000c38e..5c1d8cb24ed 100644 --- a/tests/wpt/meta/IndexedDB/idbobjectstore-delete-exception-order.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbobjectstore-delete-exception-order.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini b/tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini index 295212c734f..b6faf944099 100644 --- a/tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini +++ b/tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/key_invalid.any.js.ini b/tests/wpt/meta/IndexedDB/key_invalid.any.js.ini index 88b89ba9409..e5c55a9a7a6 100644 --- a/tests/wpt/meta/IndexedDB/key_invalid.any.js.ini +++ b/tests/wpt/meta/IndexedDB/key_invalid.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/keyorder.any.js.ini b/tests/wpt/meta/IndexedDB/keyorder.any.js.ini index 17a4dc15604..5bd3336e7aa 100644 --- a/tests/wpt/meta/IndexedDB/keyorder.any.js.ini +++ b/tests/wpt/meta/IndexedDB/keyorder.any.js.ini @@ -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 diff --git a/tests/wpt/meta/IndexedDB/value.any.js.ini b/tests/wpt/meta/IndexedDB/value.any.js.ini index f1f399a564c..e0a6cd0222b 100644 --- a/tests/wpt/meta/IndexedDB/value.any.js.ini +++ b/tests/wpt/meta/IndexedDB/value.any.js.ini @@ -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