diff --git a/components/script/dom/idbfactory.rs b/components/script/dom/idbfactory.rs index 66f7590e2da..da9d77c5320 100644 --- a/components/script/dom/idbfactory.rs +++ b/components/script/dom/idbfactory.rs @@ -1,17 +1,19 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - use dom_struct::dom_struct; +use js::rust::HandleValue; use servo_url::origin::ImmutableOrigin; use crate::dom::bindings::codegen::Bindings::IDBFactoryBinding::IDBFactoryMethods; use crate::dom::bindings::error::{Error, Fallible}; +use crate::dom::bindings::import::base::SafeJSContext; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::globalscope::GlobalScope; use crate::dom::idbopendbrequest::IDBOpenDBRequest; +use crate::indexed_db::convert_value_to_key; use crate::script_runtime::CanGc; #[dom_struct] @@ -89,9 +91,20 @@ impl IDBFactoryMethods for IDBFactory { // fn Databases(&self) -> Rc { // unimplemented!(); // } - // - // // https://www.w3.org/TR/IndexedDB-2/#dom-idbfactory-cmp - // fn Cmp(&self, _cx: SafeJSContext, _first: HandleValue, _second: HandleValue) -> i16 { - // unimplemented!(); - // } + + // https://www.w3.org/TR/IndexedDB-2/#dom-idbfactory-cmp + fn Cmp(&self, cx: SafeJSContext, first: HandleValue, second: HandleValue) -> Fallible { + let first_key = convert_value_to_key(cx, first, None)?; + let second_key = convert_value_to_key(cx, second, None)?; + let cmp = first_key.partial_cmp(&second_key); + if let Some(cmp) = cmp { + match cmp { + std::cmp::Ordering::Less => Ok(-1), + std::cmp::Ordering::Equal => Ok(0), + std::cmp::Ordering::Greater => Ok(1), + } + } else { + Ok(i16::MAX) + } + } } diff --git a/components/script_bindings/webidls/IDBFactory.webidl b/components/script_bindings/webidls/IDBFactory.webidl index 87ef2e2dd7e..da896831170 100644 --- a/components/script_bindings/webidls/IDBFactory.webidl +++ b/components/script_bindings/webidls/IDBFactory.webidl @@ -21,7 +21,7 @@ interface IDBFactory { // Promise> databases(); - // short cmp(any first, any second); + [Throws] short cmp(any first, any second); }; // https://w3c.github.io/IndexedDB/#dictdef-idbdatabaseinfo diff --git a/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini b/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini index cf00fe02880..4c1a61f2c78 100644 --- a/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini @@ -2,6 +2,7 @@ expected: ERROR [idbfactory_cmp.any.html] + expected: CRASH [IDBFactory.cmp() - compared keys return correct value] expected: FAIL @@ -37,6 +38,7 @@ [idbfactory_cmp.any.worker.html] + expected: CRASH [IDBFactory.cmp() - compared keys return correct value] expected: FAIL diff --git a/tests/wpt/meta/IndexedDB/idbobjectstore_delete.any.js.ini b/tests/wpt/meta/IndexedDB/idbobjectstore_delete.any.js.ini index d93927e870a..fe3aeaea9dd 100644 --- a/tests/wpt/meta/IndexedDB/idbobjectstore_delete.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idbobjectstore_delete.any.js.ini @@ -1,11 +1,45 @@ [idbobjectstore_delete.any.worker.html] - expected: CRASH + [delete() removes record (inline keys)] + expected: FAIL + + [delete() key doesn't match any records] + expected: FAIL + + [Object store's key path is an object attribute] + expected: FAIL + + [delete() removes record (out-of-line keys)] + expected: FAIL + + [delete() removes all of the records in the range] + expected: FAIL + + [If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError] + expected: FAIL + [idbobjectstore_delete.any.serviceworker.html] expected: ERROR [idbobjectstore_delete.any.html] - expected: CRASH + [delete() removes record (inline keys)] + expected: FAIL + + [delete() key doesn't match any records] + expected: FAIL + + [Object store's key path is an object attribute] + expected: FAIL + + [delete() removes record (out-of-line keys)] + expected: FAIL + + [delete() removes all of the records in the range] + expected: FAIL + + [If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError] + expected: FAIL + [idbobjectstore_delete.any.sharedworker.html] expected: ERROR diff --git a/tests/wpt/meta/IndexedDB/idlharness.any.js.ini b/tests/wpt/meta/IndexedDB/idlharness.any.js.ini index 36b51347cf2..fb0ab8d2c69 100644 --- a/tests/wpt/meta/IndexedDB/idlharness.any.js.ini +++ b/tests/wpt/meta/IndexedDB/idlharness.any.js.ini @@ -8,9 +8,6 @@ [IDBFactory interface: operation databases()] expected: FAIL - [IDBFactory interface: operation cmp(any, any)] - expected: FAIL - [IDBObjectStore interface: attribute keyPath] expected: FAIL @@ -226,9 +223,6 @@ [IDBFactory interface: operation databases()] expected: FAIL - [IDBFactory interface: operation cmp(any, any)] - expected: FAIL - [IDBObjectStore interface: attribute keyPath] 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 b6faf944099..295212c734f 100644 --- a/tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini +++ b/tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini @@ -2,6 +2,7 @@ expected: ERROR [key-conversion-exceptions.any.worker.html] + expected: CRASH [IDBFactory cmp() static with throwing/invalid keys] expected: FAIL @@ -19,6 +20,7 @@ [key-conversion-exceptions.any.html] + expected: CRASH [IDBFactory cmp() static with throwing/invalid keys] expected: FAIL diff --git a/tests/wpt/meta/IndexedDB/structured-clone.any.js.ini b/tests/wpt/meta/IndexedDB/structured-clone.any.js.ini index 3683d1c0be4..e3124e473d0 100644 --- a/tests/wpt/meta/IndexedDB/structured-clone.any.js.ini +++ b/tests/wpt/meta/IndexedDB/structured-clone.any.js.ini @@ -101,6 +101,27 @@ [Date: Sat Nov 20 2286 12:46:40 GMT-0500 (Eastern Standard Time)] expected: FAIL + [Date: Wed Dec 31 1969 15:59:59 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 16:00:01 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 16:16:40 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Mon Jan 12 1970 05:46:40 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Sat Sep 08 2001 18:46:40 GMT-0700 (Pacific Daylight Time)] + expected: FAIL + + [Date: Sat Nov 20 2286 09:46:40 GMT-0800 (Pacific Standard Time)] + expected: FAIL + [structured-clone.any.html?81-100] [Uint16Array: 0,1,65534,65535] @@ -385,6 +406,18 @@ [Date: Wed Dec 31 1969 18:43:20 GMT-0500 (Eastern Standard Time)] expected: FAIL + [Date: Sun Feb 09 1653 22:20:22 GMT-0752 (Pacific Standard Time)] + expected: FAIL + + [Date: Sun Apr 24 1938 14:13:20 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Sat Dec 20 1969 02:13:20 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 15:43:20 GMT-0800 (Pacific Standard Time)] + expected: FAIL + [structured-clone.any.worker.html?41-60] [Number: 0] @@ -471,6 +504,18 @@ [Date: Wed Dec 31 1969 18:43:20 GMT-0500 (Eastern Standard Time)] expected: FAIL + [Date: Sun Feb 09 1653 22:20:22 GMT-0752 (Pacific Standard Time)] + expected: FAIL + + [Date: Sun Apr 24 1938 14:13:20 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Sat Dec 20 1969 02:13:20 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 15:43:20 GMT-0800 (Pacific Standard Time)] + expected: FAIL + [structured-clone.any.html?61-80] [Date: Wed Dec 31 1969 23:59:59 GMT+0000 (Coordinated Universal Time)] @@ -575,6 +620,27 @@ [Date: Sat Nov 20 2286 12:46:40 GMT-0500 (Eastern Standard Time)] expected: FAIL + [Date: Wed Dec 31 1969 15:59:59 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 16:00:01 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Wed Dec 31 1969 16:16:40 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Mon Jan 12 1970 05:46:40 GMT-0800 (Pacific Standard Time)] + expected: FAIL + + [Date: Sat Sep 08 2001 18:46:40 GMT-0700 (Pacific Daylight Time)] + expected: FAIL + + [Date: Sat Nov 20 2286 09:46:40 GMT-0800 (Pacific Standard Time)] + expected: FAIL + [structured-clone.any.html?1-20] [undefined: undefined]