1#![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::EventHandlerBinding::EventHandlerNonNull;
6use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
7use crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions;
8use crate::codegen::GenericBindings::WorkerGlobalScopeBinding::WorkerGlobalScope_Binding;
9use crate::import::base::*;
10
11pub use self::DedicatedWorkerGlobalScope_Binding::{Wrap, DedicatedWorkerGlobalScopeMethods, GetProtoObject, DefineDOMInterface};
12pub mod DedicatedWorkerGlobalScope_Binding {
13use crate::codegen::GenericBindings::EventHandlerBinding::EventHandlerNonNull;
14use crate::codegen::GenericBindings::EventTargetBinding::EventTarget_Binding;
15use crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions;
16use crate::codegen::GenericBindings::WorkerGlobalScopeBinding::WorkerGlobalScope_Binding;
17use crate::import::module::*;
18
19unsafe extern "C" fn get_name<D: DomTypes>
20(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
21 let mut result = false;
22 wrap_panic(&mut || result = (|| {
23 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
24 let this = &*(this as *const D::DedicatedWorkerGlobalScope);
25 let result: DOMString = this.Name();
26
27 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
28 return true;
29 })());
30 result
31}
32
33unsafe extern "C" fn set_name<D: DomTypes>
34(cx: *mut RawJSContext, obj: RawHandleObject, this: *mut libc::c_void, args: JSJitSetterCallArgs) -> bool{
35 let mut result = false;
36 wrap_panic(&mut || result = {
37
38 JS_DefineProperty(cx, HandleObject::from_raw(obj), c"name".as_ptr(),
39 HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE as u32)
40 });
41 result
42}
43
44
45static name_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
46
47pub(crate) fn init_name_getterinfo<D: DomTypes>() {
48 name_getterinfo.set(JSJitInfo {
49 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
50 getter: Some(get_name::<D>)
51 },
52 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
53 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
54 },
55 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
56 _bitfield_align_1: [],
57 _bitfield_1: __BindgenBitfieldUnit::new(
58 new_jsjitinfo_bitfield_1!(
59 JSJitInfo_OpType::Getter as u8,
60 JSJitInfo_AliasSet::AliasEverything as u8,
61 JSValueType::JSVAL_TYPE_STRING as u8,
62 true,
63 false,
64 false,
65 false,
66 false,
67 false,
68 0,
69 ).to_ne_bytes()
70 ),
71});
72}
73static name_setterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
74
75pub(crate) fn init_name_setterinfo<D: DomTypes>() {
76 name_setterinfo.set(JSJitInfo {
77 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
78 setter: Some(set_name::<D>)
79 },
80 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
81 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
82 },
83 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
84 _bitfield_align_1: [],
85 _bitfield_1: __BindgenBitfieldUnit::new(
86 new_jsjitinfo_bitfield_1!(
87 JSJitInfo_OpType::Setter as u8,
88 JSJitInfo_AliasSet::AliasEverything as u8,
89 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
90 false,
91 false,
92 false,
93 false,
94 false,
95 false,
96 0,
97 ).to_ne_bytes()
98 ),
99});
100}
101unsafe extern "C" fn postMessage<D: DomTypes>
102(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
103 let mut result = false;
104 wrap_panic(&mut || result = (|| {
105 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
106 let this = &*(this as *const D::DedicatedWorkerGlobalScope);
107 let args = &*args;
108 let argc = args.argc_;
109
110 let argcount = cmp::min(argc, 2);
111 match argcount {
112 1 => {
113 let arg0: HandleValue = HandleValue::from_raw(args.get(0));
114 let arg1: RootedTraceableBox<crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions> = if args.get(1).is_undefined() {
115 crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions::empty()
116 } else {
117 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
118 Ok(ConversionResult::Success(value)) => value,
119 Ok(ConversionResult::Failure(error)) => {
120 throw_type_error(cx.raw_cx(), &error);
121 return false;
122
123 }
124 _ => {
125 return false;
126
127 },
128 }
129
130 };
131 let result: Result<(), Error> = this.PostMessage_(SafeJSContext::from_ptr(cx.raw_cx()), arg0, arg1);
132 let result = match result {
133 Ok(result) => result,
134 Err(e) => {
135 <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());
136 return false;
137 },
138 };
139
140 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
141 return true;
142 }
143 2 => {
144 let arg0: HandleValue = HandleValue::from_raw(args.get(0));
145 if HandleValue::from_raw(args.get(1)).get().is_null_or_undefined() {
146 let arg1: RootedTraceableBox<crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions> = if args.get(1).is_undefined() {
147 crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions::empty()
148 } else {
149 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
150 Ok(ConversionResult::Success(value)) => value,
151 Ok(ConversionResult::Failure(error)) => {
152 throw_type_error(cx.raw_cx(), &error);
153 return false;
154
155 }
156 _ => {
157 return false;
158
159 },
160 }
161
162 };
163 let result: Result<(), Error> = this.PostMessage_(SafeJSContext::from_ptr(cx.raw_cx()), arg0, arg1);
164 let result = match result {
165 Ok(result) => result,
166 Err(e) => {
167 <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());
168 return false;
169 },
170 };
171
172 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
173 return true;
174 }
175 if HandleValue::from_raw(args.get(1)).get().is_object() && is_array_like::<D>(cx.raw_cx(), HandleValue::from_raw(args.get(1))) {
176 let arg1: Vec<*mut JSObject> = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
177 Ok(ConversionResult::Success(value)) => value,
178 Ok(ConversionResult::Failure(error)) => {
179 throw_type_error(cx.raw_cx(), &error);
180 return false;
181
182 }
183 _ => {
184 return false;
185
186 },
187 }
188 ;
189 auto_root!(&in(cx) let arg1 = arg1);
190 let result: Result<(), Error> = this.PostMessage(SafeJSContext::from_ptr(cx.raw_cx()), arg0, arg1);
191 let result = match result {
192 Ok(result) => result,
193 Err(e) => {
194 <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());
195 return false;
196 },
197 };
198
199 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
200 return true;
201 }
202 if HandleValue::from_raw(args.get(1)).get().is_object() {
203 let arg1: RootedTraceableBox<crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions> = if args.get(1).is_undefined() {
204 crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions::empty()
205 } else {
206 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
207 Ok(ConversionResult::Success(value)) => value,
208 Ok(ConversionResult::Failure(error)) => {
209 throw_type_error(cx.raw_cx(), &error);
210 return false;
211
212 }
213 _ => {
214 return false;
215
216 },
217 }
218
219 };
220 let result: Result<(), Error> = this.PostMessage_(SafeJSContext::from_ptr(cx.raw_cx()), arg0, arg1);
221 let result = match result {
222 Ok(result) => result,
223 Err(e) => {
224 <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());
225 return false;
226 },
227 };
228
229 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
230 return true;
231 }
232 throw_type_error(cx.raw_cx(), "Could not convert JavaScript argument");
233 return false;
234 }
235 _ => {
236 throw_type_error(cx.raw_cx(), "Not enough arguments to \"DedicatedWorkerGlobalScope.postMessage\".");
237 return false;
238 }
239 }
240 })());
241 result
242}
243
244
245static postMessage_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
246
247pub(crate) fn init_postMessage_methodinfo<D: DomTypes>() {
248 postMessage_methodinfo.set(JSJitInfo {
249 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
250 method: Some(postMessage::<D>)
251 },
252 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
253 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
254 },
255 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
256 _bitfield_align_1: [],
257 _bitfield_1: __BindgenBitfieldUnit::new(
258 new_jsjitinfo_bitfield_1!(
259 JSJitInfo_OpType::Method as u8,
260 JSJitInfo_AliasSet::AliasEverything as u8,
261 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
262 false,
263 false,
264 false,
265 false,
266 false,
267 false,
268 0,
269 ).to_ne_bytes()
270 ),
271});
272}
273unsafe extern "C" fn get_onmessage<D: DomTypes>
274(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
275 let mut result = false;
276 wrap_panic(&mut || result = (|| {
277 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
278 let this = &*(this as *const D::DedicatedWorkerGlobalScope);
279 let result: Option<Rc<crate::codegen::GenericBindings::EventHandlerBinding::EventHandlerNonNull<D>>> = this.GetOnmessage();
280
281 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
282 return true;
283 })());
284 result
285}
286
287unsafe extern "C" fn set_onmessage<D: DomTypes>
288(cx: *mut RawJSContext, obj: RawHandleObject, this: *mut libc::c_void, args: JSJitSetterCallArgs) -> bool{
289 let mut result = false;
290 wrap_panic(&mut || result = {
291 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
292 let this = &*(this as *const D::DedicatedWorkerGlobalScope);
293 let arg0: Option<Rc<EventHandlerNonNull<D>>> = if HandleValue::from_raw(args.get(0)).get().is_object() {
294 Some(EventHandlerNonNull::<D>::new(SafeJSContext::from_ptr(cx.raw_cx()), HandleValue::from_raw(args.get(0)).get().to_object()))
295 } else {
296 None
297 };
298 let result: () = this.SetOnmessage(arg0);
299
300 true
301 });
302 result
303}
304
305
306static onmessage_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
307
308pub(crate) fn init_onmessage_getterinfo<D: DomTypes>() {
309 onmessage_getterinfo.set(JSJitInfo {
310 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
311 getter: Some(get_onmessage::<D>)
312 },
313 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
314 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
315 },
316 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
317 _bitfield_align_1: [],
318 _bitfield_1: __BindgenBitfieldUnit::new(
319 new_jsjitinfo_bitfield_1!(
320 JSJitInfo_OpType::Getter as u8,
321 JSJitInfo_AliasSet::AliasEverything as u8,
322 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
323 true,
324 false,
325 false,
326 false,
327 false,
328 false,
329 0,
330 ).to_ne_bytes()
331 ),
332});
333}
334static onmessage_setterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
335
336pub(crate) fn init_onmessage_setterinfo<D: DomTypes>() {
337 onmessage_setterinfo.set(JSJitInfo {
338 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
339 setter: Some(set_onmessage::<D>)
340 },
341 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
342 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
343 },
344 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
345 _bitfield_align_1: [],
346 _bitfield_1: __BindgenBitfieldUnit::new(
347 new_jsjitinfo_bitfield_1!(
348 JSJitInfo_OpType::Setter as u8,
349 JSJitInfo_AliasSet::AliasEverything as u8,
350 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
351 false,
352 false,
353 false,
354 false,
355 false,
356 false,
357 0,
358 ).to_ne_bytes()
359 ),
360});
361}
362unsafe extern "C" fn get_onmessageerror<D: DomTypes>
363(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
364 let mut result = false;
365 wrap_panic(&mut || result = (|| {
366 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
367 let this = &*(this as *const D::DedicatedWorkerGlobalScope);
368 let result: Option<Rc<crate::codegen::GenericBindings::EventHandlerBinding::EventHandlerNonNull<D>>> = this.GetOnmessageerror();
369
370 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
371 return true;
372 })());
373 result
374}
375
376unsafe extern "C" fn set_onmessageerror<D: DomTypes>
377(cx: *mut RawJSContext, obj: RawHandleObject, this: *mut libc::c_void, args: JSJitSetterCallArgs) -> bool{
378 let mut result = false;
379 wrap_panic(&mut || result = {
380 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
381 let this = &*(this as *const D::DedicatedWorkerGlobalScope);
382 let arg0: Option<Rc<EventHandlerNonNull<D>>> = if HandleValue::from_raw(args.get(0)).get().is_object() {
383 Some(EventHandlerNonNull::<D>::new(SafeJSContext::from_ptr(cx.raw_cx()), HandleValue::from_raw(args.get(0)).get().to_object()))
384 } else {
385 None
386 };
387 let result: () = this.SetOnmessageerror(arg0);
388
389 true
390 });
391 result
392}
393
394
395static onmessageerror_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
396
397pub(crate) fn init_onmessageerror_getterinfo<D: DomTypes>() {
398 onmessageerror_getterinfo.set(JSJitInfo {
399 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
400 getter: Some(get_onmessageerror::<D>)
401 },
402 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
403 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
404 },
405 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
406 _bitfield_align_1: [],
407 _bitfield_1: __BindgenBitfieldUnit::new(
408 new_jsjitinfo_bitfield_1!(
409 JSJitInfo_OpType::Getter as u8,
410 JSJitInfo_AliasSet::AliasEverything as u8,
411 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
412 true,
413 false,
414 false,
415 false,
416 false,
417 false,
418 0,
419 ).to_ne_bytes()
420 ),
421});
422}
423static onmessageerror_setterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
424
425pub(crate) fn init_onmessageerror_setterinfo<D: DomTypes>() {
426 onmessageerror_setterinfo.set(JSJitInfo {
427 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
428 setter: Some(set_onmessageerror::<D>)
429 },
430 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
431 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
432 },
433 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
434 _bitfield_align_1: [],
435 _bitfield_1: __BindgenBitfieldUnit::new(
436 new_jsjitinfo_bitfield_1!(
437 JSJitInfo_OpType::Setter as u8,
438 JSJitInfo_AliasSet::AliasEverything as u8,
439 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
440 false,
441 false,
442 false,
443 false,
444 false,
445 false,
446 0,
447 ).to_ne_bytes()
448 ),
449});
450}
451unsafe extern "C" fn close<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::DedicatedWorkerGlobalScope);
457 let args = &*args;
458 let argc = args.argc_;
459 let result: () = this.Close();
460
461 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
462 return true;
463 })());
464 result
465}
466
467
468static close_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
469
470pub(crate) fn init_close_methodinfo<D: DomTypes>() {
471 close_methodinfo.set(JSJitInfo {
472 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
473 method: Some(close::<D>)
474 },
475 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
476 protoID: PrototypeList::ID::DedicatedWorkerGlobalScope as u16,
477 },
478 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 3 },
479 _bitfield_align_1: [],
480 _bitfield_1: __BindgenBitfieldUnit::new(
481 new_jsjitinfo_bitfield_1!(
482 JSJitInfo_OpType::Method as u8,
483 JSJitInfo_AliasSet::AliasEverything as u8,
484 JSValueType::JSVAL_TYPE_UNDEFINED as u8,
485 true,
486 false,
487 false,
488 false,
489 false,
490 false,
491 0,
492 ).to_ne_bytes()
493 ),
494});
495}
496unsafe extern "C" fn _finalize<D: DomTypes>
497(_cx: *mut GCContext, obj: *mut JSObject){
498 wrap_panic(&mut || {
499
500 let this = native_from_object_static::<D::DedicatedWorkerGlobalScope>(obj).unwrap();
501 finalize_global(obj, this);
502 })
503}
504
505unsafe extern "C" fn _trace<D: DomTypes>
506(trc: *mut JSTracer, obj: *mut JSObject){
507 wrap_panic(&mut || {
508
509 let this = native_from_object_static::<D::DedicatedWorkerGlobalScope>(obj).unwrap();
510 if this.is_null() { return; } (*this).trace(trc);
512 trace_global(trc, obj);
513 })
514}
515
516
517static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
518
519pub(crate) fn init_class_ops<D: DomTypes>() {
520 CLASS_OPS.set(JSClassOps {
521 addProperty: None,
522 delProperty: None,
523 enumerate: None,
524 newEnumerate: Some(enumerate_global),
525 resolve: Some(resolve_global),
526 mayResolve: Some(may_resolve_global),
527 finalize: Some(_finalize::<D>),
528 call: None,
529 construct: None,
530 trace: Some(js::jsapi::JS_GlobalObjectTraceHook),
531 });
532}
533
534pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
535
536pub(crate) fn init_domjs_class<D: DomTypes>() {
537 init_class_ops::<D>();
538 Class.set(DOMJSClass {
539 base: JSClass {
540 name: c"DedicatedWorkerGlobalScope".as_ptr(),
541 flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL | JSCLASS_FOREGROUND_FINALIZE |
542 (((JSCLASS_GLOBAL_SLOT_COUNT + 1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
543 ,
544 cOps: unsafe { CLASS_OPS.get() },
545 spec: ptr::null(),
546 ext: ptr::null(),
547 oOps: ptr::null(),
548 },
549 dom_class:
550DOMClass {
551 interface_chain: [ PrototypeList::ID::EventTarget, PrototypeList::ID::GlobalScope, PrototypeList::ID::WorkerGlobalScope, PrototypeList::ID::DedicatedWorkerGlobalScope, PrototypeList::ID::Last, PrototypeList::ID::Last ],
552 depth: 3,
553 type_id: crate::codegen::InheritTypes::TopTypeId { eventtarget: (crate::codegen::InheritTypes::EventTargetTypeId::GlobalScope(crate::codegen::InheritTypes::GlobalScopeTypeId::WorkerGlobalScope(crate::codegen::InheritTypes::WorkerGlobalScopeTypeId::DedicatedWorkerGlobalScope))) },
554 malloc_size_of: malloc_size_of_including_raw_self::<D::DedicatedWorkerGlobalScope> as unsafe fn(&mut _, _) -> _,
555 global: Globals::DEDICATED_WORKER_GLOBAL_SCOPE,
556},
557 });
558}
559
560#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub fn Wrap<D: DomTypes>
561(cx: SafeJSContext, object: Box<D::DedicatedWorkerGlobalScope>) -> DomRoot<D::DedicatedWorkerGlobalScope>{
562
563 unsafe {
564 let raw = Root::new(MaybeUnreflectedDom::from_box(object));
565 let origin = (*raw.as_ptr()).upcast::<D::GlobalScope>().origin();
566
567 rooted!(&in(cx) let mut obj = ptr::null_mut::<JSObject>());
568 create_global_object::<D>(
569 cx,
570 &Class.get().base,
571 raw.as_ptr() as *const libc::c_void,
572 _trace::<D>,
573 obj.handle_mut(),
574 origin,
575 false);
576 assert!(!obj.is_null());
577
578 let root = raw.reflect_with(obj.get());
579
580 let _ac = JSAutoRealm::new(cx.raw_cx(), obj.get());
581 rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
582 GetProtoObject::<D>(cx, obj.handle(), canonical_proto.handle_mut());
583 assert!(JS_SetPrototype(cx.raw_cx(), obj.handle(), canonical_proto.handle()));
584 let mut immutable = false;
585 assert!(JS_SetImmutablePrototype(cx.raw_cx(), obj.handle(), &mut immutable));
586 assert!(immutable);
587
588 define_guarded_properties::<D>(cx, obj.handle(), sAttributes.get(), obj.handle());
589 define_guarded_methods::<D>(cx, obj.handle(), sMethods.get(), obj.handle());
590
591
592
593 DomRoot::from_ref(&*root)
594 }
595
596}
597
598pub trait DedicatedWorkerGlobalScopeMethods<D: DomTypes> {
599 fn Name(&self, ) -> DOMString;
600 fn PostMessage(&self, r#cx: SafeJSContext, r#message: HandleValue, r#transfer: CustomAutoRooterGuard<Vec<*mut JSObject>>) -> Fallible<()>;
601 fn PostMessage_(&self, r#cx: SafeJSContext, r#message: HandleValue, r#options: RootedTraceableBox<crate::codegen::GenericBindings::MessagePortBinding::StructuredSerializeOptions>) -> Fallible<()>;
602 fn GetOnmessage(&self, ) -> Option<Rc<crate::codegen::GenericBindings::EventHandlerBinding::EventHandlerNonNull<D>>>;
603 fn SetOnmessage(&self, r#value: Option<Rc<EventHandlerNonNull<D>>>);
604 fn GetOnmessageerror(&self, ) -> Option<Rc<crate::codegen::GenericBindings::EventHandlerBinding::EventHandlerNonNull<D>>>;
605 fn SetOnmessageerror(&self, r#value: Option<Rc<EventHandlerNonNull<D>>>);
606 fn Close(&self, );
607}
608static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
609
610pub(crate) fn init_sMethods_specs<D: DomTypes>() {
611 sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
612 JSFunctionSpec {
613 name: JSPropertySpec_Name { string_: c"postMessage".as_ptr() },
614 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { postMessage_methodinfo.get() } as *const _ as *const JSJitInfo },
615 nargs: 1,
616 flags: (JSPROP_ENUMERATE) as u16,
617 selfHostedName: ptr::null()
618 },
619 JSFunctionSpec {
620 name: JSPropertySpec_Name { string_: c"close".as_ptr() },
621 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { close_methodinfo.get() } as *const _ as *const JSJitInfo },
622 nargs: 0,
623 flags: (JSPROP_ENUMERATE) as u16,
624 selfHostedName: ptr::null()
625 },
626 JSFunctionSpec {
627 name: JSPropertySpec_Name { string_: ptr::null() },
628 call: JSNativeWrapper { op: None, info: ptr::null() },
629 nargs: 0,
630 flags: 0,
631 selfHostedName: ptr::null()
632 }]))[..]
633])));
634}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
635
636pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
637 sMethods.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::DEDICATED_WORKER_GLOBAL_SCOPE)], (unsafe { sMethods_specs.get() })[0])])));
638}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
639
640pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
641 sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
642 JSPropertySpec {
643 name: JSPropertySpec_Name { string_: c"name".as_ptr() },
644 attributes_: (JSPROP_ENUMERATE),
645 kind_: (JSPropertySpec_Kind::NativeAccessor),
646 u: JSPropertySpec_AccessorsOrValue {
647 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
648 getter: JSPropertySpec_Accessor {
649 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { name_getterinfo.get() } },
650 },
651 setter: JSPropertySpec_Accessor {
652 native: JSNativeWrapper { op: Some(generic_setter), info: unsafe { name_setterinfo.get() } },
653 }
654 }
655 }
656 }
657,
658 JSPropertySpec {
659 name: JSPropertySpec_Name { string_: c"onmessage".as_ptr() },
660 attributes_: (JSPROP_ENUMERATE),
661 kind_: (JSPropertySpec_Kind::NativeAccessor),
662 u: JSPropertySpec_AccessorsOrValue {
663 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
664 getter: JSPropertySpec_Accessor {
665 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { onmessage_getterinfo.get() } },
666 },
667 setter: JSPropertySpec_Accessor {
668 native: JSNativeWrapper { op: Some(generic_setter), info: unsafe { onmessage_setterinfo.get() } },
669 }
670 }
671 }
672 }
673,
674 JSPropertySpec {
675 name: JSPropertySpec_Name { string_: c"onmessageerror".as_ptr() },
676 attributes_: (JSPROP_ENUMERATE),
677 kind_: (JSPropertySpec_Kind::NativeAccessor),
678 u: JSPropertySpec_AccessorsOrValue {
679 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
680 getter: JSPropertySpec_Accessor {
681 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { onmessageerror_getterinfo.get() } },
682 },
683 setter: JSPropertySpec_Accessor {
684 native: JSNativeWrapper { op: Some(generic_setter), info: unsafe { onmessageerror_setterinfo.get() } },
685 }
686 }
687 }
688 }
689,
690 JSPropertySpec::ZERO]))[..]
691,
692&Box::leak(Box::new([
693 JSPropertySpec {
694 name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
695 attributes_: (JSPROP_READONLY),
696 kind_: (JSPropertySpec_Kind::Value),
697 u: JSPropertySpec_AccessorsOrValue {
698 value: JSPropertySpec_ValueWrapper {
699 type_: JSPropertySpec_ValueWrapper_Type::String,
700 __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
701 string: c"DedicatedWorkerGlobalScope".as_ptr(),
702 }
703 }
704 }
705 }
706,
707 JSPropertySpec::ZERO]))[..]
708])));
709}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
710
711pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
712 sAttributes.set(Box::leak(Box::new([ Guard::new(&[Condition::Exposed(Globals::DEDICATED_WORKER_GLOBAL_SCOPE)], (unsafe { sAttributes_specs.get() })[0]),
713 Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
714}
715pub fn GetProtoObject<D: DomTypes>
716(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
717 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::DedicatedWorkerGlobalScope), CreateInterfaceObjects::<D>, rval)
719}
720
721
722static PrototypeClass: JSClass = JSClass {
723 name: c"DedicatedWorkerGlobalScopePrototype".as_ptr(),
724 flags:
725 (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
727 cOps: ptr::null(),
728 spec: ptr::null(),
729 ext: ptr::null(),
730 oOps: ptr::null(),
731};
732
733
734static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
735
736pub(crate) fn init_interface_object<D: DomTypes>() {
737 INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
738 Box::leak(Box::new(InterfaceConstructorBehavior::throw())),
739 b"function DedicatedWorkerGlobalScope() {\n [native code]\n}",
740 PrototypeList::ID::DedicatedWorkerGlobalScope,
741 3,
742 ));
743}
744
745pub fn DefineDOMInterface<D: DomTypes>
746(cx: SafeJSContext, global: HandleObject){
747 define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::DedicatedWorkerGlobalScope),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
748}
749
750pub fn ConstructorEnabled<D: DomTypes>
751(aCx: SafeJSContext, aObj: HandleObject) -> bool{
752 is_exposed_in(aObj, Globals::DEDICATED_WORKER_GLOBAL_SCOPE)
753}
754
755unsafe fn CreateInterfaceObjects<D: DomTypes>
756(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
757
758 rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
759 WorkerGlobalScope_Binding::GetProtoObject::<D>(cx, global, prototype_proto.handle_mut());
760 assert!(!prototype_proto.is_null());
761
762 rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
763 create_interface_prototype_object::<D>(cx,
764 global,
765 prototype_proto.handle(),
766 &PrototypeClass,
767 &[],
768 &[],
769 &[],
770 &[],
771 prototype.handle_mut());
772 assert!(!prototype.is_null());
773 assert!((*cache)[PrototypeList::ID::DedicatedWorkerGlobalScope as usize].is_null());
774 (*cache)[PrototypeList::ID::DedicatedWorkerGlobalScope as usize] = prototype.get();
775 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::DedicatedWorkerGlobalScope as isize),
776 ptr::null_mut(),
777 prototype.get());
778
779 rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
780
781 WorkerGlobalScope_Binding::GetConstructorObject::<D>(cx, global, interface_proto.handle_mut());
782
783 assert!(!interface_proto.is_null());
784
785 rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
786 create_noncallback_interface_object::<D>(cx,
787 global,
788 interface_proto.handle(),
789 INTERFACE_OBJECT_CLASS.get(),
790 &[],
791 &[],
792 &[],
793 prototype.handle(),
794 c"DedicatedWorkerGlobalScope",
795 0,
796 &[],
797 interface.handle_mut());
798 assert!(!interface.is_null());
799}
800
801
802 pub(crate) fn init_statics<D: DomTypes>() {
803 init_interface_object::<D>();
804 init_domjs_class::<D>();
805 crate::codegen::GenericBindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScope_Binding::init_postMessage_methodinfo::<D>();
806crate::codegen::GenericBindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScope_Binding::init_close_methodinfo::<D>();
807 init_name_getterinfo::<D>();
808init_onmessage_getterinfo::<D>();
809init_onmessageerror_getterinfo::<D>();
810 init_name_setterinfo::<D>();
811init_onmessage_setterinfo::<D>();
812init_onmessageerror_setterinfo::<D>();
813
814 init_sMethods_specs::<D>();
815init_sMethods_prefs::<D>();
816init_sAttributes_specs::<D>();
817init_sAttributes_prefs::<D>();
818 }
819 }