1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */

#![allow(non_camel_case_types,non_upper_case_globals,unused_imports,unused_variables,unused_assignments,unused_mut,clippy::approx_constant,clippy::let_unit_value,clippy::needless_return,clippy::too_many_arguments,clippy::unnecessary_cast,clippy::upper_case_acronyms)]

use crate::dom::bindings::import::base::*;

#[derive(JSTraceable, Default)]
#[crown::unrooted_must_root_lint::must_root]
pub struct IterableKeyOrValueResult {
    pub done: bool,
    pub value: RootedTraceableBox<Heap<JSVal>>,
}
impl IterableKeyOrValueResult {
    pub fn empty() -> RootedTraceableBox<Self> {
        let mut dictionary = RootedTraceableBox::new(Self::default());
                dictionary.done = false;
                dictionary.value = RootedTraceableBox::from_box(Heap::boxed(UndefinedValue()));
        dictionary
    }
    pub fn new(cx: SafeJSContext, val: HandleValue)
                      -> Result<ConversionResult<RootedTraceableBox<IterableKeyOrValueResult>>, ()> {
        unsafe {
            let object = if val.get().is_null_or_undefined() {
                ptr::null_mut()
            } else if val.get().is_object() {
                val.get().to_object()
            } else {
                return Ok(ConversionResult::Failure("Value is not an object.".into()));
            };
            rooted!(in(*cx) let object = object);
        let dictionary = RootedTraceableBox::new(IterableKeyOrValueResult {
                done: {
                    rooted!(in(*cx) let mut rval = UndefinedValue());
                    if get_dictionary_property(*cx, object.handle(), "done", rval.handle_mut())? && !rval.is_undefined() {
                            match FromJSValConvertible::from_jsval(*cx, rval.handle(), ()) {
                                Ok(ConversionResult::Success(v)) => v,
                                Ok(ConversionResult::Failure(error)) => {
                                    throw_type_error(*cx, &error);
                                    return Err(());

                                }
                                _ => { return Err(());
                             }
                            }
                    } else {
                            false
                    }
                },
                value: {
                    rooted!(in(*cx) let mut rval = UndefinedValue());
                    if get_dictionary_property(*cx, object.handle(), "value", rval.handle_mut())? && !rval.is_undefined() {
                            RootedTraceableBox::from_box(Heap::boxed(rval.handle().get()))
                    } else {
                            RootedTraceableBox::from_box(Heap::boxed(UndefinedValue()))
                    }
                },
        });
            Ok(ConversionResult::Success(dictionary))
        }
    }
}

impl FromJSValConvertible for RootedTraceableBox<IterableKeyOrValueResult> {
    type Config = ();
    unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ())
                         -> Result<ConversionResult<RootedTraceableBox<IterableKeyOrValueResult>>, ()> {
        IterableKeyOrValueResult::new(SafeJSContext::from_ptr(cx), value)
    }
}

impl IterableKeyOrValueResult {
    pub(crate) unsafe fn to_jsobject(&self, cx: *mut JSContext, mut obj: MutableHandleObject) {
        let done = &self.done;
        rooted!(in(cx) let mut done_js = UndefinedValue());
        done.to_jsval(cx, done_js.handle_mut());
        set_dictionary_property(cx, obj.handle(), "done", done_js.handle()).unwrap();
        let value = &self.value;
        rooted!(in(cx) let mut value_js = UndefinedValue());
        value.to_jsval(cx, value_js.handle_mut());
        set_dictionary_property(cx, obj.handle(), "value", value_js.handle()).unwrap();
    }
}

impl ToJSValConvertible for IterableKeyOrValueResult {
    unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
        self.to_jsobject(cx, obj.handle_mut());
        rval.set(ObjectOrNullValue(obj.get()))
    }
}


#[derive(JSTraceable, Default)]
#[crown::unrooted_must_root_lint::must_root]
pub struct IterableKeyAndValueResult {
    pub done: bool,
    pub value: Option<Vec<RootedTraceableBox<Heap<JSVal>>>>,
}
impl IterableKeyAndValueResult {
    pub fn empty() -> RootedTraceableBox<Self> {
        let mut dictionary = RootedTraceableBox::new(Self::default());
                dictionary.done = false;
                dictionary.value = None;
        dictionary
    }
    pub fn new(cx: SafeJSContext, val: HandleValue)
                      -> Result<ConversionResult<RootedTraceableBox<IterableKeyAndValueResult>>, ()> {
        unsafe {
            let object = if val.get().is_null_or_undefined() {
                ptr::null_mut()
            } else if val.get().is_object() {
                val.get().to_object()
            } else {
                return Ok(ConversionResult::Failure("Value is not an object.".into()));
            };
            rooted!(in(*cx) let object = object);
        let dictionary = RootedTraceableBox::new(IterableKeyAndValueResult {
                done: {
                    rooted!(in(*cx) let mut rval = UndefinedValue());
                    if get_dictionary_property(*cx, object.handle(), "done", rval.handle_mut())? && !rval.is_undefined() {
                            match FromJSValConvertible::from_jsval(*cx, rval.handle(), ()) {
                                Ok(ConversionResult::Success(v)) => v,
                                Ok(ConversionResult::Failure(error)) => {
                                    throw_type_error(*cx, &error);
                                    return Err(());

                                }
                                _ => { return Err(());
                             }
                            }
                    } else {
                            false
                    }
                },
                value: {
                    rooted!(in(*cx) let mut rval = UndefinedValue());
                    if get_dictionary_property(*cx, object.handle(), "value", rval.handle_mut())? && !rval.is_undefined() {
                            Some(match FromJSValConvertible::from_jsval(*cx, rval.handle(), ()) {
                                Ok(ConversionResult::Success(value)) => value,
                                Ok(ConversionResult::Failure(error)) => {
                                    throw_type_error(*cx, &error);
                                    return Err(());

                                }
                                _ => { return Err(());
                             },
                            })
                    } else {
                            None
                    }
                },
        });
            Ok(ConversionResult::Success(dictionary))
        }
    }
}

impl FromJSValConvertible for RootedTraceableBox<IterableKeyAndValueResult> {
    type Config = ();
    unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, _option: ())
                         -> Result<ConversionResult<RootedTraceableBox<IterableKeyAndValueResult>>, ()> {
        IterableKeyAndValueResult::new(SafeJSContext::from_ptr(cx), value)
    }
}

impl IterableKeyAndValueResult {
    pub(crate) unsafe fn to_jsobject(&self, cx: *mut JSContext, mut obj: MutableHandleObject) {
        let done = &self.done;
        rooted!(in(cx) let mut done_js = UndefinedValue());
        done.to_jsval(cx, done_js.handle_mut());
        set_dictionary_property(cx, obj.handle(), "done", done_js.handle()).unwrap();
        if let Some(ref value) = self.value {
            rooted!(in(cx) let mut value_js = UndefinedValue());
            value.to_jsval(cx, value_js.handle_mut());
            set_dictionary_property(cx, obj.handle(), "value", value_js.handle()).unwrap();
        }
    }
}

impl ToJSValConvertible for IterableKeyAndValueResult {
    unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
        self.to_jsobject(cx, obj.handle_mut());
        rval.set(ObjectOrNullValue(obj.get()))
    }
}