Skip to content

Commit ab78a76

Browse files
authored
script: Implement IDBFactory.cmp (servo#38260)
Implements `IDBFactory.cmp`, most of the work was done by servo#38123. Testing: Covered by WPT (lots of flaky results: the appropriate tests are in tests/wpt/meta/IndexedDB/idlharness.any.js.ini) Fixes: None --------- Signed-off-by: Ashwin Naren <[email protected]>
1 parent 6cd8578 commit ab78a76

File tree

7 files changed

+126
-15
lines changed

7 files changed

+126
-15
lines changed

components/script/dom/idbfactory.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
54
use dom_struct::dom_struct;
5+
use js::rust::HandleValue;
66
use servo_url::origin::ImmutableOrigin;
77

88
use crate::dom::bindings::codegen::Bindings::IDBFactoryBinding::IDBFactoryMethods;
99
use crate::dom::bindings::error::{Error, Fallible};
10+
use crate::dom::bindings::import::base::SafeJSContext;
1011
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
1112
use crate::dom::bindings::root::DomRoot;
1213
use crate::dom::bindings::str::DOMString;
1314
use crate::dom::globalscope::GlobalScope;
1415
use crate::dom::idbopendbrequest::IDBOpenDBRequest;
16+
use crate::indexed_db::convert_value_to_key;
1517
use crate::script_runtime::CanGc;
1618

1719
#[dom_struct]
@@ -89,9 +91,20 @@ impl IDBFactoryMethods<crate::DomTypeHolder> for IDBFactory {
8991
// fn Databases(&self) -> Rc<Promise> {
9092
// unimplemented!();
9193
// }
92-
//
93-
// // https://www.w3.org/TR/IndexedDB-2/#dom-idbfactory-cmp
94-
// fn Cmp(&self, _cx: SafeJSContext, _first: HandleValue, _second: HandleValue) -> i16 {
95-
// unimplemented!();
96-
// }
94+
95+
// https://www.w3.org/TR/IndexedDB-2/#dom-idbfactory-cmp
96+
fn Cmp(&self, cx: SafeJSContext, first: HandleValue, second: HandleValue) -> Fallible<i16> {
97+
let first_key = convert_value_to_key(cx, first, None)?;
98+
let second_key = convert_value_to_key(cx, second, None)?;
99+
let cmp = first_key.partial_cmp(&second_key);
100+
if let Some(cmp) = cmp {
101+
match cmp {
102+
std::cmp::Ordering::Less => Ok(-1),
103+
std::cmp::Ordering::Equal => Ok(0),
104+
std::cmp::Ordering::Greater => Ok(1),
105+
}
106+
} else {
107+
Ok(i16::MAX)
108+
}
109+
}
97110
}

components/script_bindings/webidls/IDBFactory.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface IDBFactory {
2121

2222
// Promise<sequence<IDBDatabaseInfo>> databases();
2323

24-
// short cmp(any first, any second);
24+
[Throws] short cmp(any first, any second);
2525
};
2626

2727
// https://w3c.github.io/IndexedDB/#dictdef-idbdatabaseinfo

tests/wpt/meta/IndexedDB/idbfactory_cmp.any.js.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
expected: ERROR
33

44
[idbfactory_cmp.any.html]
5+
expected: CRASH
56
[IDBFactory.cmp() - compared keys return correct value]
67
expected: FAIL
78

@@ -37,6 +38,7 @@
3738

3839

3940
[idbfactory_cmp.any.worker.html]
41+
expected: CRASH
4042
[IDBFactory.cmp() - compared keys return correct value]
4143
expected: FAIL
4244

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
[idbobjectstore_delete.any.worker.html]
2-
expected: CRASH
2+
[delete() removes record (inline keys)]
3+
expected: FAIL
4+
5+
[delete() key doesn't match any records]
6+
expected: FAIL
7+
8+
[Object store's key path is an object attribute]
9+
expected: FAIL
10+
11+
[delete() removes record (out-of-line keys)]
12+
expected: FAIL
13+
14+
[delete() removes all of the records in the range]
15+
expected: FAIL
16+
17+
[If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError]
18+
expected: FAIL
19+
320

421
[idbobjectstore_delete.any.serviceworker.html]
522
expected: ERROR
623

724
[idbobjectstore_delete.any.html]
8-
expected: CRASH
25+
[delete() removes record (inline keys)]
26+
expected: FAIL
27+
28+
[delete() key doesn't match any records]
29+
expected: FAIL
30+
31+
[Object store's key path is an object attribute]
32+
expected: FAIL
33+
34+
[delete() removes record (out-of-line keys)]
35+
expected: FAIL
36+
37+
[delete() removes all of the records in the range]
38+
expected: FAIL
39+
40+
[If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError]
41+
expected: FAIL
42+
943

1044
[idbobjectstore_delete.any.sharedworker.html]
1145
expected: ERROR

tests/wpt/meta/IndexedDB/idlharness.any.js.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
[IDBFactory interface: operation databases()]
99
expected: FAIL
1010

11-
[IDBFactory interface: operation cmp(any, any)]
12-
expected: FAIL
13-
1411
[IDBObjectStore interface: attribute keyPath]
1512
expected: FAIL
1613

@@ -226,9 +223,6 @@
226223
[IDBFactory interface: operation databases()]
227224
expected: FAIL
228225

229-
[IDBFactory interface: operation cmp(any, any)]
230-
expected: FAIL
231-
232226
[IDBObjectStore interface: attribute keyPath]
233227
expected: FAIL
234228

tests/wpt/meta/IndexedDB/key-conversion-exceptions.any.js.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
expected: ERROR
33

44
[key-conversion-exceptions.any.worker.html]
5+
expected: CRASH
56
[IDBFactory cmp() static with throwing/invalid keys]
67
expected: FAIL
78

@@ -19,6 +20,7 @@
1920

2021

2122
[key-conversion-exceptions.any.html]
23+
expected: CRASH
2224
[IDBFactory cmp() static with throwing/invalid keys]
2325
expected: FAIL
2426

tests/wpt/meta/IndexedDB/structured-clone.any.js.ini

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@
101101
[Date: Sat Nov 20 2286 12:46:40 GMT-0500 (Eastern Standard Time)]
102102
expected: FAIL
103103

104+
[Date: Wed Dec 31 1969 15:59:59 GMT-0800 (Pacific Standard Time)]
105+
expected: FAIL
106+
107+
[Date: Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time)]
108+
expected: FAIL
109+
110+
[Date: Wed Dec 31 1969 16:00:01 GMT-0800 (Pacific Standard Time)]
111+
expected: FAIL
112+
113+
[Date: Wed Dec 31 1969 16:16:40 GMT-0800 (Pacific Standard Time)]
114+
expected: FAIL
115+
116+
[Date: Mon Jan 12 1970 05:46:40 GMT-0800 (Pacific Standard Time)]
117+
expected: FAIL
118+
119+
[Date: Sat Sep 08 2001 18:46:40 GMT-0700 (Pacific Daylight Time)]
120+
expected: FAIL
121+
122+
[Date: Sat Nov 20 2286 09:46:40 GMT-0800 (Pacific Standard Time)]
123+
expected: FAIL
124+
104125

105126
[structured-clone.any.html?81-100]
106127
[Uint16Array: 0,1,65534,65535]
@@ -385,6 +406,18 @@
385406
[Date: Wed Dec 31 1969 18:43:20 GMT-0500 (Eastern Standard Time)]
386407
expected: FAIL
387408

409+
[Date: Sun Feb 09 1653 22:20:22 GMT-0752 (Pacific Standard Time)]
410+
expected: FAIL
411+
412+
[Date: Sun Apr 24 1938 14:13:20 GMT-0800 (Pacific Standard Time)]
413+
expected: FAIL
414+
415+
[Date: Sat Dec 20 1969 02:13:20 GMT-0800 (Pacific Standard Time)]
416+
expected: FAIL
417+
418+
[Date: Wed Dec 31 1969 15:43:20 GMT-0800 (Pacific Standard Time)]
419+
expected: FAIL
420+
388421

389422
[structured-clone.any.worker.html?41-60]
390423
[Number: 0]
@@ -471,6 +504,18 @@
471504
[Date: Wed Dec 31 1969 18:43:20 GMT-0500 (Eastern Standard Time)]
472505
expected: FAIL
473506

507+
[Date: Sun Feb 09 1653 22:20:22 GMT-0752 (Pacific Standard Time)]
508+
expected: FAIL
509+
510+
[Date: Sun Apr 24 1938 14:13:20 GMT-0800 (Pacific Standard Time)]
511+
expected: FAIL
512+
513+
[Date: Sat Dec 20 1969 02:13:20 GMT-0800 (Pacific Standard Time)]
514+
expected: FAIL
515+
516+
[Date: Wed Dec 31 1969 15:43:20 GMT-0800 (Pacific Standard Time)]
517+
expected: FAIL
518+
474519

475520
[structured-clone.any.html?61-80]
476521
[Date: Wed Dec 31 1969 23:59:59 GMT+0000 (Coordinated Universal Time)]
@@ -575,6 +620,27 @@
575620
[Date: Sat Nov 20 2286 12:46:40 GMT-0500 (Eastern Standard Time)]
576621
expected: FAIL
577622

623+
[Date: Wed Dec 31 1969 15:59:59 GMT-0800 (Pacific Standard Time)]
624+
expected: FAIL
625+
626+
[Date: Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time)]
627+
expected: FAIL
628+
629+
[Date: Wed Dec 31 1969 16:00:01 GMT-0800 (Pacific Standard Time)]
630+
expected: FAIL
631+
632+
[Date: Wed Dec 31 1969 16:16:40 GMT-0800 (Pacific Standard Time)]
633+
expected: FAIL
634+
635+
[Date: Mon Jan 12 1970 05:46:40 GMT-0800 (Pacific Standard Time)]
636+
expected: FAIL
637+
638+
[Date: Sat Sep 08 2001 18:46:40 GMT-0700 (Pacific Daylight Time)]
639+
expected: FAIL
640+
641+
[Date: Sat Nov 20 2286 09:46:40 GMT-0800 (Pacific Standard Time)]
642+
expected: FAIL
643+
578644

579645
[structured-clone.any.html?1-20]
580646
[undefined: undefined]

0 commit comments

Comments
 (0)