script/dom/
idbcursorwithvalue.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::rust::MutableHandleValue;
7use net_traits::indexeddb_thread::IndexedDBKeyRange;
8
9use crate::dom::bindings::codegen::Bindings::IDBCursorBinding::IDBCursorDirection;
10use crate::dom::bindings::codegen::Bindings::IDBCursorWithValueBinding::IDBCursorWithValueMethods;
11use crate::dom::bindings::reflector::reflect_dom_object;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::globalscope::GlobalScope;
14use crate::dom::idbcursor::{IDBCursor, ObjectStoreOrIndex};
15use crate::dom::idbtransaction::IDBTransaction;
16use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
17
18#[dom_struct]
19pub(crate) struct IDBCursorWithValue {
20    cursor: IDBCursor,
21}
22
23impl IDBCursorWithValue {
24    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
25    fn new_inherited(
26        transaction: &IDBTransaction,
27        direction: IDBCursorDirection,
28        got_value: bool,
29        source: ObjectStoreOrIndex,
30        range: IndexedDBKeyRange,
31        key_only: bool,
32    ) -> IDBCursorWithValue {
33        IDBCursorWithValue {
34            cursor: IDBCursor::new_inherited(
35                transaction,
36                direction,
37                got_value,
38                source,
39                range,
40                key_only,
41            ),
42        }
43    }
44
45    #[expect(unused)]
46    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
47    #[allow(clippy::too_many_arguments)]
48    pub(crate) fn new(
49        global: &GlobalScope,
50        transaction: &IDBTransaction,
51        direction: IDBCursorDirection,
52        got_value: bool,
53        source: ObjectStoreOrIndex,
54        range: IndexedDBKeyRange,
55        key_only: bool,
56        can_gc: CanGc,
57    ) -> DomRoot<IDBCursorWithValue> {
58        reflect_dom_object(
59            Box::new(IDBCursorWithValue::new_inherited(
60                transaction,
61                direction,
62                got_value,
63                source,
64                range,
65                key_only,
66            )),
67            global,
68            can_gc,
69        )
70    }
71}
72
73impl IDBCursorWithValueMethods<crate::DomTypeHolder> for IDBCursorWithValue {
74    /// <https://www.w3.org/TR/IndexedDB-2/#dom-idbcursorwithvalue-value>
75    fn Value(&self, _cx: SafeJSContext, value: MutableHandleValue) {
76        self.cursor.value(value);
77    }
78}