script_bindings/home/runner/work/servo/servo/target/debug/build/script_bindings-d55f55d5af1efaee/out/Bindings/
BlobBinding.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::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
6use crate::codegen::GenericBindings::WorkerGlobalScopeBinding::WorkerGlobalScope_Binding;
7use crate::import::base::*;
8
9pub use self::GenericUnionTypes::ArrayBufferOrArrayBufferViewOrBlobOrString as BlobPart;
10
11#[derive(JSTraceable)]
12pub struct BlobPropertyBag {
13    pub type_: DOMString,
14}
15impl Default for BlobPropertyBag {
16    fn default() -> Self {
17        Self::empty()
18    }
19}
20
21impl BlobPropertyBag {
22    pub fn empty() -> Self {
23        Self {
24                type_: DOMString::from(""),
25        }
26    }
27    pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
28                      -> Result<ConversionResult<BlobPropertyBag>, ()> {
29        unsafe {
30            let object = if val.get().is_null_or_undefined() {
31                ptr::null_mut()
32            } else if val.get().is_object() {
33                val.get().to_object()
34            } else {
35                return Ok(ConversionResult::Failure("Value is not an object.".into()));
36            };
37            rooted!(&in(cx) let object = object);
38        let dictionary = BlobPropertyBag {
39                type_: {
40                    rooted!(&in(cx) let mut rval = UndefinedValue());
41                    if get_dictionary_property(cx.raw_cx(), object.handle(), "type", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
42                            match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), StringificationBehavior::Default) {
43                                Ok(ConversionResult::Success(value)) => value,
44                                Ok(ConversionResult::Failure(error)) => {
45                                    throw_type_error(cx.raw_cx(), &error);
46                            return Err(());
47
48                                }
49                                _ => {
50                                    return Err(());
51
52                                },
53                            }
54
55                    } else {
56                            DOMString::from("")
57                    }
58                },
59        };
60            Ok(ConversionResult::Success(dictionary))
61        }
62    }
63}
64
65impl FromJSValConvertible for BlobPropertyBag {
66    type Config = ();
67    unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
68                         -> Result<ConversionResult<BlobPropertyBag>, ()> {
69        BlobPropertyBag::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
70    }
71}
72
73impl BlobPropertyBag {
74    #[allow(clippy::wrong_self_convention)]
75    pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
76        let type_ = &self.type_;
77        rooted!(in(cx) let mut type__js = UndefinedValue());
78        type_.to_jsval(cx, type__js.handle_mut());
79        set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "type", type__js.handle()).unwrap();
80    }
81}
82
83impl ToJSValConvertible for BlobPropertyBag {
84    unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
85        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
86        self.to_jsobject(cx, obj.handle_mut());
87        rval.set(ObjectOrNullValue(obj.get()))
88    }
89}
90
91
92pub use self::Blob_Binding::{Wrap, BlobMethods, GetProtoObject, GetConstructorObject, DefineDOMInterface};
93pub mod Blob_Binding {
94use crate::codegen::GenericBindings::BlobBinding::BlobPropertyBag;
95use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
96use crate::codegen::GenericBindings::WorkerGlobalScopeBinding::WorkerGlobalScope_Binding;
97use crate::import::module::*;
98
99unsafe extern "C" fn get_size<D: DomTypes>
100(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
101    let mut result = false;
102    wrap_panic(&mut || result = (|| {
103        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
104        let this = &*(this as *const D::Blob);
105        let result: u64 = this.Size();
106
107        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
108        return true;
109    })());
110    result
111}
112
113
114static size_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
115
116pub(crate) fn init_size_getterinfo<D: DomTypes>() {
117    size_getterinfo.set(JSJitInfo {
118    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
119        getter: Some(get_size::<D>)
120    },
121    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
122        protoID: PrototypeList::ID::Blob as u16,
123    },
124    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
125    _bitfield_align_1: [],
126    _bitfield_1: __BindgenBitfieldUnit::new(
127        new_jsjitinfo_bitfield_1!(
128            JSJitInfo_OpType::Getter as u8,
129            JSJitInfo_AliasSet::AliasEverything as u8,
130            JSValueType::JSVAL_TYPE_DOUBLE as u8,
131            true,
132            false,
133            false,
134            false,
135            false,
136            false,
137            0,
138        ).to_ne_bytes()
139    ),
140});
141}
142unsafe extern "C" fn get_type<D: DomTypes>
143(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
144    let mut result = false;
145    wrap_panic(&mut || result = (|| {
146        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
147        let this = &*(this as *const D::Blob);
148        let result: DOMString = this.Type();
149
150        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
151        return true;
152    })());
153    result
154}
155
156
157static type_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
158
159pub(crate) fn init_type_getterinfo<D: DomTypes>() {
160    type_getterinfo.set(JSJitInfo {
161    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
162        getter: Some(get_type::<D>)
163    },
164    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
165        protoID: PrototypeList::ID::Blob as u16,
166    },
167    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
168    _bitfield_align_1: [],
169    _bitfield_1: __BindgenBitfieldUnit::new(
170        new_jsjitinfo_bitfield_1!(
171            JSJitInfo_OpType::Getter as u8,
172            JSJitInfo_AliasSet::AliasEverything as u8,
173            JSValueType::JSVAL_TYPE_STRING as u8,
174            true,
175            false,
176            false,
177            false,
178            false,
179            false,
180            0,
181        ).to_ne_bytes()
182    ),
183});
184}
185unsafe extern "C" fn slice<D: DomTypes>
186(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
187    let mut result = false;
188    wrap_panic(&mut || result = (|| {
189        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
190        let this = &*(this as *const D::Blob);
191        let args = &*args;
192        let argc = args.argc_;
193        let arg0: Option<i64> = if args.get(0).is_undefined() {
194            None
195        } else {
196            Some(match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), ConversionBehavior::Clamp) {
197                Ok(ConversionResult::Success(value)) => value,
198                Ok(ConversionResult::Failure(error)) => {
199                    throw_type_error(cx.raw_cx(), &error);
200            return false;
201
202                }
203                _ => {
204                    return false;
205
206                },
207            }
208            )
209        };
210        let arg1: Option<i64> = if args.get(1).is_undefined() {
211            None
212        } else {
213            Some(match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ConversionBehavior::Clamp) {
214                Ok(ConversionResult::Success(value)) => value,
215                Ok(ConversionResult::Failure(error)) => {
216                    throw_type_error(cx.raw_cx(), &error);
217            return false;
218
219                }
220                _ => {
221                    return false;
222
223                },
224            }
225            )
226        };
227        let arg2: Option<DOMString> = if args.get(2).is_undefined() {
228            None
229        } else {
230            Some(match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(2)), StringificationBehavior::Default) {
231                Ok(ConversionResult::Success(value)) => value,
232                Ok(ConversionResult::Failure(error)) => {
233                    throw_type_error(cx.raw_cx(), &error);
234            return false;
235
236                }
237                _ => {
238                    return false;
239
240                },
241            }
242            )
243        };
244        let result: DomRoot<D::Blob> = this.Slice(arg0, arg1, arg2, CanGc::note());
245
246        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
247        return true;
248    })());
249    result
250}
251
252
253static slice_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
254
255pub(crate) fn init_slice_methodinfo<D: DomTypes>() {
256    slice_methodinfo.set(JSJitInfo {
257    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
258        method: Some(slice::<D>)
259    },
260    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
261        protoID: PrototypeList::ID::Blob as u16,
262    },
263    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
264    _bitfield_align_1: [],
265    _bitfield_1: __BindgenBitfieldUnit::new(
266        new_jsjitinfo_bitfield_1!(
267            JSJitInfo_OpType::Method as u8,
268            JSJitInfo_AliasSet::AliasEverything as u8,
269            JSValueType::JSVAL_TYPE_OBJECT as u8,
270            false,
271            false,
272            false,
273            false,
274            false,
275            false,
276            0,
277        ).to_ne_bytes()
278    ),
279});
280}
281unsafe extern "C" fn stream<D: DomTypes>
282(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
283    let mut result = false;
284    wrap_panic(&mut || result = (|| {
285        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
286        let this = &*(this as *const D::Blob);
287        let args = &*args;
288        let argc = args.argc_;
289        let result: Result<DomRoot<D::ReadableStream>, Error> = this.Stream(CanGc::note());
290        let result = match result {
291            Ok(result) => result,
292            Err(e) => {
293                <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), &this.global_(InRealm::already(&AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx.raw_cx())))), e, CanGc::note());
294                return false;
295            },
296        };
297
298        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
299        return true;
300    })());
301    result
302}
303
304
305static stream_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
306
307pub(crate) fn init_stream_methodinfo<D: DomTypes>() {
308    stream_methodinfo.set(JSJitInfo {
309    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
310        method: Some(stream::<D>)
311    },
312    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
313        protoID: PrototypeList::ID::Blob as u16,
314    },
315    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
316    _bitfield_align_1: [],
317    _bitfield_1: __BindgenBitfieldUnit::new(
318        new_jsjitinfo_bitfield_1!(
319            JSJitInfo_OpType::Method as u8,
320            JSJitInfo_AliasSet::AliasEverything as u8,
321            JSValueType::JSVAL_TYPE_OBJECT as u8,
322            false,
323            false,
324            false,
325            false,
326            false,
327            false,
328            0,
329        ).to_ne_bytes()
330    ),
331});
332}
333unsafe extern "C" fn text<D: DomTypes>
334(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
335    let mut result = false;
336    wrap_panic(&mut || result = (|| {
337        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
338        let this = &*(this as *const D::Blob);
339        let args = &*args;
340        let argc = args.argc_;
341        let result: Rc<D::Promise> = this.Text(CanGc::note());
342
343        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
344        return true;
345    })());
346    result
347}
348
349unsafe extern "C" fn text_promise_wrapper<D: DomTypes>
350(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
351    let mut result = false;
352    wrap_panic(&mut || result = (|| {
353        let ok = text::<D>(cx, _obj, this, args);
354        if ok {
355          return true;
356        }
357        return exception_to_promise(cx, (*args).rval(), CanGc::note());
358
359    })());
360    result
361}
362
363
364static text_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
365
366pub(crate) fn init_text_methodinfo<D: DomTypes>() {
367    text_methodinfo.set(JSJitInfo {
368    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
369        method: Some(text_promise_wrapper::<D>)
370    },
371    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
372        protoID: PrototypeList::ID::Blob as u16,
373    },
374    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
375    _bitfield_align_1: [],
376    _bitfield_1: __BindgenBitfieldUnit::new(
377        new_jsjitinfo_bitfield_1!(
378            JSJitInfo_OpType::Method as u8,
379            JSJitInfo_AliasSet::AliasEverything as u8,
380            JSValueType::JSVAL_TYPE_OBJECT as u8,
381            true,
382            false,
383            false,
384            false,
385            false,
386            false,
387            0,
388        ).to_ne_bytes()
389    ),
390});
391}
392unsafe extern "C" fn arrayBuffer<D: DomTypes>
393(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
394    let mut result = false;
395    wrap_panic(&mut || result = (|| {
396        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
397        let this = &*(this as *const D::Blob);
398        let args = &*args;
399        let argc = args.argc_;
400        let result: Rc<D::Promise> = this.ArrayBuffer(InRealm::already(&AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx.raw_cx()))), CanGc::note());
401
402        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
403        return true;
404    })());
405    result
406}
407
408unsafe extern "C" fn arrayBuffer_promise_wrapper<D: DomTypes>
409(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
410    let mut result = false;
411    wrap_panic(&mut || result = (|| {
412        let ok = arrayBuffer::<D>(cx, _obj, this, args);
413        if ok {
414          return true;
415        }
416        return exception_to_promise(cx, (*args).rval(), CanGc::note());
417
418    })());
419    result
420}
421
422
423static arrayBuffer_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
424
425pub(crate) fn init_arrayBuffer_methodinfo<D: DomTypes>() {
426    arrayBuffer_methodinfo.set(JSJitInfo {
427    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
428        method: Some(arrayBuffer_promise_wrapper::<D>)
429    },
430    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
431        protoID: PrototypeList::ID::Blob as u16,
432    },
433    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
434    _bitfield_align_1: [],
435    _bitfield_1: __BindgenBitfieldUnit::new(
436        new_jsjitinfo_bitfield_1!(
437            JSJitInfo_OpType::Method as u8,
438            JSJitInfo_AliasSet::AliasEverything as u8,
439            JSValueType::JSVAL_TYPE_OBJECT as u8,
440            true,
441            false,
442            false,
443            false,
444            false,
445            false,
446            0,
447        ).to_ne_bytes()
448    ),
449});
450}
451unsafe extern "C" fn bytes<D: DomTypes>
452(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
453    let mut result = false;
454    wrap_panic(&mut || result = (|| {
455        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
456        let this = &*(this as *const D::Blob);
457        let args = &*args;
458        let argc = args.argc_;
459        let result: Rc<D::Promise> = this.Bytes(InRealm::already(&AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx.raw_cx()))), CanGc::note());
460
461        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
462        return true;
463    })());
464    result
465}
466
467unsafe extern "C" fn bytes_promise_wrapper<D: DomTypes>
468(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
469    let mut result = false;
470    wrap_panic(&mut || result = (|| {
471        let ok = bytes::<D>(cx, _obj, this, args);
472        if ok {
473          return true;
474        }
475        return exception_to_promise(cx, (*args).rval(), CanGc::note());
476
477    })());
478    result
479}
480
481
482static bytes_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
483
484pub(crate) fn init_bytes_methodinfo<D: DomTypes>() {
485    bytes_methodinfo.set(JSJitInfo {
486    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
487        method: Some(bytes_promise_wrapper::<D>)
488    },
489    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
490        protoID: PrototypeList::ID::Blob as u16,
491    },
492    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
493    _bitfield_align_1: [],
494    _bitfield_1: __BindgenBitfieldUnit::new(
495        new_jsjitinfo_bitfield_1!(
496            JSJitInfo_OpType::Method as u8,
497            JSJitInfo_AliasSet::AliasEverything as u8,
498            JSValueType::JSVAL_TYPE_OBJECT as u8,
499            true,
500            false,
501            false,
502            false,
503            false,
504            false,
505            0,
506        ).to_ne_bytes()
507    ),
508});
509}
510unsafe extern "C" fn _finalize<D: DomTypes>
511(_cx: *mut GCContext, obj: *mut JSObject){
512    wrap_panic(&mut || {
513
514        let this = native_from_object_static::<D::Blob>(obj).unwrap();
515        finalize_weak_referenceable(obj, this);
516    })
517}
518
519unsafe extern "C" fn _trace<D: DomTypes>
520(trc: *mut JSTracer, obj: *mut JSObject){
521    wrap_panic(&mut || {
522
523        let this = native_from_object_static::<D::Blob>(obj).unwrap();
524        if this.is_null() { return; } // GC during obj creation
525        (*this).trace(trc);
526    })
527}
528
529
530static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
531
532pub(crate) fn init_class_ops<D: DomTypes>() {
533    CLASS_OPS.set(JSClassOps {
534        addProperty: None,
535        delProperty: None,
536        enumerate: None,
537        newEnumerate: None,
538        resolve: None,
539        mayResolve: None,
540        finalize: Some(_finalize::<D>),
541        call: None,
542        construct: None,
543        trace: Some(_trace::<D>),
544    });
545}
546
547pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
548
549pub(crate) fn init_domjs_class<D: DomTypes>() {
550    init_class_ops::<D>();
551    Class.set(DOMJSClass {
552        base: JSClass {
553            name: c"Blob".as_ptr(),
554            flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
555                   (((2) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
556                   /* JSCLASS_HAS_RESERVED_SLOTS(2) */,
557            cOps: unsafe { CLASS_OPS.get() },
558            spec: ptr::null(),
559            ext: ptr::null(),
560            oOps: ptr::null(),
561        },
562        dom_class:
563DOMClass {
564    interface_chain: [ PrototypeList::ID::Blob, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
565    depth: 0,
566    type_id: crate::codegen::InheritTypes::TopTypeId { blob: (crate::codegen::InheritTypes::BlobTypeId::Blob) },
567    malloc_size_of: malloc_size_of_including_raw_self::<D::Blob> as unsafe fn(&mut _, _) -> _,
568    global: Globals::EMPTY,
569},
570    });
571}
572
573#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
574(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::Blob>, _can_gc: CanGc) -> DomRoot<D::Blob>{
575
576    let raw = Root::new(MaybeUnreflectedDom::from_box(object));
577
578    let scope = scope.reflector().get_jsobject();
579    assert!(!scope.get().is_null());
580    assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
581    let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
582
583    rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
584    GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
585    assert!(!canonical_proto.is_null());
586
587
588    rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
589    if let Some(given) = given_proto {
590        proto.set(*given);
591        if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
592            assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
593        }
594    } else {
595        proto.set(*canonical_proto);
596    }
597    rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
598        cx.raw_cx(),
599        &Class.get().base,
600        proto.handle(),
601    ));
602    assert!(!obj.is_null());
603    JS_SetReservedSlot(
604        obj.get(),
605        DOM_OBJECT_SLOT,
606        &PrivateValue(raw.as_ptr() as *const libc::c_void),
607    );
608
609    let val = PrivateValue(ptr::null());
610    JS_SetReservedSlot(obj.get(), DOM_WEAK_SLOT, &val);
611
612    let root = raw.reflect_with(obj.get());
613
614
615
616    DomRoot::from_ref(&*root)
617}
618
619pub trait BlobMethods<D: DomTypes> {
620    fn Size(&self, ) -> u64;
621    fn Type(&self, ) -> DOMString;
622    fn Slice(&self, r#start: Option<i64>, r#end: Option<i64>, r#contentType: Option<DOMString>, r#_can_gc: CanGc) -> DomRoot<D::Blob>;
623    fn Stream(&self, r#_can_gc: CanGc) -> Fallible<DomRoot<D::ReadableStream>>;
624    fn Text(&self, r#_can_gc: CanGc) -> Rc<D::Promise>;
625    fn ArrayBuffer(&self, r#_comp: InRealm, r#_can_gc: CanGc) -> Rc<D::Promise>;
626    fn Bytes(&self, r#_comp: InRealm, r#_can_gc: CanGc) -> Rc<D::Promise>;
627    fn Constructor(r#global: &D::GlobalScope, r#proto: Option<HandleObject>, r#can_gc: CanGc, r#blobParts: Option<Vec<GenericUnionTypes::ArrayBufferOrArrayBufferViewOrBlobOrString::<D>>>, r#options: &crate::codegen::GenericBindings::BlobBinding::BlobPropertyBag) -> Fallible<DomRoot<D::Blob>>;
628}
629static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
630
631pub(crate) fn init_sMethods_specs<D: DomTypes>() {
632    sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
633    JSFunctionSpec {
634        name: JSPropertySpec_Name { string_: c"slice".as_ptr() },
635        call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { slice_methodinfo.get() } as *const _ as *const JSJitInfo },
636        nargs: 0,
637        flags: (JSPROP_ENUMERATE) as u16,
638        selfHostedName: ptr::null()
639    },
640    JSFunctionSpec {
641        name: JSPropertySpec_Name { string_: c"stream".as_ptr() },
642        call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { stream_methodinfo.get() } as *const _ as *const JSJitInfo },
643        nargs: 0,
644        flags: (JSPROP_ENUMERATE) as u16,
645        selfHostedName: ptr::null()
646    },
647    JSFunctionSpec {
648        name: JSPropertySpec_Name { string_: c"text".as_ptr() },
649        call: JSNativeWrapper { op: Some(generic_method::<true>), info: unsafe { text_methodinfo.get() } as *const _ as *const JSJitInfo },
650        nargs: 0,
651        flags: (JSPROP_ENUMERATE) as u16,
652        selfHostedName: ptr::null()
653    },
654    JSFunctionSpec {
655        name: JSPropertySpec_Name { string_: c"arrayBuffer".as_ptr() },
656        call: JSNativeWrapper { op: Some(generic_method::<true>), info: unsafe { arrayBuffer_methodinfo.get() } as *const _ as *const JSJitInfo },
657        nargs: 0,
658        flags: (JSPROP_ENUMERATE) as u16,
659        selfHostedName: ptr::null()
660    },
661    JSFunctionSpec {
662        name: JSPropertySpec_Name { string_: c"bytes".as_ptr() },
663        call: JSNativeWrapper { op: Some(generic_method::<true>), info: unsafe { bytes_methodinfo.get() } as *const _ as *const JSJitInfo },
664        nargs: 0,
665        flags: (JSPROP_ENUMERATE) as u16,
666        selfHostedName: ptr::null()
667    },
668    JSFunctionSpec {
669        name: JSPropertySpec_Name { string_: ptr::null() },
670        call: JSNativeWrapper { op: None, info: ptr::null() },
671        nargs: 0,
672        flags: 0,
673        selfHostedName: ptr::null()
674    }]))[..]
675])));
676}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
677
678pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
679    sMethods.set(Box::leak(Box::new([    Guard::new(&[Condition::Exposed(Globals::WINDOW),Condition::Exposed(Globals::SERVICE_WORKER_GLOBAL_SCOPE),Condition::Exposed(Globals::DEDICATED_WORKER_GLOBAL_SCOPE)], (unsafe { sMethods_specs.get() })[0])])));
680}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
681
682pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
683    sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
684    JSPropertySpec {
685                    name: JSPropertySpec_Name { string_: c"size".as_ptr() },
686                    attributes_: (JSPROP_ENUMERATE),
687                    kind_: (JSPropertySpec_Kind::NativeAccessor),
688                    u: JSPropertySpec_AccessorsOrValue {
689                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
690                            getter: JSPropertySpec_Accessor {
691                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { size_getterinfo.get() } },
692                            },
693                            setter: JSPropertySpec_Accessor {
694                                native: JSNativeWrapper { op: None, info: ptr::null() },
695                            }
696                        }
697                    }
698                }
699,
700    JSPropertySpec {
701                    name: JSPropertySpec_Name { string_: c"type".as_ptr() },
702                    attributes_: (JSPROP_ENUMERATE),
703                    kind_: (JSPropertySpec_Kind::NativeAccessor),
704                    u: JSPropertySpec_AccessorsOrValue {
705                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
706                            getter: JSPropertySpec_Accessor {
707                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { type_getterinfo.get() } },
708                            },
709                            setter: JSPropertySpec_Accessor {
710                                native: JSNativeWrapper { op: None, info: ptr::null() },
711                            }
712                        }
713                    }
714                }
715,
716    JSPropertySpec::ZERO]))[..]
717,
718&Box::leak(Box::new([
719    JSPropertySpec {
720                    name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
721                    attributes_: (JSPROP_READONLY),
722                    kind_: (JSPropertySpec_Kind::Value),
723                    u: JSPropertySpec_AccessorsOrValue {
724                        value: JSPropertySpec_ValueWrapper {
725                            type_: JSPropertySpec_ValueWrapper_Type::String,
726                            __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
727                                string: c"Blob".as_ptr(),
728                            }
729                        }
730                    }
731                }
732,
733    JSPropertySpec::ZERO]))[..]
734])));
735}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
736
737pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
738    sAttributes.set(Box::leak(Box::new([    Guard::new(&[Condition::Exposed(Globals::WINDOW),Condition::Exposed(Globals::SERVICE_WORKER_GLOBAL_SCOPE),Condition::Exposed(Globals::DEDICATED_WORKER_GLOBAL_SCOPE)], (unsafe { sAttributes_specs.get() })[0]),
739    Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
740}
741pub fn GetProtoObject<D: DomTypes>
742(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
743    /* Get the interface prototype object for this class.  This will create the
744       object as needed. */get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::Blob), CreateInterfaceObjects::<D>, rval)
745}
746
747
748static PrototypeClass: JSClass = JSClass {
749    name: c"BlobPrototype".as_ptr(),
750    flags:
751        // JSCLASS_HAS_RESERVED_SLOTS()
752        (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
753    cOps: ptr::null(),
754    spec: ptr::null(),
755    ext: ptr::null(),
756    oOps: ptr::null(),
757};
758
759unsafe extern "C" fn _constructor<D: DomTypes>
760(cx: *mut RawJSContext, argc: u32, vp: *mut JSVal) -> bool{
761    let mut result = false;
762    wrap_panic(&mut || result = {
763        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
764        let args = CallArgs::from_vp(vp, argc);
765        let global = D::GlobalScope::from_object(JS_CALLEE(cx.raw_cx(), vp).to_object());
766
767                    call_default_constructor::<D>(
768                        SafeJSContext::from_ptr(cx.raw_cx()),
769                        &args,
770                        &global,
771                        PrototypeList::ID::Blob,
772                        "Blob",
773                        CreateInterfaceObjects::<D>,
774                        |cx: SafeJSContext, args: &CallArgs, global: &D::GlobalScope, desired_proto: HandleObject| {
775                            let arg0: Option<Vec<GenericUnionTypes::ArrayBufferOrArrayBufferViewOrBlobOrString::<D>>> = if args.get(0).is_undefined() {
776            None
777        } else {
778            Some(match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), ()) {
779                Ok(ConversionResult::Success(value)) => value,
780                Ok(ConversionResult::Failure(error)) => {
781                    throw_type_error(cx.raw_cx(), &error);
782            return false;
783
784                }
785                _ => {
786                    return false;
787
788                },
789            }
790            )
791        };
792        let arg1: crate::codegen::GenericBindings::BlobBinding::BlobPropertyBag = if args.get(1).is_undefined() {
793            crate::codegen::GenericBindings::BlobBinding::BlobPropertyBag::empty()
794        } else {
795            match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
796                Ok(ConversionResult::Success(value)) => value,
797                Ok(ConversionResult::Failure(error)) => {
798                    throw_type_error(cx.raw_cx(), &error);
799            return false;
800
801                }
802                _ => {
803                    return false;
804
805                },
806            }
807
808        };
809        let result: Result<DomRoot<D::Blob>, Error> = <D::Blob>::Constructor(global, Some(desired_proto), CanGc::note(), arg0, &arg1);
810        let result = match result {
811            Ok(result) => result,
812            Err(e) => {
813                <D as DomHelpers<D>>::throw_dom_exception(SafeJSContext::from_ptr(cx.raw_cx()), global.upcast::<D::GlobalScope>(), e, CanGc::note());
814                return false;
815            },
816        };
817
818        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
819        return true;
820                        }
821                    )
822
823    });
824    result
825}
826
827
828static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
829
830pub(crate) fn init_interface_object<D: DomTypes>() {
831    INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
832        Box::leak(Box::new(InterfaceConstructorBehavior::call(_constructor::<D>))),
833        b"function Blob() {\n    [native code]\n}",
834        PrototypeList::ID::Blob,
835        0,
836    ));
837}
838
839pub fn GetConstructorObject<D: DomTypes>
840(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
841    /* Get the interface object for this class.  This will create the object as
842       needed. */get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::Constructor(PrototypeList::Constructor::Blob), CreateInterfaceObjects::<D>, rval)
843}
844
845pub fn DefineDOMInterface<D: DomTypes>
846(cx: SafeJSContext, global: HandleObject){
847    define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::Blob),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
848}
849
850pub fn ConstructorEnabled<D: DomTypes>
851(aCx: SafeJSContext, aObj: HandleObject) -> bool{
852    is_exposed_in(aObj, Globals::DEDICATED_WORKER_GLOBAL_SCOPE | Globals::SERVICE_WORKER_GLOBAL_SCOPE | Globals::WINDOW)
853}
854
855unsafe fn CreateInterfaceObjects<D: DomTypes>
856(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
857
858    rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
859    prototype_proto.set(GetRealmObjectPrototype(cx.raw_cx()));
860    assert!(!prototype_proto.is_null());
861
862    rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
863    create_interface_prototype_object::<D>(cx,
864                                      global,
865                                      prototype_proto.handle(),
866                                      &PrototypeClass,
867                                      sMethods.get(),
868                                      sAttributes.get(),
869                                      &[],
870                                      &[],
871                                      prototype.handle_mut());
872    assert!(!prototype.is_null());
873    assert!((*cache)[PrototypeList::ID::Blob as usize].is_null());
874    (*cache)[PrototypeList::ID::Blob as usize] = prototype.get();
875    <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::Blob as isize),
876                                  ptr::null_mut(),
877                                  prototype.get());
878
879    rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
880    interface_proto.set(GetRealmFunctionPrototype(cx.raw_cx()));
881
882    assert!(!interface_proto.is_null());
883
884    rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
885    create_noncallback_interface_object::<D>(cx,
886                                        global,
887                                        interface_proto.handle(),
888                                        INTERFACE_OBJECT_CLASS.get(),
889                                        &[],
890                                        &[],
891                                        &[],
892                                        prototype.handle(),
893                                        c"Blob",
894                                        0,
895                                        &[],
896                                        interface.handle_mut());
897    assert!(!interface.is_null());
898
899    assert!((*cache)[PrototypeList::Constructor::Blob as usize].is_null());
900    (*cache)[PrototypeList::Constructor::Blob as usize] = interface.get();
901    <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::Constructor::Blob as isize),
902                                  ptr::null_mut(),
903                                  interface.get());
904
905}
906
907
908        pub(crate) fn init_statics<D: DomTypes>() {
909            init_interface_object::<D>();
910            init_domjs_class::<D>();
911            crate::codegen::GenericBindings::BlobBinding::Blob_Binding::init_slice_methodinfo::<D>();
912crate::codegen::GenericBindings::BlobBinding::Blob_Binding::init_stream_methodinfo::<D>();
913crate::codegen::GenericBindings::BlobBinding::Blob_Binding::init_text_methodinfo::<D>();
914crate::codegen::GenericBindings::BlobBinding::Blob_Binding::init_arrayBuffer_methodinfo::<D>();
915crate::codegen::GenericBindings::BlobBinding::Blob_Binding::init_bytes_methodinfo::<D>();
916            init_size_getterinfo::<D>();
917init_type_getterinfo::<D>();
918
919
920            init_sMethods_specs::<D>();
921init_sMethods_prefs::<D>();
922init_sAttributes_specs::<D>();
923init_sAttributes_prefs::<D>();
924        }
925        } // mod Blob_Binding
926
927