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::import::base::*;
6
7pub use self::GenericUnionTypes::TrustedHTMLOrTrustedScriptOrTrustedScriptURL as TrustedType;
8
9#[derive(JSTraceable)]
10pub struct TrustedTypePolicyOptions<D: DomTypes> {
11 pub createHTML: Option<Rc<CreateHTMLCallback<D>>>,
12 pub createScript: Option<Rc<CreateScriptCallback<D>>>,
13 pub createScriptURL: Option<Rc<CreateScriptURLCallback<D>>>,
14}
15impl<D: DomTypes> Default for TrustedTypePolicyOptions<D> {
16 fn default() -> Self {
17 Self::empty()
18 }
19}
20
21impl<D: DomTypes> TrustedTypePolicyOptions<D> {
22 pub fn empty() -> Self {
23 Self {
24 createHTML: None,
25 createScript: None,
26 createScriptURL: None,
27 }
28 }
29 pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
30 -> Result<ConversionResult<TrustedTypePolicyOptions<D>>, ()> {
31 unsafe {
32 let object = if val.get().is_null_or_undefined() {
33 ptr::null_mut()
34 } else if val.get().is_object() {
35 val.get().to_object()
36 } else {
37 return Ok(ConversionResult::Failure("Value is not an object.".into()));
38 };
39 rooted!(&in(cx) let object = object);
40 let dictionary = TrustedTypePolicyOptions {
41 createHTML: {
42 rooted!(&in(cx) let mut rval = UndefinedValue());
43 if get_dictionary_property(cx.raw_cx(), object.handle(), "createHTML", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
44 Some(if rval.handle().get().is_object() {
45 if IsCallable(rval.handle().get().to_object()) {
46 CreateHTMLCallback::<D>::new(SafeJSContext::from_ptr(cx.raw_cx()), rval.handle().get().to_object())
47 } else {
48 throw_type_error(cx.raw_cx(), "Value is not callable.");
49 return Err(());
50
51 }
52 } else {
53 throw_type_error(cx.raw_cx(), "Value is not an object.");
54 return Err(());
55
56 })
57 } else {
58 None
59 }
60 },
61 createScript: {
62 rooted!(&in(cx) let mut rval = UndefinedValue());
63 if get_dictionary_property(cx.raw_cx(), object.handle(), "createScript", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
64 Some(if rval.handle().get().is_object() {
65 if IsCallable(rval.handle().get().to_object()) {
66 CreateScriptCallback::<D>::new(SafeJSContext::from_ptr(cx.raw_cx()), rval.handle().get().to_object())
67 } else {
68 throw_type_error(cx.raw_cx(), "Value is not callable.");
69 return Err(());
70
71 }
72 } else {
73 throw_type_error(cx.raw_cx(), "Value is not an object.");
74 return Err(());
75
76 })
77 } else {
78 None
79 }
80 },
81 createScriptURL: {
82 rooted!(&in(cx) let mut rval = UndefinedValue());
83 if get_dictionary_property(cx.raw_cx(), object.handle(), "createScriptURL", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
84 Some(if rval.handle().get().is_object() {
85 if IsCallable(rval.handle().get().to_object()) {
86 CreateScriptURLCallback::<D>::new(SafeJSContext::from_ptr(cx.raw_cx()), rval.handle().get().to_object())
87 } else {
88 throw_type_error(cx.raw_cx(), "Value is not callable.");
89 return Err(());
90
91 }
92 } else {
93 throw_type_error(cx.raw_cx(), "Value is not an object.");
94 return Err(());
95
96 })
97 } else {
98 None
99 }
100 },
101 };
102 Ok(ConversionResult::Success(dictionary))
103 }
104 }
105}
106
107impl<D: DomTypes> FromJSValConvertible for TrustedTypePolicyOptions<D> {
108 type Config = ();
109 unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
110 -> Result<ConversionResult<TrustedTypePolicyOptions<D>>, ()> {
111 TrustedTypePolicyOptions::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
112 }
113}
114
115impl<D: DomTypes> TrustedTypePolicyOptions<D> {
116 #[allow(clippy::wrong_self_convention)]
117 pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
118 if let Some(ref createHTML) = self.createHTML {
119 rooted!(in(cx) let mut createHTML_js = UndefinedValue());
120 createHTML.to_jsval(cx, createHTML_js.handle_mut());
121 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "createHTML", createHTML_js.handle()).unwrap();
122 }
123 if let Some(ref createScript) = self.createScript {
124 rooted!(in(cx) let mut createScript_js = UndefinedValue());
125 createScript.to_jsval(cx, createScript_js.handle_mut());
126 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "createScript", createScript_js.handle()).unwrap();
127 }
128 if let Some(ref createScriptURL) = self.createScriptURL {
129 rooted!(in(cx) let mut createScriptURL_js = UndefinedValue());
130 createScriptURL.to_jsval(cx, createScriptURL_js.handle_mut());
131 set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "createScriptURL", createScriptURL_js.handle()).unwrap();
132 }
133 }
134}
135
136impl<D: DomTypes> ToJSValConvertible for TrustedTypePolicyOptions<D> {
137 unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
138 rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
139 self.to_jsobject(cx, obj.handle_mut());
140 rval.set(ObjectOrNullValue(obj.get()))
141 }
142}
143
144
145#[derive(JSTraceable, MallocSizeOf, PartialEq)]
146#[cfg_attr(crown, allow(crown::unrooted_must_root))]
147#[cfg_attr(crown, crown::unrooted_must_root_lint::allow_unrooted_interior)]
148pub struct CreateHTMLCallback<D: DomTypes> {
149 pub parent: CallbackFunction<D>,
150}
151
152impl<D: DomTypes> CreateHTMLCallback<D> {
153
154 pub unsafe fn new(aCx: SafeJSContext, aCallback: *mut JSObject) -> Rc<CreateHTMLCallback<D>> {
155 let mut ret = Rc::new(CreateHTMLCallback {
156 parent: CallbackFunction::new()
157 });
158 match Rc::get_mut(&mut ret) {
160 Some(ref mut callback) => callback.parent.init(aCx, aCallback),
161 None => unreachable!(),
162 };
163 ret
164 }
165
166 pub fn Call_<T: ThisReflector>(&self, thisObj: &T, input: DOMString, arguments: Vec<HandleValue>, aExceptionHandling: ExceptionHandling, can_gc: CanGc) -> Fallible<Option<DOMString>> {
167 let s = CallSetup::<D>::new(self, aExceptionHandling);
168 rooted!(in(*s.get_context()) let mut thisValue: JSVal);
169 let wrap_result = wrap_call_this_value(s.get_context(), thisObj, thisValue.handle_mut());
170 if !wrap_result {
171 return Err(JSFailed);
172 }
173 unsafe { self.Call(s.get_context(), thisValue.handle(), input, arguments, can_gc) }
174 }
175
176 pub fn Call__<>(&self, input: DOMString, arguments: Vec<HandleValue>, aExceptionHandling: ExceptionHandling, can_gc: CanGc) -> Fallible<Option<DOMString>> {
177 let s = CallSetup::<D>::new(self, aExceptionHandling);
178
179 unsafe { self.Call(s.get_context(), HandleValue::undefined(), input, arguments, can_gc) }
180 }
181
182 unsafe fn Call<>(&self, cx: SafeJSContext, aThisObj: HandleValue, input: DOMString, arguments: Vec<HandleValue>, can_gc: CanGc) -> Fallible<Option<DOMString>> {
183 rooted!(&in(cx) let mut rval = UndefinedValue());
184 rooted_vec!(let mut argv);
185 argv.extend((0..1 + arguments.len()).map(|_| Heap::default()));
186
187 let mut argc = 1 + arguments.len();
188
189 for idx in 0..arguments.len() {
190 rooted!(&in(cx) let mut argv_root = UndefinedValue());
191 (arguments[idx].get()).to_jsval(cx.raw_cx(), argv_root.handle_mut());
192 {
193 let arg = &mut argv[1 + idx];
194 *arg = Heap::default();
195 arg.set(argv_root.get());
196 }
197 }
198
199 rooted!(&in(cx) let mut argv_root = UndefinedValue());
200 (input).to_jsval(cx.raw_cx(), argv_root.handle_mut());
201 {
202 let arg = &mut argv[0];
203 *arg = Heap::default();
204 arg.set(argv_root.get());
205 }
206
207 rooted!(&in(cx) let callable = ObjectValue(self.callback()));
208 rooted!(&in(cx) let rootedThis = aThisObj.get());
209 let ok = Call(
210 cx.raw_cx(), rootedThis.handle(), callable.handle(),
211 &HandleValueArray {
212 length_: argc as ::libc::size_t,
213 elements_: argv.as_ptr() as *const JSVal
214 }, rval.handle_mut());
215 maybe_resume_unwind();
216 if !ok {
217 return Err(JSFailed);
218 }
219 let retval: Option<DOMString> = match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), StringificationBehavior::Default) {
220 Ok(ConversionResult::Success(value)) => value,
221 Ok(ConversionResult::Failure(error)) => {
222 throw_type_error(cx.raw_cx(), &error);
223 return Err(JSFailed);
224
225 }
226 _ => {
227 return Err(JSFailed);
228
229 },
230 }
231 ;
232 Ok(retval)
233
234 }
235}
236
237impl<D: DomTypes> CallbackContainer<D> for CreateHTMLCallback<D> {
238 unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<CreateHTMLCallback<D>> {
239 CreateHTMLCallback::new(cx, callback)
240 }
241
242 fn callback_holder(&self) -> &CallbackObject<D> {
243 self.parent.callback_holder()
244 }
245}
246
247impl<D: DomTypes> ToJSValConvertible for CreateHTMLCallback<D> {
248 unsafe fn to_jsval(&self, cx: *mut RawJSContext, rval: MutableHandleValue) {
249 self.callback().to_jsval(cx, rval);
250 }
251}
252
253
254#[derive(JSTraceable, MallocSizeOf, PartialEq)]
255#[cfg_attr(crown, allow(crown::unrooted_must_root))]
256#[cfg_attr(crown, crown::unrooted_must_root_lint::allow_unrooted_interior)]
257pub struct CreateScriptCallback<D: DomTypes> {
258 pub parent: CallbackFunction<D>,
259}
260
261impl<D: DomTypes> CreateScriptCallback<D> {
262
263 pub unsafe fn new(aCx: SafeJSContext, aCallback: *mut JSObject) -> Rc<CreateScriptCallback<D>> {
264 let mut ret = Rc::new(CreateScriptCallback {
265 parent: CallbackFunction::new()
266 });
267 match Rc::get_mut(&mut ret) {
269 Some(ref mut callback) => callback.parent.init(aCx, aCallback),
270 None => unreachable!(),
271 };
272 ret
273 }
274
275 pub fn Call_<T: ThisReflector>(&self, thisObj: &T, input: DOMString, arguments: Vec<HandleValue>, aExceptionHandling: ExceptionHandling, can_gc: CanGc) -> Fallible<Option<DOMString>> {
276 let s = CallSetup::<D>::new(self, aExceptionHandling);
277 rooted!(in(*s.get_context()) let mut thisValue: JSVal);
278 let wrap_result = wrap_call_this_value(s.get_context(), thisObj, thisValue.handle_mut());
279 if !wrap_result {
280 return Err(JSFailed);
281 }
282 unsafe { self.Call(s.get_context(), thisValue.handle(), input, arguments, can_gc) }
283 }
284
285 pub fn Call__<>(&self, input: DOMString, arguments: Vec<HandleValue>, aExceptionHandling: ExceptionHandling, can_gc: CanGc) -> Fallible<Option<DOMString>> {
286 let s = CallSetup::<D>::new(self, aExceptionHandling);
287
288 unsafe { self.Call(s.get_context(), HandleValue::undefined(), input, arguments, can_gc) }
289 }
290
291 unsafe fn Call<>(&self, cx: SafeJSContext, aThisObj: HandleValue, input: DOMString, arguments: Vec<HandleValue>, can_gc: CanGc) -> Fallible<Option<DOMString>> {
292 rooted!(&in(cx) let mut rval = UndefinedValue());
293 rooted_vec!(let mut argv);
294 argv.extend((0..1 + arguments.len()).map(|_| Heap::default()));
295
296 let mut argc = 1 + arguments.len();
297
298 for idx in 0..arguments.len() {
299 rooted!(&in(cx) let mut argv_root = UndefinedValue());
300 (arguments[idx].get()).to_jsval(cx.raw_cx(), argv_root.handle_mut());
301 {
302 let arg = &mut argv[1 + idx];
303 *arg = Heap::default();
304 arg.set(argv_root.get());
305 }
306 }
307
308 rooted!(&in(cx) let mut argv_root = UndefinedValue());
309 (input).to_jsval(cx.raw_cx(), argv_root.handle_mut());
310 {
311 let arg = &mut argv[0];
312 *arg = Heap::default();
313 arg.set(argv_root.get());
314 }
315
316 rooted!(&in(cx) let callable = ObjectValue(self.callback()));
317 rooted!(&in(cx) let rootedThis = aThisObj.get());
318 let ok = Call(
319 cx.raw_cx(), rootedThis.handle(), callable.handle(),
320 &HandleValueArray {
321 length_: argc as ::libc::size_t,
322 elements_: argv.as_ptr() as *const JSVal
323 }, rval.handle_mut());
324 maybe_resume_unwind();
325 if !ok {
326 return Err(JSFailed);
327 }
328 let retval: Option<DOMString> = match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), StringificationBehavior::Default) {
329 Ok(ConversionResult::Success(value)) => value,
330 Ok(ConversionResult::Failure(error)) => {
331 throw_type_error(cx.raw_cx(), &error);
332 return Err(JSFailed);
333
334 }
335 _ => {
336 return Err(JSFailed);
337
338 },
339 }
340 ;
341 Ok(retval)
342
343 }
344}
345
346impl<D: DomTypes> CallbackContainer<D> for CreateScriptCallback<D> {
347 unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<CreateScriptCallback<D>> {
348 CreateScriptCallback::new(cx, callback)
349 }
350
351 fn callback_holder(&self) -> &CallbackObject<D> {
352 self.parent.callback_holder()
353 }
354}
355
356impl<D: DomTypes> ToJSValConvertible for CreateScriptCallback<D> {
357 unsafe fn to_jsval(&self, cx: *mut RawJSContext, rval: MutableHandleValue) {
358 self.callback().to_jsval(cx, rval);
359 }
360}
361
362
363#[derive(JSTraceable, MallocSizeOf, PartialEq)]
364#[cfg_attr(crown, allow(crown::unrooted_must_root))]
365#[cfg_attr(crown, crown::unrooted_must_root_lint::allow_unrooted_interior)]
366pub struct CreateScriptURLCallback<D: DomTypes> {
367 pub parent: CallbackFunction<D>,
368}
369
370impl<D: DomTypes> CreateScriptURLCallback<D> {
371
372 pub unsafe fn new(aCx: SafeJSContext, aCallback: *mut JSObject) -> Rc<CreateScriptURLCallback<D>> {
373 let mut ret = Rc::new(CreateScriptURLCallback {
374 parent: CallbackFunction::new()
375 });
376 match Rc::get_mut(&mut ret) {
378 Some(ref mut callback) => callback.parent.init(aCx, aCallback),
379 None => unreachable!(),
380 };
381 ret
382 }
383
384 pub fn Call_<T: ThisReflector>(&self, thisObj: &T, input: DOMString, arguments: Vec<HandleValue>, aExceptionHandling: ExceptionHandling, can_gc: CanGc) -> Fallible<Option<USVString>> {
385 let s = CallSetup::<D>::new(self, aExceptionHandling);
386 rooted!(in(*s.get_context()) let mut thisValue: JSVal);
387 let wrap_result = wrap_call_this_value(s.get_context(), thisObj, thisValue.handle_mut());
388 if !wrap_result {
389 return Err(JSFailed);
390 }
391 unsafe { self.Call(s.get_context(), thisValue.handle(), input, arguments, can_gc) }
392 }
393
394 pub fn Call__<>(&self, input: DOMString, arguments: Vec<HandleValue>, aExceptionHandling: ExceptionHandling, can_gc: CanGc) -> Fallible<Option<USVString>> {
395 let s = CallSetup::<D>::new(self, aExceptionHandling);
396
397 unsafe { self.Call(s.get_context(), HandleValue::undefined(), input, arguments, can_gc) }
398 }
399
400 unsafe fn Call<>(&self, cx: SafeJSContext, aThisObj: HandleValue, input: DOMString, arguments: Vec<HandleValue>, can_gc: CanGc) -> Fallible<Option<USVString>> {
401 rooted!(&in(cx) let mut rval = UndefinedValue());
402 rooted_vec!(let mut argv);
403 argv.extend((0..1 + arguments.len()).map(|_| Heap::default()));
404
405 let mut argc = 1 + arguments.len();
406
407 for idx in 0..arguments.len() {
408 rooted!(&in(cx) let mut argv_root = UndefinedValue());
409 (arguments[idx].get()).to_jsval(cx.raw_cx(), argv_root.handle_mut());
410 {
411 let arg = &mut argv[1 + idx];
412 *arg = Heap::default();
413 arg.set(argv_root.get());
414 }
415 }
416
417 rooted!(&in(cx) let mut argv_root = UndefinedValue());
418 (input).to_jsval(cx.raw_cx(), argv_root.handle_mut());
419 {
420 let arg = &mut argv[0];
421 *arg = Heap::default();
422 arg.set(argv_root.get());
423 }
424
425 rooted!(&in(cx) let callable = ObjectValue(self.callback()));
426 rooted!(&in(cx) let rootedThis = aThisObj.get());
427 let ok = Call(
428 cx.raw_cx(), rootedThis.handle(), callable.handle(),
429 &HandleValueArray {
430 length_: argc as ::libc::size_t,
431 elements_: argv.as_ptr() as *const JSVal
432 }, rval.handle_mut());
433 maybe_resume_unwind();
434 if !ok {
435 return Err(JSFailed);
436 }
437 let retval: Option<USVString> = match FromJSValConvertible::from_jsval(cx.raw_cx(), rval.handle(), ()) {
438 Ok(ConversionResult::Success(value)) => value,
439 Ok(ConversionResult::Failure(error)) => {
440 throw_type_error(cx.raw_cx(), &error);
441 return Err(JSFailed);
442
443 }
444 _ => {
445 return Err(JSFailed);
446
447 },
448 }
449 ;
450 Ok(retval)
451
452 }
453}
454
455impl<D: DomTypes> CallbackContainer<D> for CreateScriptURLCallback<D> {
456 unsafe fn new(cx: SafeJSContext, callback: *mut JSObject) -> Rc<CreateScriptURLCallback<D>> {
457 CreateScriptURLCallback::new(cx, callback)
458 }
459
460 fn callback_holder(&self) -> &CallbackObject<D> {
461 self.parent.callback_holder()
462 }
463}
464
465impl<D: DomTypes> ToJSValConvertible for CreateScriptURLCallback<D> {
466 unsafe fn to_jsval(&self, cx: *mut RawJSContext, rval: MutableHandleValue) {
467 self.callback().to_jsval(cx, rval);
468 }
469}
470
471
472pub use self::TrustedTypePolicyFactory_Binding::{Wrap, TrustedTypePolicyFactoryMethods, GetProtoObject, DefineDOMInterface};
473pub mod TrustedTypePolicyFactory_Binding {
474use crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::CreateHTMLCallback;
475use crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::CreateScriptCallback;
476use crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::CreateScriptURLCallback;
477use crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyOptions;
478use crate::import::module::*;
479
480unsafe extern "C" fn createPolicy<D: DomTypes>
481(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
482 let mut result = false;
483 wrap_panic(&mut || result = (|| {
484 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
485 let this = &*(this as *const D::TrustedTypePolicyFactory);
486 let args = &*args;
487 let argc = args.argc_;
488
489 if argc < 1 {
490 throw_type_error(cx.raw_cx(), "Not enough arguments to \"TrustedTypePolicyFactory.createPolicy\".");
491 return false;
492 }
493 let arg0: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), StringificationBehavior::Default) {
494 Ok(ConversionResult::Success(value)) => value,
495 Ok(ConversionResult::Failure(error)) => {
496 throw_type_error(cx.raw_cx(), &error);
497 return false;
498
499 }
500 _ => {
501 return false;
502
503 },
504 }
505 ;
506 let arg1: crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyOptions<D> = if args.get(1).is_undefined() {
507 crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyOptions::empty()
508 } else {
509 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), ()) {
510 Ok(ConversionResult::Success(value)) => value,
511 Ok(ConversionResult::Failure(error)) => {
512 throw_type_error(cx.raw_cx(), &error);
513 return false;
514
515 }
516 _ => {
517 return false;
518
519 },
520 }
521
522 };
523 let result: Result<DomRoot<D::TrustedTypePolicy>, Error> = this.CreatePolicy(arg0, &arg1, CanGc::note());
524 let result = match result {
525 Ok(result) => result,
526 Err(e) => {
527 <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());
528 return false;
529 },
530 };
531
532 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
533 return true;
534 })());
535 result
536}
537
538
539static createPolicy_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
540
541pub(crate) fn init_createPolicy_methodinfo<D: DomTypes>() {
542 createPolicy_methodinfo.set(JSJitInfo {
543 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
544 method: Some(createPolicy::<D>)
545 },
546 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
547 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
548 },
549 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
550 _bitfield_align_1: [],
551 _bitfield_1: __BindgenBitfieldUnit::new(
552 new_jsjitinfo_bitfield_1!(
553 JSJitInfo_OpType::Method as u8,
554 JSJitInfo_AliasSet::AliasEverything as u8,
555 JSValueType::JSVAL_TYPE_OBJECT as u8,
556 false,
557 false,
558 false,
559 false,
560 false,
561 false,
562 0,
563 ).to_ne_bytes()
564 ),
565});
566}
567unsafe extern "C" fn isHTML<D: DomTypes>
568(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
569 let mut result = false;
570 wrap_panic(&mut || result = (|| {
571 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
572 let this = &*(this as *const D::TrustedTypePolicyFactory);
573 let args = &*args;
574 let argc = args.argc_;
575
576 if argc < 1 {
577 throw_type_error(cx.raw_cx(), "Not enough arguments to \"TrustedTypePolicyFactory.isHTML\".");
578 return false;
579 }
580 let arg0: HandleValue = HandleValue::from_raw(args.get(0));
581 let result: bool = this.IsHTML(SafeJSContext::from_ptr(cx.raw_cx()), arg0);
582
583 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
584 return true;
585 })());
586 result
587}
588
589
590static isHTML_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
591
592pub(crate) fn init_isHTML_methodinfo<D: DomTypes>() {
593 isHTML_methodinfo.set(JSJitInfo {
594 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
595 method: Some(isHTML::<D>)
596 },
597 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
598 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
599 },
600 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
601 _bitfield_align_1: [],
602 _bitfield_1: __BindgenBitfieldUnit::new(
603 new_jsjitinfo_bitfield_1!(
604 JSJitInfo_OpType::Method as u8,
605 JSJitInfo_AliasSet::AliasEverything as u8,
606 JSValueType::JSVAL_TYPE_BOOLEAN as u8,
607 false,
608 false,
609 false,
610 false,
611 false,
612 false,
613 0,
614 ).to_ne_bytes()
615 ),
616});
617}
618unsafe extern "C" fn isScript<D: DomTypes>
619(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
620 let mut result = false;
621 wrap_panic(&mut || result = (|| {
622 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
623 let this = &*(this as *const D::TrustedTypePolicyFactory);
624 let args = &*args;
625 let argc = args.argc_;
626
627 if argc < 1 {
628 throw_type_error(cx.raw_cx(), "Not enough arguments to \"TrustedTypePolicyFactory.isScript\".");
629 return false;
630 }
631 let arg0: HandleValue = HandleValue::from_raw(args.get(0));
632 let result: bool = this.IsScript(SafeJSContext::from_ptr(cx.raw_cx()), arg0);
633
634 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
635 return true;
636 })());
637 result
638}
639
640
641static isScript_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
642
643pub(crate) fn init_isScript_methodinfo<D: DomTypes>() {
644 isScript_methodinfo.set(JSJitInfo {
645 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
646 method: Some(isScript::<D>)
647 },
648 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
649 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
650 },
651 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
652 _bitfield_align_1: [],
653 _bitfield_1: __BindgenBitfieldUnit::new(
654 new_jsjitinfo_bitfield_1!(
655 JSJitInfo_OpType::Method as u8,
656 JSJitInfo_AliasSet::AliasEverything as u8,
657 JSValueType::JSVAL_TYPE_BOOLEAN as u8,
658 false,
659 false,
660 false,
661 false,
662 false,
663 false,
664 0,
665 ).to_ne_bytes()
666 ),
667});
668}
669unsafe extern "C" fn isScriptURL<D: DomTypes>
670(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
671 let mut result = false;
672 wrap_panic(&mut || result = (|| {
673 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
674 let this = &*(this as *const D::TrustedTypePolicyFactory);
675 let args = &*args;
676 let argc = args.argc_;
677
678 if argc < 1 {
679 throw_type_error(cx.raw_cx(), "Not enough arguments to \"TrustedTypePolicyFactory.isScriptURL\".");
680 return false;
681 }
682 let arg0: HandleValue = HandleValue::from_raw(args.get(0));
683 let result: bool = this.IsScriptURL(SafeJSContext::from_ptr(cx.raw_cx()), arg0);
684
685 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
686 return true;
687 })());
688 result
689}
690
691
692static isScriptURL_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
693
694pub(crate) fn init_isScriptURL_methodinfo<D: DomTypes>() {
695 isScriptURL_methodinfo.set(JSJitInfo {
696 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
697 method: Some(isScriptURL::<D>)
698 },
699 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
700 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
701 },
702 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
703 _bitfield_align_1: [],
704 _bitfield_1: __BindgenBitfieldUnit::new(
705 new_jsjitinfo_bitfield_1!(
706 JSJitInfo_OpType::Method as u8,
707 JSJitInfo_AliasSet::AliasEverything as u8,
708 JSValueType::JSVAL_TYPE_BOOLEAN as u8,
709 false,
710 false,
711 false,
712 false,
713 false,
714 false,
715 0,
716 ).to_ne_bytes()
717 ),
718});
719}
720unsafe extern "C" fn get_emptyHTML<D: DomTypes>
721(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
722 let mut result = false;
723 wrap_panic(&mut || result = (|| {
724 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
725 let this = &*(this as *const D::TrustedTypePolicyFactory);
726 let result: DomRoot<D::TrustedHTML> = this.EmptyHTML(CanGc::note());
727
728 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
729 return true;
730 })());
731 result
732}
733
734
735static emptyHTML_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
736
737pub(crate) fn init_emptyHTML_getterinfo<D: DomTypes>() {
738 emptyHTML_getterinfo.set(JSJitInfo {
739 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
740 getter: Some(get_emptyHTML::<D>)
741 },
742 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
743 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
744 },
745 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
746 _bitfield_align_1: [],
747 _bitfield_1: __BindgenBitfieldUnit::new(
748 new_jsjitinfo_bitfield_1!(
749 JSJitInfo_OpType::Getter as u8,
750 JSJitInfo_AliasSet::AliasEverything as u8,
751 JSValueType::JSVAL_TYPE_OBJECT as u8,
752 true,
753 false,
754 false,
755 false,
756 false,
757 false,
758 0,
759 ).to_ne_bytes()
760 ),
761});
762}
763unsafe extern "C" fn get_emptyScript<D: DomTypes>
764(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
765 let mut result = false;
766 wrap_panic(&mut || result = (|| {
767 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
768 let this = &*(this as *const D::TrustedTypePolicyFactory);
769 let result: DomRoot<D::TrustedScript> = this.EmptyScript(CanGc::note());
770
771 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
772 return true;
773 })());
774 result
775}
776
777
778static emptyScript_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
779
780pub(crate) fn init_emptyScript_getterinfo<D: DomTypes>() {
781 emptyScript_getterinfo.set(JSJitInfo {
782 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
783 getter: Some(get_emptyScript::<D>)
784 },
785 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
786 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
787 },
788 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
789 _bitfield_align_1: [],
790 _bitfield_1: __BindgenBitfieldUnit::new(
791 new_jsjitinfo_bitfield_1!(
792 JSJitInfo_OpType::Getter as u8,
793 JSJitInfo_AliasSet::AliasEverything as u8,
794 JSValueType::JSVAL_TYPE_OBJECT as u8,
795 true,
796 false,
797 false,
798 false,
799 false,
800 false,
801 0,
802 ).to_ne_bytes()
803 ),
804});
805}
806unsafe extern "C" fn getAttributeType<D: DomTypes>
807(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
808 let mut result = false;
809 wrap_panic(&mut || result = (|| {
810 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
811 let this = &*(this as *const D::TrustedTypePolicyFactory);
812 let args = &*args;
813 let argc = args.argc_;
814
815 if argc < 2 {
816 throw_type_error(cx.raw_cx(), "Not enough arguments to \"TrustedTypePolicyFactory.getAttributeType\".");
817 return false;
818 }
819 let arg0: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), StringificationBehavior::Default) {
820 Ok(ConversionResult::Success(value)) => value,
821 Ok(ConversionResult::Failure(error)) => {
822 throw_type_error(cx.raw_cx(), &error);
823 return false;
824
825 }
826 _ => {
827 return false;
828
829 },
830 }
831 ;
832 let arg1: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), StringificationBehavior::Default) {
833 Ok(ConversionResult::Success(value)) => value,
834 Ok(ConversionResult::Failure(error)) => {
835 throw_type_error(cx.raw_cx(), &error);
836 return false;
837
838 }
839 _ => {
840 return false;
841
842 },
843 }
844 ;
845 let arg2: Option<DOMString> = if args.get(2).is_undefined() {
846 Some(DOMString::from(""))
847 } else {
848 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(2)), StringificationBehavior::Default) {
849 Ok(ConversionResult::Success(value)) => value,
850 Ok(ConversionResult::Failure(error)) => {
851 throw_type_error(cx.raw_cx(), &error);
852 return false;
853
854 }
855 _ => {
856 return false;
857
858 },
859 }
860
861 };
862 let arg3: Option<DOMString> = if args.get(3).is_undefined() {
863 Some(DOMString::from(""))
864 } else {
865 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(3)), StringificationBehavior::Default) {
866 Ok(ConversionResult::Success(value)) => value,
867 Ok(ConversionResult::Failure(error)) => {
868 throw_type_error(cx.raw_cx(), &error);
869 return false;
870
871 }
872 _ => {
873 return false;
874
875 },
876 }
877
878 };
879 let result: Option<DOMString> = this.GetAttributeType(arg0, arg1, arg2, arg3);
880
881 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
882 return true;
883 })());
884 result
885}
886
887
888static getAttributeType_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
889
890pub(crate) fn init_getAttributeType_methodinfo<D: DomTypes>() {
891 getAttributeType_methodinfo.set(JSJitInfo {
892 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
893 method: Some(getAttributeType::<D>)
894 },
895 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
896 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
897 },
898 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
899 _bitfield_align_1: [],
900 _bitfield_1: __BindgenBitfieldUnit::new(
901 new_jsjitinfo_bitfield_1!(
902 JSJitInfo_OpType::Method as u8,
903 JSJitInfo_AliasSet::AliasEverything as u8,
904 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
905 false,
906 false,
907 false,
908 false,
909 false,
910 false,
911 0,
912 ).to_ne_bytes()
913 ),
914});
915}
916unsafe extern "C" fn getPropertyType<D: DomTypes>
917(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: *const JSJitMethodCallArgs) -> bool{
918 let mut result = false;
919 wrap_panic(&mut || result = (|| {
920 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
921 let this = &*(this as *const D::TrustedTypePolicyFactory);
922 let args = &*args;
923 let argc = args.argc_;
924
925 if argc < 2 {
926 throw_type_error(cx.raw_cx(), "Not enough arguments to \"TrustedTypePolicyFactory.getPropertyType\".");
927 return false;
928 }
929 let arg0: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(0)), StringificationBehavior::Default) {
930 Ok(ConversionResult::Success(value)) => value,
931 Ok(ConversionResult::Failure(error)) => {
932 throw_type_error(cx.raw_cx(), &error);
933 return false;
934
935 }
936 _ => {
937 return false;
938
939 },
940 }
941 ;
942 let arg1: DOMString = match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(1)), StringificationBehavior::Default) {
943 Ok(ConversionResult::Success(value)) => value,
944 Ok(ConversionResult::Failure(error)) => {
945 throw_type_error(cx.raw_cx(), &error);
946 return false;
947
948 }
949 _ => {
950 return false;
951
952 },
953 }
954 ;
955 let arg2: Option<DOMString> = if args.get(2).is_undefined() {
956 Some(DOMString::from(""))
957 } else {
958 match FromJSValConvertible::from_jsval(cx.raw_cx(), HandleValue::from_raw(args.get(2)), StringificationBehavior::Default) {
959 Ok(ConversionResult::Success(value)) => value,
960 Ok(ConversionResult::Failure(error)) => {
961 throw_type_error(cx.raw_cx(), &error);
962 return false;
963
964 }
965 _ => {
966 return false;
967
968 },
969 }
970
971 };
972 let result: Option<DOMString> = this.GetPropertyType(arg0, arg1, arg2);
973
974 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
975 return true;
976 })());
977 result
978}
979
980
981static getPropertyType_methodinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
982
983pub(crate) fn init_getPropertyType_methodinfo<D: DomTypes>() {
984 getPropertyType_methodinfo.set(JSJitInfo {
985 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
986 method: Some(getPropertyType::<D>)
987 },
988 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
989 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
990 },
991 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
992 _bitfield_align_1: [],
993 _bitfield_1: __BindgenBitfieldUnit::new(
994 new_jsjitinfo_bitfield_1!(
995 JSJitInfo_OpType::Method as u8,
996 JSJitInfo_AliasSet::AliasEverything as u8,
997 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
998 false,
999 false,
1000 false,
1001 false,
1002 false,
1003 false,
1004 0,
1005 ).to_ne_bytes()
1006 ),
1007});
1008}
1009unsafe extern "C" fn get_defaultPolicy<D: DomTypes>
1010(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
1011 let mut result = false;
1012 wrap_panic(&mut || result = (|| {
1013 let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
1014 let this = &*(this as *const D::TrustedTypePolicyFactory);
1015 let result: Option<DomRoot<D::TrustedTypePolicy>> = this.GetDefaultPolicy();
1016
1017 (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
1018 return true;
1019 })());
1020 result
1021}
1022
1023
1024static defaultPolicy_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
1025
1026pub(crate) fn init_defaultPolicy_getterinfo<D: DomTypes>() {
1027 defaultPolicy_getterinfo.set(JSJitInfo {
1028 __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
1029 getter: Some(get_defaultPolicy::<D>)
1030 },
1031 __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
1032 protoID: PrototypeList::ID::TrustedTypePolicyFactory as u16,
1033 },
1034 __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
1035 _bitfield_align_1: [],
1036 _bitfield_1: __BindgenBitfieldUnit::new(
1037 new_jsjitinfo_bitfield_1!(
1038 JSJitInfo_OpType::Getter as u8,
1039 JSJitInfo_AliasSet::AliasEverything as u8,
1040 JSValueType::JSVAL_TYPE_UNKNOWN as u8,
1041 true,
1042 false,
1043 false,
1044 false,
1045 false,
1046 false,
1047 0,
1048 ).to_ne_bytes()
1049 ),
1050});
1051}
1052unsafe extern "C" fn _finalize<D: DomTypes>
1053(_cx: *mut GCContext, obj: *mut JSObject){
1054 wrap_panic(&mut || {
1055
1056 let this = native_from_object_static::<D::TrustedTypePolicyFactory>(obj).unwrap();
1057 finalize_common(this);
1058 })
1059}
1060
1061unsafe extern "C" fn _trace<D: DomTypes>
1062(trc: *mut JSTracer, obj: *mut JSObject){
1063 wrap_panic(&mut || {
1064
1065 let this = native_from_object_static::<D::TrustedTypePolicyFactory>(obj).unwrap();
1066 if this.is_null() { return; } (*this).trace(trc);
1068 })
1069}
1070
1071
1072static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
1073
1074pub(crate) fn init_class_ops<D: DomTypes>() {
1075 CLASS_OPS.set(JSClassOps {
1076 addProperty: None,
1077 delProperty: None,
1078 enumerate: None,
1079 newEnumerate: None,
1080 resolve: None,
1081 mayResolve: None,
1082 finalize: Some(_finalize::<D>),
1083 call: None,
1084 construct: None,
1085 trace: Some(_trace::<D>),
1086 });
1087}
1088
1089pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
1090
1091pub(crate) fn init_domjs_class<D: DomTypes>() {
1092 init_class_ops::<D>();
1093 Class.set(DOMJSClass {
1094 base: JSClass {
1095 name: c"TrustedTypePolicyFactory".as_ptr(),
1096 flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
1097 (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
1098 ,
1099 cOps: unsafe { CLASS_OPS.get() },
1100 spec: ptr::null(),
1101 ext: ptr::null(),
1102 oOps: ptr::null(),
1103 },
1104 dom_class:
1105DOMClass {
1106 interface_chain: [ PrototypeList::ID::TrustedTypePolicyFactory, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
1107 depth: 0,
1108 type_id: crate::codegen::InheritTypes::TopTypeId { alone: () },
1109 malloc_size_of: malloc_size_of_including_raw_self::<D::TrustedTypePolicyFactory> as unsafe fn(&mut _, _) -> _,
1110 global: Globals::EMPTY,
1111},
1112 });
1113}
1114
1115#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
1116(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::TrustedTypePolicyFactory>, _can_gc: CanGc) -> DomRoot<D::TrustedTypePolicyFactory>{
1117
1118 let raw = Root::new(MaybeUnreflectedDom::from_box(object));
1119
1120 let scope = scope.reflector().get_jsobject();
1121 assert!(!scope.get().is_null());
1122 assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
1123 let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
1124
1125 rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
1126 GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
1127 assert!(!canonical_proto.is_null());
1128
1129
1130 rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
1131 if let Some(given) = given_proto {
1132 proto.set(*given);
1133 if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
1134 assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
1135 }
1136 } else {
1137 proto.set(*canonical_proto);
1138 }
1139 rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
1140 cx.raw_cx(),
1141 &Class.get().base,
1142 proto.handle(),
1143 ));
1144 assert!(!obj.is_null());
1145 JS_SetReservedSlot(
1146 obj.get(),
1147 DOM_OBJECT_SLOT,
1148 &PrivateValue(raw.as_ptr() as *const libc::c_void),
1149 );
1150
1151 let root = raw.reflect_with(obj.get());
1152
1153
1154
1155 DomRoot::from_ref(&*root)
1156}
1157
1158pub trait TrustedTypePolicyFactoryMethods<D: DomTypes> {
1159 fn CreatePolicy(&self, r#policyName: DOMString, r#policyOptions: &crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyOptions<D>, r#_can_gc: CanGc) -> Fallible<DomRoot<D::TrustedTypePolicy>>;
1160 fn IsHTML(&self, r#cx: SafeJSContext, r#value: HandleValue) -> bool;
1161 fn IsScript(&self, r#cx: SafeJSContext, r#value: HandleValue) -> bool;
1162 fn IsScriptURL(&self, r#cx: SafeJSContext, r#value: HandleValue) -> bool;
1163 fn EmptyHTML(&self, r#_can_gc: CanGc) -> DomRoot<D::TrustedHTML>;
1164 fn EmptyScript(&self, r#_can_gc: CanGc) -> DomRoot<D::TrustedScript>;
1165 fn GetAttributeType(&self, r#tagName: DOMString, r#attribute: DOMString, r#elementNs: Option<DOMString>, r#attrNs: Option<DOMString>) -> Option<DOMString>;
1166 fn GetPropertyType(&self, r#tagName: DOMString, r#property: DOMString, r#elementNs: Option<DOMString>) -> Option<DOMString>;
1167 fn GetDefaultPolicy(&self, ) -> Option<DomRoot<D::TrustedTypePolicy>>;
1168}
1169static sMethods_specs: ThreadUnsafeOnceLock<&[&[JSFunctionSpec]]> = ThreadUnsafeOnceLock::new();
1170
1171pub(crate) fn init_sMethods_specs<D: DomTypes>() {
1172 sMethods_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
1173 JSFunctionSpec {
1174 name: JSPropertySpec_Name { string_: c"createPolicy".as_ptr() },
1175 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { createPolicy_methodinfo.get() } as *const _ as *const JSJitInfo },
1176 nargs: 1,
1177 flags: (JSPROP_ENUMERATE) as u16,
1178 selfHostedName: ptr::null()
1179 },
1180 JSFunctionSpec {
1181 name: JSPropertySpec_Name { string_: c"isHTML".as_ptr() },
1182 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { isHTML_methodinfo.get() } as *const _ as *const JSJitInfo },
1183 nargs: 1,
1184 flags: (JSPROP_ENUMERATE) as u16,
1185 selfHostedName: ptr::null()
1186 },
1187 JSFunctionSpec {
1188 name: JSPropertySpec_Name { string_: c"isScript".as_ptr() },
1189 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { isScript_methodinfo.get() } as *const _ as *const JSJitInfo },
1190 nargs: 1,
1191 flags: (JSPROP_ENUMERATE) as u16,
1192 selfHostedName: ptr::null()
1193 },
1194 JSFunctionSpec {
1195 name: JSPropertySpec_Name { string_: c"isScriptURL".as_ptr() },
1196 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { isScriptURL_methodinfo.get() } as *const _ as *const JSJitInfo },
1197 nargs: 1,
1198 flags: (JSPROP_ENUMERATE) as u16,
1199 selfHostedName: ptr::null()
1200 },
1201 JSFunctionSpec {
1202 name: JSPropertySpec_Name { string_: c"getAttributeType".as_ptr() },
1203 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { getAttributeType_methodinfo.get() } as *const _ as *const JSJitInfo },
1204 nargs: 2,
1205 flags: (JSPROP_ENUMERATE) as u16,
1206 selfHostedName: ptr::null()
1207 },
1208 JSFunctionSpec {
1209 name: JSPropertySpec_Name { string_: c"getPropertyType".as_ptr() },
1210 call: JSNativeWrapper { op: Some(generic_method::<false>), info: unsafe { getPropertyType_methodinfo.get() } as *const _ as *const JSJitInfo },
1211 nargs: 2,
1212 flags: (JSPROP_ENUMERATE) as u16,
1213 selfHostedName: ptr::null()
1214 },
1215 JSFunctionSpec {
1216 name: JSPropertySpec_Name { string_: ptr::null() },
1217 call: JSNativeWrapper { op: None, info: ptr::null() },
1218 nargs: 0,
1219 flags: 0,
1220 selfHostedName: ptr::null()
1221 }]))[..]
1222])));
1223}static sMethods: ThreadUnsafeOnceLock<&[Guard<&[JSFunctionSpec]>]> = ThreadUnsafeOnceLock::new();
1224
1225pub(crate) fn init_sMethods_prefs<D: DomTypes>() {
1226 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])])));
1227}static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
1228
1229pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
1230 sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
1231 JSPropertySpec {
1232 name: JSPropertySpec_Name { string_: c"emptyHTML".as_ptr() },
1233 attributes_: (JSPROP_ENUMERATE),
1234 kind_: (JSPropertySpec_Kind::NativeAccessor),
1235 u: JSPropertySpec_AccessorsOrValue {
1236 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
1237 getter: JSPropertySpec_Accessor {
1238 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { emptyHTML_getterinfo.get() } },
1239 },
1240 setter: JSPropertySpec_Accessor {
1241 native: JSNativeWrapper { op: None, info: ptr::null() },
1242 }
1243 }
1244 }
1245 }
1246,
1247 JSPropertySpec {
1248 name: JSPropertySpec_Name { string_: c"emptyScript".as_ptr() },
1249 attributes_: (JSPROP_ENUMERATE),
1250 kind_: (JSPropertySpec_Kind::NativeAccessor),
1251 u: JSPropertySpec_AccessorsOrValue {
1252 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
1253 getter: JSPropertySpec_Accessor {
1254 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { emptyScript_getterinfo.get() } },
1255 },
1256 setter: JSPropertySpec_Accessor {
1257 native: JSNativeWrapper { op: None, info: ptr::null() },
1258 }
1259 }
1260 }
1261 }
1262,
1263 JSPropertySpec {
1264 name: JSPropertySpec_Name { string_: c"defaultPolicy".as_ptr() },
1265 attributes_: (JSPROP_ENUMERATE),
1266 kind_: (JSPropertySpec_Kind::NativeAccessor),
1267 u: JSPropertySpec_AccessorsOrValue {
1268 accessors: JSPropertySpec_AccessorsOrValue_Accessors {
1269 getter: JSPropertySpec_Accessor {
1270 native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { defaultPolicy_getterinfo.get() } },
1271 },
1272 setter: JSPropertySpec_Accessor {
1273 native: JSNativeWrapper { op: None, info: ptr::null() },
1274 }
1275 }
1276 }
1277 }
1278,
1279 JSPropertySpec::ZERO]))[..]
1280,
1281&Box::leak(Box::new([
1282 JSPropertySpec {
1283 name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
1284 attributes_: (JSPROP_READONLY),
1285 kind_: (JSPropertySpec_Kind::Value),
1286 u: JSPropertySpec_AccessorsOrValue {
1287 value: JSPropertySpec_ValueWrapper {
1288 type_: JSPropertySpec_ValueWrapper_Type::String,
1289 __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
1290 string: c"TrustedTypePolicyFactory".as_ptr(),
1291 }
1292 }
1293 }
1294 }
1295,
1296 JSPropertySpec::ZERO]))[..]
1297])));
1298}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
1299
1300pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
1301 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]),
1302 Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
1303}
1304pub fn GetProtoObject<D: DomTypes>
1305(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
1306 get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::TrustedTypePolicyFactory), CreateInterfaceObjects::<D>, rval)
1308}
1309
1310
1311static PrototypeClass: JSClass = JSClass {
1312 name: c"TrustedTypePolicyFactoryPrototype".as_ptr(),
1313 flags:
1314 (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
1316 cOps: ptr::null(),
1317 spec: ptr::null(),
1318 ext: ptr::null(),
1319 oOps: ptr::null(),
1320};
1321
1322
1323static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
1324
1325pub(crate) fn init_interface_object<D: DomTypes>() {
1326 INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
1327 Box::leak(Box::new(InterfaceConstructorBehavior::throw())),
1328 b"function TrustedTypePolicyFactory() {\n [native code]\n}",
1329 PrototypeList::ID::TrustedTypePolicyFactory,
1330 0,
1331 ));
1332}
1333
1334pub fn DefineDOMInterface<D: DomTypes>
1335(cx: SafeJSContext, global: HandleObject){
1336 define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::TrustedTypePolicyFactory),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
1337}
1338
1339pub fn ConstructorEnabled<D: DomTypes>
1340(aCx: SafeJSContext, aObj: HandleObject) -> bool{
1341 is_exposed_in(aObj, Globals::DEDICATED_WORKER_GLOBAL_SCOPE | Globals::SERVICE_WORKER_GLOBAL_SCOPE | Globals::WINDOW)
1342}
1343
1344unsafe fn CreateInterfaceObjects<D: DomTypes>
1345(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
1346
1347 rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
1348 prototype_proto.set(GetRealmObjectPrototype(cx.raw_cx()));
1349 assert!(!prototype_proto.is_null());
1350
1351 rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
1352 create_interface_prototype_object::<D>(cx,
1353 global,
1354 prototype_proto.handle(),
1355 &PrototypeClass,
1356 sMethods.get(),
1357 sAttributes.get(),
1358 &[],
1359 &[],
1360 prototype.handle_mut());
1361 assert!(!prototype.is_null());
1362 assert!((*cache)[PrototypeList::ID::TrustedTypePolicyFactory as usize].is_null());
1363 (*cache)[PrototypeList::ID::TrustedTypePolicyFactory as usize] = prototype.get();
1364 <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::TrustedTypePolicyFactory as isize),
1365 ptr::null_mut(),
1366 prototype.get());
1367
1368 rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
1369 interface_proto.set(GetRealmFunctionPrototype(cx.raw_cx()));
1370
1371 assert!(!interface_proto.is_null());
1372
1373 rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
1374 create_noncallback_interface_object::<D>(cx,
1375 global,
1376 interface_proto.handle(),
1377 INTERFACE_OBJECT_CLASS.get(),
1378 &[],
1379 &[],
1380 &[],
1381 prototype.handle(),
1382 c"TrustedTypePolicyFactory",
1383 0,
1384 &[],
1385 interface.handle_mut());
1386 assert!(!interface.is_null());
1387}
1388
1389
1390 pub(crate) fn init_statics<D: DomTypes>() {
1391 init_interface_object::<D>();
1392 init_domjs_class::<D>();
1393 crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyFactory_Binding::init_createPolicy_methodinfo::<D>();
1394crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyFactory_Binding::init_isHTML_methodinfo::<D>();
1395crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyFactory_Binding::init_isScript_methodinfo::<D>();
1396crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyFactory_Binding::init_isScriptURL_methodinfo::<D>();
1397crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyFactory_Binding::init_getAttributeType_methodinfo::<D>();
1398crate::codegen::GenericBindings::TrustedTypePolicyFactoryBinding::TrustedTypePolicyFactory_Binding::init_getPropertyType_methodinfo::<D>();
1399 init_emptyHTML_getterinfo::<D>();
1400init_emptyScript_getterinfo::<D>();
1401init_defaultPolicy_getterinfo::<D>();
1402
1403
1404 init_sMethods_specs::<D>();
1405init_sMethods_prefs::<D>();
1406init_sAttributes_specs::<D>();
1407init_sAttributes_prefs::<D>();
1408 }
1409 }