script_bindings/home/runner/work/servo/servo/target/debug/build/script_bindings-d55f55d5af1efaee/out/Bindings/
IterableIteratorBinding.rs

1/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */
2
3#![allow(non_camel_case_types,non_upper_case_globals,unsafe_op_in_unsafe_fn,unused_imports,unused_variables,unused_assignments,unused_mut,clippy::approx_constant,clippy::enum_variant_names,clippy::let_unit_value,clippy::needless_return,clippy::too_many_arguments,clippy::unnecessary_cast,clippy::upper_case_acronyms)]
4
5use crate::import::base::*;
6
7#[derive(JSTraceable)]
8#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
9pub struct IterableKeyOrValueResult {
10    pub done: bool,
11    pub value: RootedTraceableBox<Heap<JSVal>>,
12}
13impl Default for IterableKeyOrValueResult {
14    fn default() -> Self {
15        Self {
16                    done: Default::default(),
17        value: Default::default(),        }
18    }
19}
20
21impl IterableKeyOrValueResult {
22    pub fn empty() -> RootedTraceableBox<Self> {
23        let mut dictionary = RootedTraceableBox::new(Self::default());
24                dictionary.done = false;
25                dictionary.value = RootedTraceableBox::from_box(Heap::boxed(UndefinedValue()));
26        dictionary
27    }
28    pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
29                      -> Result<ConversionResult<RootedTraceableBox<IterableKeyOrValueResult>>, ()> {
30        unsafe {
31            let object = if val.get().is_null_or_undefined() {
32                ptr::null_mut()
33            } else if val.get().is_object() {
34                val.get().to_object()
35            } else {
36                return Ok(ConversionResult::Failure("Value is not an object.".into()));
37            };
38            rooted!(&in(cx) let object = object);
39        let dictionary = RootedTraceableBox::new(IterableKeyOrValueResult {
40                done: {
41                    rooted!(&in(cx) let mut rval = UndefinedValue());
42                    if get_dictionary_property(cx.raw_cx(), object.handle(), "done", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
43                            match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
44                                Ok(ConversionResult::Success(value)) => value,
45                                Ok(ConversionResult::Failure(error)) => {
46                                    throw_type_error(cx.raw_cx(), &error);
47                            return Err(());
48
49                                }
50                                _ => {
51                                    return Err(());
52
53                                },
54                            }
55
56                    } else {
57                            false
58                    }
59                },
60                value: {
61                    rooted!(&in(cx) let mut rval = UndefinedValue());
62                    if get_dictionary_property(cx.raw_cx(), object.handle(), "value", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
63                            RootedTraceableBox::from_box(Heap::boxed(rval.handle().get()))
64                    } else {
65                            RootedTraceableBox::from_box(Heap::boxed(UndefinedValue()))
66                    }
67                },
68        });
69            Ok(ConversionResult::Success(dictionary))
70        }
71    }
72}
73
74impl FromJSValConvertible for RootedTraceableBox<IterableKeyOrValueResult> {
75    type Config = ();
76    unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
77                         -> Result<ConversionResult<RootedTraceableBox<IterableKeyOrValueResult>>, ()> {
78        IterableKeyOrValueResult::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
79    }
80}
81
82impl IterableKeyOrValueResult {
83    #[allow(clippy::wrong_self_convention)]
84    pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
85        let done = &self.done;
86        rooted!(in(cx) let mut done_js = UndefinedValue());
87        done.to_jsval(cx, done_js.handle_mut());
88        set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "done", done_js.handle()).unwrap();
89        let value = &self.value;
90        rooted!(in(cx) let mut value_js = UndefinedValue());
91        value.to_jsval(cx, value_js.handle_mut());
92        set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "value", value_js.handle()).unwrap();
93    }
94}
95
96impl ToJSValConvertible for IterableKeyOrValueResult {
97    unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
98        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
99        self.to_jsobject(cx, obj.handle_mut());
100        rval.set(ObjectOrNullValue(obj.get()))
101    }
102}
103
104
105#[derive(JSTraceable)]
106#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
107pub struct IterableKeyAndValueResult {
108    pub done: bool,
109    pub value: Option<Vec<RootedTraceableBox<Heap<JSVal>>>>,
110}
111impl Default for IterableKeyAndValueResult {
112    fn default() -> Self {
113        Self {
114                    done: Default::default(),
115        value: Default::default(),        }
116    }
117}
118
119impl IterableKeyAndValueResult {
120    pub fn empty() -> RootedTraceableBox<Self> {
121        let mut dictionary = RootedTraceableBox::new(Self::default());
122                dictionary.done = false;
123                dictionary.value = None;
124        dictionary
125    }
126    pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
127                      -> Result<ConversionResult<RootedTraceableBox<IterableKeyAndValueResult>>, ()> {
128        unsafe {
129            let object = if val.get().is_null_or_undefined() {
130                ptr::null_mut()
131            } else if val.get().is_object() {
132                val.get().to_object()
133            } else {
134                return Ok(ConversionResult::Failure("Value is not an object.".into()));
135            };
136            rooted!(&in(cx) let object = object);
137        let dictionary = RootedTraceableBox::new(IterableKeyAndValueResult {
138                done: {
139                    rooted!(&in(cx) let mut rval = UndefinedValue());
140                    if get_dictionary_property(cx.raw_cx(), object.handle(), "done", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
141                            match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
142                                Ok(ConversionResult::Success(value)) => value,
143                                Ok(ConversionResult::Failure(error)) => {
144                                    throw_type_error(cx.raw_cx(), &error);
145                            return Err(());
146
147                                }
148                                _ => {
149                                    return Err(());
150
151                                },
152                            }
153
154                    } else {
155                            false
156                    }
157                },
158                value: {
159                    rooted!(&in(cx) let mut rval = UndefinedValue());
160                    if get_dictionary_property(cx.raw_cx(), object.handle(), "value", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
161                            Some(match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
162                                Ok(ConversionResult::Success(value)) => value,
163                                Ok(ConversionResult::Failure(error)) => {
164                                    throw_type_error(cx.raw_cx(), &error);
165                            return Err(());
166
167                                }
168                                _ => {
169                                    return Err(());
170
171                                },
172                            }
173                            )
174                    } else {
175                            None
176                    }
177                },
178        });
179            Ok(ConversionResult::Success(dictionary))
180        }
181    }
182}
183
184impl FromJSValConvertible for RootedTraceableBox<IterableKeyAndValueResult> {
185    type Config = ();
186    unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
187                         -> Result<ConversionResult<RootedTraceableBox<IterableKeyAndValueResult>>, ()> {
188        IterableKeyAndValueResult::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
189    }
190}
191
192impl IterableKeyAndValueResult {
193    #[allow(clippy::wrong_self_convention)]
194    pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
195        let done = &self.done;
196        rooted!(in(cx) let mut done_js = UndefinedValue());
197        done.to_jsval(cx, done_js.handle_mut());
198        set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "done", done_js.handle()).unwrap();
199        if let Some(ref value) = self.value {
200            rooted!(in(cx) let mut value_js = UndefinedValue());
201            value.to_jsval(cx, value_js.handle_mut());
202            set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "value", value_js.handle()).unwrap();
203        }
204    }
205}
206
207impl ToJSValConvertible for IterableKeyAndValueResult {
208    unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
209        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
210        self.to_jsobject(cx, obj.handle_mut());
211        rval.set(ObjectOrNullValue(obj.get()))
212    }
213}
214
215