Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM WebComponents.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "WebComponentsBinding.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/NonRefcountedDOMObject.h"
8 : #include "mozilla/dom/Nullable.h"
9 : #include "mozilla/dom/ScriptSettings.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 :
15 0 : ElementRegistrationOptions::ElementRegistrationOptions()
16 0 : : mPrototype(nullptr)
17 : {
18 : // Safe to pass a null context if we pass a null value
19 0 : Init(nullptr, JS::NullHandleValue);
20 0 : }
21 :
22 :
23 : bool
24 0 : ElementRegistrationOptions::InitIds(JSContext* cx, ElementRegistrationOptionsAtoms* atomsCache)
25 : {
26 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
27 :
28 : // Initialize these in reverse order so that any failure leaves the first one
29 : // uninitialized.
30 0 : if (!atomsCache->prototype_id.init(cx, "prototype") ||
31 0 : !atomsCache->extends_id.init(cx, "extends")) {
32 0 : return false;
33 : }
34 0 : return true;
35 : }
36 :
37 : bool
38 0 : ElementRegistrationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
39 : {
40 : // Passing a null JSContext is OK only if we're initing from null,
41 : // Since in that case we will not have to do any property gets
42 : // Also evaluate isNullOrUndefined in order to avoid false-positive
43 : // checkers by static analysis tools
44 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
45 0 : ElementRegistrationOptionsAtoms* atomsCache = nullptr;
46 0 : if (cx) {
47 0 : atomsCache = GetAtomCache<ElementRegistrationOptionsAtoms>(cx);
48 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
49 0 : return false;
50 : }
51 : }
52 :
53 0 : if (!IsConvertibleToDictionary(val)) {
54 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
55 : }
56 :
57 0 : bool isNull = val.isNullOrUndefined();
58 : // We only need these if !isNull, in which case we have |cx|.
59 0 : Maybe<JS::Rooted<JSObject *> > object;
60 0 : Maybe<JS::Rooted<JS::Value> > temp;
61 0 : if (!isNull) {
62 0 : MOZ_ASSERT(cx);
63 0 : object.emplace(cx, &val.toObject());
64 0 : temp.emplace(cx);
65 : }
66 0 : if (!isNull) {
67 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->extends_id, temp.ptr())) {
68 0 : return false;
69 : }
70 : }
71 0 : if (!isNull && !temp->isUndefined()) {
72 0 : if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mExtends)) {
73 0 : return false;
74 : }
75 : } else {
76 0 : mExtends.SetIsVoid(true);
77 : }
78 0 : mIsAnyMemberPresent = true;
79 :
80 0 : if (!isNull) {
81 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->prototype_id, temp.ptr())) {
82 0 : return false;
83 : }
84 : }
85 0 : if (!isNull && !temp->isUndefined()) {
86 0 : if (temp.ref().isObject()) {
87 : #ifdef __clang__
88 : #pragma clang diagnostic push
89 : #pragma clang diagnostic ignored "-Wunreachable-code"
90 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
91 : #endif // __clang__
92 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
93 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'prototype' member of ElementRegistrationOptions");
94 0 : return false;
95 : }
96 : #ifdef __clang__
97 : #pragma clang diagnostic pop
98 : #endif // __clang__
99 0 : mPrototype = &temp.ref().toObject();
100 0 : } else if (temp.ref().isNullOrUndefined()) {
101 0 : mPrototype = nullptr;
102 : } else {
103 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'prototype' member of ElementRegistrationOptions");
104 0 : return false;
105 : }
106 : } else {
107 0 : mPrototype = nullptr;
108 : }
109 0 : mIsAnyMemberPresent = true;
110 0 : return true;
111 : }
112 :
113 : bool
114 0 : ElementRegistrationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
115 : {
116 0 : ElementRegistrationOptionsAtoms* atomsCache = GetAtomCache<ElementRegistrationOptionsAtoms>(cx);
117 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
118 0 : return false;
119 : }
120 :
121 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
122 0 : if (!obj) {
123 0 : return false;
124 : }
125 0 : rval.set(JS::ObjectValue(*obj));
126 :
127 : do {
128 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
129 0 : JS::Rooted<JS::Value> temp(cx);
130 0 : nsString const & currentValue = mExtends;
131 0 : if (!xpc::StringToJsval(cx, currentValue, &temp)) {
132 0 : return false;
133 : }
134 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->extends_id, temp, JSPROP_ENUMERATE)) {
135 0 : return false;
136 : }
137 0 : break;
138 : } while(0);
139 :
140 : do {
141 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
142 0 : JS::Rooted<JS::Value> temp(cx);
143 0 : JSObject* const & currentValue = mPrototype;
144 0 : if (currentValue) {
145 0 : JS::ExposeObjectToActiveJS(currentValue);
146 : }
147 0 : temp.setObjectOrNull(currentValue);
148 0 : if (!MaybeWrapObjectOrNullValue(cx, &temp)) {
149 0 : return false;
150 : }
151 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->prototype_id, temp, JSPROP_ENUMERATE)) {
152 0 : return false;
153 : }
154 0 : break;
155 : } while(0);
156 :
157 0 : return true;
158 : }
159 :
160 : void
161 0 : ElementRegistrationOptions::TraceDictionary(JSTracer* trc)
162 : {
163 0 : if (mPrototype) {
164 0 : JS::UnsafeTraceRoot(trc, &mPrototype, "ElementRegistrationOptions.mPrototype");
165 : }
166 0 : }
167 :
168 : namespace binding_detail {
169 : } // namespace binding_detail
170 :
171 :
172 :
173 0 : LifecycleCallbacks::LifecycleCallbacks()
174 : {
175 : // Safe to pass a null context if we pass a null value
176 0 : Init(nullptr, JS::NullHandleValue);
177 0 : }
178 :
179 :
180 : bool
181 0 : LifecycleCallbacks::InitIds(JSContext* cx, LifecycleCallbacksAtoms* atomsCache)
182 : {
183 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
184 :
185 : // Initialize these in reverse order so that any failure leaves the first one
186 : // uninitialized.
187 0 : if (!atomsCache->detachedCallback_id.init(cx, "detachedCallback") ||
188 0 : !atomsCache->createdCallback_id.init(cx, "createdCallback") ||
189 0 : !atomsCache->attributeChangedCallback_id.init(cx, "attributeChangedCallback") ||
190 0 : !atomsCache->attachedCallback_id.init(cx, "attachedCallback")) {
191 0 : return false;
192 : }
193 0 : return true;
194 : }
195 :
196 : bool
197 0 : LifecycleCallbacks::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
198 : {
199 : // Passing a null JSContext is OK only if we're initing from null,
200 : // Since in that case we will not have to do any property gets
201 : // Also evaluate isNullOrUndefined in order to avoid false-positive
202 : // checkers by static analysis tools
203 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
204 0 : LifecycleCallbacksAtoms* atomsCache = nullptr;
205 0 : if (cx) {
206 0 : atomsCache = GetAtomCache<LifecycleCallbacksAtoms>(cx);
207 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
208 0 : return false;
209 : }
210 : }
211 :
212 0 : if (!IsConvertibleToDictionary(val)) {
213 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
214 : }
215 :
216 0 : bool isNull = val.isNullOrUndefined();
217 : // We only need these if !isNull, in which case we have |cx|.
218 0 : Maybe<JS::Rooted<JSObject *> > object;
219 0 : Maybe<JS::Rooted<JS::Value> > temp;
220 0 : if (!isNull) {
221 0 : MOZ_ASSERT(cx);
222 0 : object.emplace(cx, &val.toObject());
223 0 : temp.emplace(cx);
224 : }
225 0 : if (!isNull) {
226 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->attachedCallback_id, temp.ptr())) {
227 0 : return false;
228 : }
229 : }
230 0 : if (!isNull && !temp->isUndefined()) {
231 0 : mAttachedCallback.Construct();
232 0 : if (temp.ref().isObject()) {
233 0 : if (JS::IsCallable(&temp.ref().toObject())) {
234 : { // scope for tempRoot
235 0 : JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
236 0 : (mAttachedCallback.Value()) = new LifecycleAttachedCallback(cx, tempRoot, GetIncumbentGlobal());
237 : }
238 : } else {
239 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'attachedCallback' member of LifecycleCallbacks");
240 0 : return false;
241 : }
242 0 : } else if (temp.ref().isNullOrUndefined()) {
243 0 : (mAttachedCallback.Value()) = nullptr;
244 : } else {
245 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'attachedCallback' member of LifecycleCallbacks");
246 0 : return false;
247 : }
248 0 : mIsAnyMemberPresent = true;
249 : }
250 :
251 0 : if (!isNull) {
252 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->attributeChangedCallback_id, temp.ptr())) {
253 0 : return false;
254 : }
255 : }
256 0 : if (!isNull && !temp->isUndefined()) {
257 0 : mAttributeChangedCallback.Construct();
258 0 : if (temp.ref().isObject()) {
259 0 : if (JS::IsCallable(&temp.ref().toObject())) {
260 : { // scope for tempRoot
261 0 : JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
262 0 : (mAttributeChangedCallback.Value()) = new LifecycleAttributeChangedCallback(cx, tempRoot, GetIncumbentGlobal());
263 : }
264 : } else {
265 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'attributeChangedCallback' member of LifecycleCallbacks");
266 0 : return false;
267 : }
268 0 : } else if (temp.ref().isNullOrUndefined()) {
269 0 : (mAttributeChangedCallback.Value()) = nullptr;
270 : } else {
271 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'attributeChangedCallback' member of LifecycleCallbacks");
272 0 : return false;
273 : }
274 0 : mIsAnyMemberPresent = true;
275 : }
276 :
277 0 : if (!isNull) {
278 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->createdCallback_id, temp.ptr())) {
279 0 : return false;
280 : }
281 : }
282 0 : if (!isNull && !temp->isUndefined()) {
283 0 : mCreatedCallback.Construct();
284 0 : if (temp.ref().isObject()) {
285 0 : if (JS::IsCallable(&temp.ref().toObject())) {
286 : { // scope for tempRoot
287 0 : JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
288 0 : (mCreatedCallback.Value()) = new LifecycleCreatedCallback(cx, tempRoot, GetIncumbentGlobal());
289 : }
290 : } else {
291 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'createdCallback' member of LifecycleCallbacks");
292 0 : return false;
293 : }
294 0 : } else if (temp.ref().isNullOrUndefined()) {
295 0 : (mCreatedCallback.Value()) = nullptr;
296 : } else {
297 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'createdCallback' member of LifecycleCallbacks");
298 0 : return false;
299 : }
300 0 : mIsAnyMemberPresent = true;
301 : }
302 :
303 0 : if (!isNull) {
304 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->detachedCallback_id, temp.ptr())) {
305 0 : return false;
306 : }
307 : }
308 0 : if (!isNull && !temp->isUndefined()) {
309 0 : mDetachedCallback.Construct();
310 0 : if (temp.ref().isObject()) {
311 0 : if (JS::IsCallable(&temp.ref().toObject())) {
312 : { // scope for tempRoot
313 0 : JS::Rooted<JSObject*> tempRoot(cx, &temp.ref().toObject());
314 0 : (mDetachedCallback.Value()) = new LifecycleDetachedCallback(cx, tempRoot, GetIncumbentGlobal());
315 : }
316 : } else {
317 0 : ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "'detachedCallback' member of LifecycleCallbacks");
318 0 : return false;
319 : }
320 0 : } else if (temp.ref().isNullOrUndefined()) {
321 0 : (mDetachedCallback.Value()) = nullptr;
322 : } else {
323 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'detachedCallback' member of LifecycleCallbacks");
324 0 : return false;
325 : }
326 0 : mIsAnyMemberPresent = true;
327 : }
328 0 : return true;
329 : }
330 :
331 : bool
332 0 : LifecycleCallbacks::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
333 : {
334 0 : LifecycleCallbacksAtoms* atomsCache = GetAtomCache<LifecycleCallbacksAtoms>(cx);
335 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
336 0 : return false;
337 : }
338 :
339 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
340 0 : if (!obj) {
341 0 : return false;
342 : }
343 0 : rval.set(JS::ObjectValue(*obj));
344 :
345 0 : if (mAttachedCallback.WasPassed()) {
346 : do {
347 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
348 0 : JS::Rooted<JS::Value> temp(cx);
349 0 : RefPtr<LifecycleAttachedCallback> const & currentValue = mAttachedCallback.InternalValue();
350 0 : if (currentValue) {
351 0 : temp.setObjectOrNull(GetCallbackFromCallbackObject(currentValue));
352 0 : if (!MaybeWrapObjectOrNullValue(cx, &temp)) {
353 0 : return false;
354 : }
355 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->attachedCallback_id, temp, JSPROP_ENUMERATE)) {
356 0 : return false;
357 : }
358 0 : break;
359 : } else {
360 0 : temp.setNull();
361 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->attachedCallback_id, temp, JSPROP_ENUMERATE)) {
362 0 : return false;
363 : }
364 0 : break;
365 : }
366 : } while(0);
367 : }
368 :
369 0 : if (mAttributeChangedCallback.WasPassed()) {
370 : do {
371 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
372 0 : JS::Rooted<JS::Value> temp(cx);
373 0 : RefPtr<LifecycleAttributeChangedCallback> const & currentValue = mAttributeChangedCallback.InternalValue();
374 0 : if (currentValue) {
375 0 : temp.setObjectOrNull(GetCallbackFromCallbackObject(currentValue));
376 0 : if (!MaybeWrapObjectOrNullValue(cx, &temp)) {
377 0 : return false;
378 : }
379 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->attributeChangedCallback_id, temp, JSPROP_ENUMERATE)) {
380 0 : return false;
381 : }
382 0 : break;
383 : } else {
384 0 : temp.setNull();
385 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->attributeChangedCallback_id, temp, JSPROP_ENUMERATE)) {
386 0 : return false;
387 : }
388 0 : break;
389 : }
390 : } while(0);
391 : }
392 :
393 0 : if (mCreatedCallback.WasPassed()) {
394 : do {
395 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
396 0 : JS::Rooted<JS::Value> temp(cx);
397 0 : RefPtr<LifecycleCreatedCallback> const & currentValue = mCreatedCallback.InternalValue();
398 0 : if (currentValue) {
399 0 : temp.setObjectOrNull(GetCallbackFromCallbackObject(currentValue));
400 0 : if (!MaybeWrapObjectOrNullValue(cx, &temp)) {
401 0 : return false;
402 : }
403 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->createdCallback_id, temp, JSPROP_ENUMERATE)) {
404 0 : return false;
405 : }
406 0 : break;
407 : } else {
408 0 : temp.setNull();
409 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->createdCallback_id, temp, JSPROP_ENUMERATE)) {
410 0 : return false;
411 : }
412 0 : break;
413 : }
414 : } while(0);
415 : }
416 :
417 0 : if (mDetachedCallback.WasPassed()) {
418 : do {
419 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
420 0 : JS::Rooted<JS::Value> temp(cx);
421 0 : RefPtr<LifecycleDetachedCallback> const & currentValue = mDetachedCallback.InternalValue();
422 0 : if (currentValue) {
423 0 : temp.setObjectOrNull(GetCallbackFromCallbackObject(currentValue));
424 0 : if (!MaybeWrapObjectOrNullValue(cx, &temp)) {
425 0 : return false;
426 : }
427 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->detachedCallback_id, temp, JSPROP_ENUMERATE)) {
428 0 : return false;
429 : }
430 0 : break;
431 : } else {
432 0 : temp.setNull();
433 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->detachedCallback_id, temp, JSPROP_ENUMERATE)) {
434 0 : return false;
435 : }
436 0 : break;
437 : }
438 : } while(0);
439 : }
440 :
441 0 : return true;
442 : }
443 :
444 : void
445 0 : LifecycleCallbacks::TraceDictionary(JSTracer* trc)
446 : {
447 0 : }
448 :
449 : namespace binding_detail {
450 : } // namespace binding_detail
451 :
452 :
453 : void
454 0 : LifecycleCreatedCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
455 : {
456 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
457 :
458 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
459 0 : if (!JS::Call(cx, aThisVal, callable,
460 0 : JS::HandleValueArray::empty(), &rval)) {
461 0 : aRv.NoteJSContextException(cx);
462 0 : return;
463 : }
464 : }
465 :
466 :
467 :
468 : void
469 0 : LifecycleAttachedCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
470 : {
471 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
472 :
473 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
474 0 : if (!JS::Call(cx, aThisVal, callable,
475 0 : JS::HandleValueArray::empty(), &rval)) {
476 0 : aRv.NoteJSContextException(cx);
477 0 : return;
478 : }
479 : }
480 :
481 :
482 :
483 : void
484 0 : LifecycleDetachedCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
485 : {
486 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
487 :
488 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
489 0 : if (!JS::Call(cx, aThisVal, callable,
490 0 : JS::HandleValueArray::empty(), &rval)) {
491 0 : aRv.NoteJSContextException(cx);
492 0 : return;
493 : }
494 : }
495 :
496 :
497 :
498 : void
499 0 : LifecycleAttributeChangedCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& attrName, const nsAString& oldValue, const nsAString& newValue, ErrorResult& aRv)
500 : {
501 0 : JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
502 0 : JS::AutoValueVector argv(cx);
503 0 : if (!argv.resize(3)) {
504 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
505 0 : return;
506 : }
507 0 : unsigned argc = 3;
508 :
509 : do {
510 0 : nsString mutableStr(newValue);
511 0 : if (!xpc::StringToJsval(cx, mutableStr, argv[2])) {
512 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
513 0 : return;
514 : }
515 0 : break;
516 : } while (0);
517 :
518 : do {
519 0 : nsString mutableStr(oldValue);
520 0 : if (!xpc::StringToJsval(cx, mutableStr, argv[1])) {
521 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
522 0 : return;
523 : }
524 0 : break;
525 : } while (0);
526 :
527 : do {
528 0 : nsString mutableStr(attrName);
529 0 : if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
530 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
531 0 : return;
532 : }
533 0 : break;
534 : } while (0);
535 :
536 0 : JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
537 0 : if (!JS::Call(cx, aThisVal, callable,
538 0 : JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
539 0 : aRv.NoteJSContextException(cx);
540 0 : return;
541 : }
542 : }
543 :
544 :
545 :
546 : namespace binding_detail {
547 : } // namespace binding_detail
548 :
549 :
550 : namespace binding_detail {
551 : } // namespace binding_detail
552 :
553 :
554 : namespace binding_detail {
555 : } // namespace binding_detail
556 :
557 :
558 : namespace binding_detail {
559 : } // namespace binding_detail
560 :
561 :
562 : } // namespace dom
563 : } // namespace mozilla
|