|
1 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public
|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
4 |
| - |
5 | 4 | use dom_struct::dom_struct;
|
| 5 | +use js::rust::HandleValue; |
6 | 6 | use servo_url::origin::ImmutableOrigin;
|
7 | 7 |
|
8 | 8 | use crate::dom::bindings::codegen::Bindings::IDBFactoryBinding::IDBFactoryMethods;
|
9 | 9 | use crate::dom::bindings::error::{Error, Fallible};
|
| 10 | +use crate::dom::bindings::import::base::SafeJSContext; |
10 | 11 | use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
|
11 | 12 | use crate::dom::bindings::root::DomRoot;
|
12 | 13 | use crate::dom::bindings::str::DOMString;
|
13 | 14 | use crate::dom::globalscope::GlobalScope;
|
14 | 15 | use crate::dom::idbopendbrequest::IDBOpenDBRequest;
|
| 16 | +use crate::indexed_db::convert_value_to_key; |
15 | 17 | use crate::script_runtime::CanGc;
|
16 | 18 |
|
17 | 19 | #[dom_struct]
|
@@ -89,9 +91,20 @@ impl IDBFactoryMethods<crate::DomTypeHolder> for IDBFactory {
|
89 | 91 | // fn Databases(&self) -> Rc<Promise> {
|
90 | 92 | // unimplemented!();
|
91 | 93 | // }
|
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 | + } |
97 | 110 | }
|
0 commit comments