Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/NotificationBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Notification.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "EventHandlerBinding.h"
5
#include "EventTargetBinding.h"
6
#include "NotificationBinding.h"
7
#include "WrapperFactory.h"
8
#include "jsapi.h"
9
#include "mozilla/OwningNonNull.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/DOMPrefs.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/Notification.h"
15
#include "mozilla/dom/Nullable.h"
16
#include "mozilla/dom/PrimitiveConversions.h"
17
#include "mozilla/dom/Promise.h"
18
#include "mozilla/dom/ScriptSettings.h"
19
#include "mozilla/dom/SimpleGlobalObject.h"
20
#include "mozilla/dom/ToJSValue.h"
21
#include "mozilla/dom/XrayExpandoClass.h"
22
23
namespace mozilla {
24
namespace dom {
25
26
namespace binding_detail {}; // Just to make sure it's known as a namespace
27
using namespace mozilla::dom::binding_detail;
28
29
30
namespace NotificationPermissionValues {
31
extern const EnumEntry strings[4] = {
32
  {"default", 7},
33
  {"denied", 6},
34
  {"granted", 7},
35
  { nullptr, 0 }
36
};
37
} // namespace NotificationPermissionValues
38
39
bool
40
ToJSValue(JSContext* aCx, NotificationPermission aArgument, JS::MutableHandle<JS::Value> aValue)
41
0
{
42
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(NotificationPermissionValues::strings));
43
0
  JSString* resultStr =
44
0
    JS_NewStringCopyN(aCx, NotificationPermissionValues::strings[uint32_t(aArgument)].value,
45
0
                      NotificationPermissionValues::strings[uint32_t(aArgument)].length);
46
0
  if (!resultStr) {
47
0
    return false;
48
0
  }
49
0
  aValue.setString(resultStr);
50
0
  return true;
51
0
}
52
53
54
namespace NotificationDirectionValues {
55
extern const EnumEntry strings[4] = {
56
  {"auto", 4},
57
  {"ltr", 3},
58
  {"rtl", 3},
59
  { nullptr, 0 }
60
};
61
} // namespace NotificationDirectionValues
62
63
bool
64
ToJSValue(JSContext* aCx, NotificationDirection aArgument, JS::MutableHandle<JS::Value> aValue)
65
0
{
66
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(NotificationDirectionValues::strings));
67
0
  JSString* resultStr =
68
0
    JS_NewStringCopyN(aCx, NotificationDirectionValues::strings[uint32_t(aArgument)].value,
69
0
                      NotificationDirectionValues::strings[uint32_t(aArgument)].length);
70
0
  if (!resultStr) {
71
0
    return false;
72
0
  }
73
0
  aValue.setString(resultStr);
74
0
  return true;
75
0
}
76
77
78
79
GetNotificationOptions::GetNotificationOptions()
80
0
{
81
0
  // Safe to pass a null context if we pass a null value
82
0
  Init(nullptr, JS::NullHandleValue);
83
0
}
84
85
86
87
bool
88
GetNotificationOptions::InitIds(JSContext* cx, GetNotificationOptionsAtoms* atomsCache)
89
0
{
90
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
91
0
92
0
  // Initialize these in reverse order so that any failure leaves the first one
93
0
  // uninitialized.
94
0
  if (!atomsCache->tag_id.init(cx, "tag")) {
95
0
    return false;
96
0
  }
97
0
  return true;
98
0
}
99
100
bool
101
GetNotificationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
102
0
{
103
0
  // Passing a null JSContext is OK only if we're initing from null,
104
0
  // Since in that case we will not have to do any property gets
105
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
106
0
  // checkers by static analysis tools
107
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
108
0
  GetNotificationOptionsAtoms* atomsCache = nullptr;
109
0
  if (cx) {
110
0
    atomsCache = GetAtomCache<GetNotificationOptionsAtoms>(cx);
111
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
112
0
      return false;
113
0
    }
114
0
  }
115
0
116
0
  if (!IsConvertibleToDictionary(val)) {
117
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
118
0
  }
119
0
120
0
  bool isNull = val.isNullOrUndefined();
121
0
  // We only need these if !isNull, in which case we have |cx|.
122
0
  Maybe<JS::Rooted<JSObject *> > object;
123
0
  Maybe<JS::Rooted<JS::Value> > temp;
124
0
  if (!isNull) {
125
0
    MOZ_ASSERT(cx);
126
0
    object.emplace(cx, &val.toObject());
127
0
    temp.emplace(cx);
128
0
  }
129
0
  if (!isNull) {
130
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->tag_id, temp.ptr())) {
131
0
      return false;
132
0
    }
133
0
  }
134
0
  if (!isNull && !temp->isUndefined()) {
135
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mTag)) {
136
0
      return false;
137
0
    }
138
0
  } else {
139
0
    static const char16_t data[] = { 0 };
140
0
    mTag.Rebind(data, ArrayLength(data) - 1);
141
0
  }
142
0
  mIsAnyMemberPresent = true;
143
0
  return true;
144
0
}
145
146
bool
147
GetNotificationOptions::Init(const nsAString& aJSON)
148
0
{
149
0
  AutoJSAPI jsapi;
150
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
151
0
  if (!cleanGlobal) {
152
0
    return false;
153
0
  }
154
0
  if (!jsapi.Init(cleanGlobal)) {
155
0
    return false;
156
0
  }
157
0
  JSContext* cx = jsapi.cx();
158
0
  JS::Rooted<JS::Value> json(cx);
159
0
  bool ok = ParseJSON(cx, aJSON, &json);
160
0
  NS_ENSURE_TRUE(ok, false);
161
0
  return Init(cx, json);
162
0
}
163
164
bool
165
GetNotificationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
166
0
{
167
0
  GetNotificationOptionsAtoms* atomsCache = GetAtomCache<GetNotificationOptionsAtoms>(cx);
168
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
169
0
    return false;
170
0
  }
171
0
172
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
173
0
  if (!obj) {
174
0
    return false;
175
0
  }
176
0
  rval.set(JS::ObjectValue(*obj));
177
0
178
0
  do {
179
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
180
0
    JS::Rooted<JS::Value> temp(cx);
181
0
    nsString const & currentValue = mTag;
182
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
183
0
      return false;
184
0
    }
185
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->tag_id, temp, JSPROP_ENUMERATE)) {
186
0
      return false;
187
0
    }
188
0
    break;
189
0
  } while(false);
190
0
191
0
  return true;
192
0
}
193
194
bool
195
GetNotificationOptions::ToJSON(nsAString& aJSON) const
196
0
{
197
0
  AutoJSAPI jsapi;
198
0
  jsapi.Init();
199
0
  JSContext *cx = jsapi.cx();
200
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
201
0
  // because we'll only be creating objects, in ways that have no
202
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
203
0
  // which likewise guarantees no side-effects for the sorts of
204
0
  // things we will pass it.
205
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
206
0
  JS::Rooted<JS::Value> val(cx);
207
0
  if (!ToObjectInternal(cx, &val)) {
208
0
    return false;
209
0
  }
210
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
211
0
  return StringifyToJSON(cx, obj, aJSON);
212
0
}
213
214
void
215
GetNotificationOptions::TraceDictionary(JSTracer* trc)
216
0
{
217
0
}
218
219
GetNotificationOptions&
220
GetNotificationOptions::operator=(const GetNotificationOptions& aOther)
221
0
{
222
0
  DictionaryBase::operator=(aOther);
223
0
  mTag = aOther.mTag;
224
0
  return *this;
225
0
}
226
227
namespace binding_detail {
228
} // namespace binding_detail
229
230
231
232
NotificationBehavior::NotificationBehavior()
233
0
{
234
0
  // Safe to pass a null context if we pass a null value
235
0
  Init(nullptr, JS::NullHandleValue);
236
0
}
237
238
239
240
bool
241
NotificationBehavior::InitIds(JSContext* cx, NotificationBehaviorAtoms* atomsCache)
242
0
{
243
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
244
0
245
0
  // Initialize these in reverse order so that any failure leaves the first one
246
0
  // uninitialized.
247
0
  if (!atomsCache->vibrationPattern_id.init(cx, "vibrationPattern") ||
248
0
      !atomsCache->soundFile_id.init(cx, "soundFile") ||
249
0
      !atomsCache->showOnlyOnce_id.init(cx, "showOnlyOnce") ||
250
0
      !atomsCache->noscreen_id.init(cx, "noscreen") ||
251
0
      !atomsCache->noclear_id.init(cx, "noclear")) {
252
0
    return false;
253
0
  }
254
0
  return true;
255
0
}
256
257
bool
258
NotificationBehavior::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
259
0
{
260
0
  // Passing a null JSContext is OK only if we're initing from null,
261
0
  // Since in that case we will not have to do any property gets
262
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
263
0
  // checkers by static analysis tools
264
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
265
0
  NotificationBehaviorAtoms* atomsCache = nullptr;
266
0
  if (cx) {
267
0
    atomsCache = GetAtomCache<NotificationBehaviorAtoms>(cx);
268
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
269
0
      return false;
270
0
    }
271
0
  }
272
0
273
0
  if (!IsConvertibleToDictionary(val)) {
274
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
275
0
  }
276
0
277
0
  bool isNull = val.isNullOrUndefined();
278
0
  // We only need these if !isNull, in which case we have |cx|.
279
0
  Maybe<JS::Rooted<JSObject *> > object;
280
0
  Maybe<JS::Rooted<JS::Value> > temp;
281
0
  if (!isNull) {
282
0
    MOZ_ASSERT(cx);
283
0
    object.emplace(cx, &val.toObject());
284
0
    temp.emplace(cx);
285
0
  }
286
0
  if (!isNull) {
287
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->noclear_id, temp.ptr())) {
288
0
      return false;
289
0
    }
290
0
  }
291
0
  if (!isNull && !temp->isUndefined()) {
292
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mNoclear)) {
293
0
      return false;
294
0
    }
295
0
  } else {
296
0
    mNoclear = false;
297
0
  }
298
0
  mIsAnyMemberPresent = true;
299
0
300
0
  if (!isNull) {
301
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->noscreen_id, temp.ptr())) {
302
0
      return false;
303
0
    }
304
0
  }
305
0
  if (!isNull && !temp->isUndefined()) {
306
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mNoscreen)) {
307
0
      return false;
308
0
    }
309
0
  } else {
310
0
    mNoscreen = false;
311
0
  }
312
0
  mIsAnyMemberPresent = true;
313
0
314
0
  if (!isNull) {
315
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->showOnlyOnce_id, temp.ptr())) {
316
0
      return false;
317
0
    }
318
0
  }
319
0
  if (!isNull && !temp->isUndefined()) {
320
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mShowOnlyOnce)) {
321
0
      return false;
322
0
    }
323
0
  } else {
324
0
    mShowOnlyOnce = false;
325
0
  }
326
0
  mIsAnyMemberPresent = true;
327
0
328
0
  if (!isNull) {
329
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->soundFile_id, temp.ptr())) {
330
0
      return false;
331
0
    }
332
0
  }
333
0
  if (!isNull && !temp->isUndefined()) {
334
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mSoundFile)) {
335
0
      return false;
336
0
    }
337
0
  } else {
338
0
    static const char16_t data[] = { 0 };
339
0
    mSoundFile.Rebind(data, ArrayLength(data) - 1);
340
0
  }
341
0
  mIsAnyMemberPresent = true;
342
0
343
0
  if (!isNull) {
344
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->vibrationPattern_id, temp.ptr())) {
345
0
      return false;
346
0
    }
347
0
  }
348
0
  if (!isNull && !temp->isUndefined()) {
349
0
    mVibrationPattern.Construct();
350
0
    if (temp.ref().isObject()) {
351
0
      JS::ForOfIterator iter(cx);
352
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
353
0
        return false;
354
0
      }
355
0
      if (!iter.valueIsIterable()) {
356
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'vibrationPattern' member of NotificationBehavior");
357
0
        return false;
358
0
      }
359
0
      Sequence<uint32_t> &arr = (mVibrationPattern.Value());
360
0
      JS::Rooted<JS::Value> temp(cx);
361
0
      while (true) {
362
0
        bool done;
363
0
        if (!iter.next(&temp, &done)) {
364
0
          return false;
365
0
        }
366
0
        if (done) {
367
0
          break;
368
0
        }
369
0
        uint32_t* slotPtr = arr.AppendElement(mozilla::fallible);
370
0
        if (!slotPtr) {
371
0
          JS_ReportOutOfMemory(cx);
372
0
          return false;
373
0
        }
374
0
        uint32_t& slot = *slotPtr;
375
0
        if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp, &slot)) {
376
0
          return false;
377
0
        }
378
0
      }
379
0
    } else {
380
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'vibrationPattern' member of NotificationBehavior");
381
0
      return false;
382
0
    }
383
0
    mIsAnyMemberPresent = true;
384
0
  }
385
0
  return true;
386
0
}
387
388
bool
389
NotificationBehavior::Init(const nsAString& aJSON)
390
0
{
391
0
  AutoJSAPI jsapi;
392
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
393
0
  if (!cleanGlobal) {
394
0
    return false;
395
0
  }
396
0
  if (!jsapi.Init(cleanGlobal)) {
397
0
    return false;
398
0
  }
399
0
  JSContext* cx = jsapi.cx();
400
0
  JS::Rooted<JS::Value> json(cx);
401
0
  bool ok = ParseJSON(cx, aJSON, &json);
402
0
  NS_ENSURE_TRUE(ok, false);
403
0
  return Init(cx, json);
404
0
}
405
406
bool
407
NotificationBehavior::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
408
0
{
409
0
  NotificationBehaviorAtoms* atomsCache = GetAtomCache<NotificationBehaviorAtoms>(cx);
410
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
411
0
    return false;
412
0
  }
413
0
414
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
415
0
  if (!obj) {
416
0
    return false;
417
0
  }
418
0
  rval.set(JS::ObjectValue(*obj));
419
0
420
0
  do {
421
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
422
0
    JS::Rooted<JS::Value> temp(cx);
423
0
    bool const & currentValue = mNoclear;
424
0
    temp.setBoolean(currentValue);
425
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->noclear_id, temp, JSPROP_ENUMERATE)) {
426
0
      return false;
427
0
    }
428
0
    break;
429
0
  } while(false);
430
0
431
0
  do {
432
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
433
0
    JS::Rooted<JS::Value> temp(cx);
434
0
    bool const & currentValue = mNoscreen;
435
0
    temp.setBoolean(currentValue);
436
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->noscreen_id, temp, JSPROP_ENUMERATE)) {
437
0
      return false;
438
0
    }
439
0
    break;
440
0
  } while(false);
441
0
442
0
  do {
443
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
444
0
    JS::Rooted<JS::Value> temp(cx);
445
0
    bool const & currentValue = mShowOnlyOnce;
446
0
    temp.setBoolean(currentValue);
447
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->showOnlyOnce_id, temp, JSPROP_ENUMERATE)) {
448
0
      return false;
449
0
    }
450
0
    break;
451
0
  } while(false);
452
0
453
0
  do {
454
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
455
0
    JS::Rooted<JS::Value> temp(cx);
456
0
    nsString const & currentValue = mSoundFile;
457
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
458
0
      return false;
459
0
    }
460
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->soundFile_id, temp, JSPROP_ENUMERATE)) {
461
0
      return false;
462
0
    }
463
0
    break;
464
0
  } while(false);
465
0
466
0
  if (mVibrationPattern.WasPassed()) {
467
0
    do {
468
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
469
0
      JS::Rooted<JS::Value> temp(cx);
470
0
      Sequence<uint32_t> const & currentValue = mVibrationPattern.InternalValue();
471
0
472
0
      uint32_t length = currentValue.Length();
473
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
474
0
      if (!returnArray) {
475
0
        return false;
476
0
      }
477
0
      // Scope for 'tmp'
478
0
      {
479
0
        JS::Rooted<JS::Value> tmp(cx);
480
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
481
0
          // Control block to let us common up the JS_DefineElement calls when there
482
0
          // are different ways to succeed at wrapping the object.
483
0
          do {
484
0
            tmp.setNumber(currentValue[sequenceIdx0]);
485
0
            break;
486
0
          } while (false);
487
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
488
0
                                JSPROP_ENUMERATE)) {
489
0
            return false;
490
0
          }
491
0
        }
492
0
      }
493
0
      temp.setObject(*returnArray);
494
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->vibrationPattern_id, temp, JSPROP_ENUMERATE)) {
495
0
        return false;
496
0
      }
497
0
      break;
498
0
    } while(false);
499
0
  }
500
0
501
0
  return true;
502
0
}
503
504
bool
505
NotificationBehavior::ToJSON(nsAString& aJSON) const
506
0
{
507
0
  AutoJSAPI jsapi;
508
0
  jsapi.Init();
509
0
  JSContext *cx = jsapi.cx();
510
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
511
0
  // because we'll only be creating objects, in ways that have no
512
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
513
0
  // which likewise guarantees no side-effects for the sorts of
514
0
  // things we will pass it.
515
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
516
0
  JS::Rooted<JS::Value> val(cx);
517
0
  if (!ToObjectInternal(cx, &val)) {
518
0
    return false;
519
0
  }
520
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
521
0
  return StringifyToJSON(cx, obj, aJSON);
522
0
}
523
524
void
525
NotificationBehavior::TraceDictionary(JSTracer* trc)
526
0
{
527
0
}
528
529
NotificationBehavior&
530
NotificationBehavior::operator=(const NotificationBehavior& aOther)
531
0
{
532
0
  DictionaryBase::operator=(aOther);
533
0
  mNoclear = aOther.mNoclear;
534
0
  mNoscreen = aOther.mNoscreen;
535
0
  mShowOnlyOnce = aOther.mShowOnlyOnce;
536
0
  mSoundFile = aOther.mSoundFile;
537
0
  mVibrationPattern.Reset();
538
0
  if (aOther.mVibrationPattern.WasPassed()) {
539
0
    mVibrationPattern.Construct(aOther.mVibrationPattern.Value());
540
0
  }
541
0
  return *this;
542
0
}
543
544
namespace binding_detail {
545
} // namespace binding_detail
546
547
548
549
NotificationOptions::NotificationOptions()
550
  : mData(JS::UndefinedValue()),
551
    mMozbehavior(FastDictionaryInitializer())
552
0
{
553
0
  // Safe to pass a null context if we pass a null value
554
0
  Init(nullptr, JS::NullHandleValue);
555
0
}
556
557
558
bool
559
NotificationOptions::InitIds(JSContext* cx, NotificationOptionsAtoms* atomsCache)
560
0
{
561
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
562
0
563
0
  // Initialize these in reverse order so that any failure leaves the first one
564
0
  // uninitialized.
565
0
  if (!atomsCache->tag_id.init(cx, "tag") ||
566
0
      !atomsCache->requireInteraction_id.init(cx, "requireInteraction") ||
567
0
      !atomsCache->mozbehavior_id.init(cx, "mozbehavior") ||
568
0
      !atomsCache->lang_id.init(cx, "lang") ||
569
0
      !atomsCache->icon_id.init(cx, "icon") ||
570
0
      !atomsCache->dir_id.init(cx, "dir") ||
571
0
      !atomsCache->data_id.init(cx, "data") ||
572
0
      !atomsCache->body_id.init(cx, "body")) {
573
0
    return false;
574
0
  }
575
0
  return true;
576
0
}
577
578
bool
579
NotificationOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
580
0
{
581
0
  // Passing a null JSContext is OK only if we're initing from null,
582
0
  // Since in that case we will not have to do any property gets
583
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
584
0
  // checkers by static analysis tools
585
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
586
0
  NotificationOptionsAtoms* atomsCache = nullptr;
587
0
  if (cx) {
588
0
    atomsCache = GetAtomCache<NotificationOptionsAtoms>(cx);
589
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
590
0
      return false;
591
0
    }
592
0
  }
593
0
594
0
  if (!IsConvertibleToDictionary(val)) {
595
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
596
0
  }
597
0
598
0
  bool isNull = val.isNullOrUndefined();
599
0
  // We only need these if !isNull, in which case we have |cx|.
600
0
  Maybe<JS::Rooted<JSObject *> > object;
601
0
  Maybe<JS::Rooted<JS::Value> > temp;
602
0
  if (!isNull) {
603
0
    MOZ_ASSERT(cx);
604
0
    object.emplace(cx, &val.toObject());
605
0
    temp.emplace(cx);
606
0
  }
607
0
  if (!isNull) {
608
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->body_id, temp.ptr())) {
609
0
      return false;
610
0
    }
611
0
  }
612
0
  if (!isNull && !temp->isUndefined()) {
613
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mBody)) {
614
0
      return false;
615
0
    }
616
0
  } else {
617
0
    static const char16_t data[] = { 0 };
618
0
    mBody.Rebind(data, ArrayLength(data) - 1);
619
0
  }
620
0
  mIsAnyMemberPresent = true;
621
0
622
0
  if (!isNull) {
623
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) {
624
0
      return false;
625
0
    }
626
0
  }
627
0
  if (!isNull && !temp->isUndefined()) {
628
0
#ifdef __clang__
629
0
#pragma clang diagnostic push
630
0
#pragma clang diagnostic ignored "-Wunreachable-code"
631
0
#pragma clang diagnostic ignored "-Wunreachable-code-return"
632
0
#endif // __clang__
633
0
    if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
634
0
      ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'data' member of NotificationOptions");
635
0
      return false;
636
0
    }
637
0
#ifdef __clang__
638
0
#pragma clang diagnostic pop
639
0
#endif // __clang__
640
0
    mData = temp.ref();
641
0
  } else {
642
0
    mData = JS::NullValue();
643
0
  }
644
0
  mIsAnyMemberPresent = true;
645
0
646
0
  if (!isNull) {
647
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->dir_id, temp.ptr())) {
648
0
      return false;
649
0
    }
650
0
  }
651
0
  if (!isNull && !temp->isUndefined()) {
652
0
    {
653
0
      int index;
654
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), NotificationDirectionValues::strings, "NotificationDirection", "'dir' member of NotificationOptions", &index)) {
655
0
        return false;
656
0
      }
657
0
      MOZ_ASSERT(index >= 0);
658
0
      mDir = static_cast<NotificationDirection>(index);
659
0
    }
660
0
  } else {
661
0
    mDir = NotificationDirection::Auto;
662
0
  }
663
0
  mIsAnyMemberPresent = true;
664
0
665
0
  if (!isNull) {
666
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->icon_id, temp.ptr())) {
667
0
      return false;
668
0
    }
669
0
  }
670
0
  if (!isNull && !temp->isUndefined()) {
671
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mIcon)) {
672
0
      return false;
673
0
    }
674
0
  } else {
675
0
    static const char16_t data[] = { 0 };
676
0
    mIcon.Rebind(data, ArrayLength(data) - 1);
677
0
  }
678
0
  mIsAnyMemberPresent = true;
679
0
680
0
  if (!isNull) {
681
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->lang_id, temp.ptr())) {
682
0
      return false;
683
0
    }
684
0
  }
685
0
  if (!isNull && !temp->isUndefined()) {
686
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLang)) {
687
0
      return false;
688
0
    }
689
0
  } else {
690
0
    static const char16_t data[] = { 0 };
691
0
    mLang.Rebind(data, ArrayLength(data) - 1);
692
0
  }
693
0
  mIsAnyMemberPresent = true;
694
0
695
0
  if (!isNull) {
696
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->mozbehavior_id, temp.ptr())) {
697
0
      return false;
698
0
    }
699
0
  }
700
0
  if (!mMozbehavior.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'mozbehavior' member of NotificationOptions", passedToJSImpl)) {
701
0
    return false;
702
0
  }
703
0
  mIsAnyMemberPresent = true;
704
0
705
0
  if (!isNull) {
706
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->requireInteraction_id, temp.ptr())) {
707
0
      return false;
708
0
    }
709
0
  }
710
0
  if (!isNull && !temp->isUndefined()) {
711
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mRequireInteraction)) {
712
0
      return false;
713
0
    }
714
0
  } else {
715
0
    mRequireInteraction = false;
716
0
  }
717
0
  mIsAnyMemberPresent = true;
718
0
719
0
  if (!isNull) {
720
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->tag_id, temp.ptr())) {
721
0
      return false;
722
0
    }
723
0
  }
724
0
  if (!isNull && !temp->isUndefined()) {
725
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mTag)) {
726
0
      return false;
727
0
    }
728
0
  } else {
729
0
    static const char16_t data[] = { 0 };
730
0
    mTag.Rebind(data, ArrayLength(data) - 1);
731
0
  }
732
0
  mIsAnyMemberPresent = true;
733
0
  return true;
734
0
}
735
736
bool
737
NotificationOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
738
0
{
739
0
  NotificationOptionsAtoms* atomsCache = GetAtomCache<NotificationOptionsAtoms>(cx);
740
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
741
0
    return false;
742
0
  }
743
0
744
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
745
0
  if (!obj) {
746
0
    return false;
747
0
  }
748
0
  rval.set(JS::ObjectValue(*obj));
749
0
750
0
  do {
751
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
752
0
    JS::Rooted<JS::Value> temp(cx);
753
0
    nsString const & currentValue = mBody;
754
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
755
0
      return false;
756
0
    }
757
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->body_id, temp, JSPROP_ENUMERATE)) {
758
0
      return false;
759
0
    }
760
0
    break;
761
0
  } while(false);
762
0
763
0
  do {
764
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
765
0
    JS::Rooted<JS::Value> temp(cx);
766
0
    JS::Value const & currentValue = mData;
767
0
    JS::ExposeValueToActiveJS(currentValue);
768
0
    temp.set(currentValue);
769
0
    if (!MaybeWrapValue(cx, &temp)) {
770
0
      return false;
771
0
    }
772
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
773
0
      return false;
774
0
    }
775
0
    break;
776
0
  } while(false);
777
0
778
0
  do {
779
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
780
0
    JS::Rooted<JS::Value> temp(cx);
781
0
    NotificationDirection const & currentValue = mDir;
782
0
    if (!ToJSValue(cx, currentValue, &temp)) {
783
0
      return false;
784
0
    }
785
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->dir_id, temp, JSPROP_ENUMERATE)) {
786
0
      return false;
787
0
    }
788
0
    break;
789
0
  } while(false);
790
0
791
0
  do {
792
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
793
0
    JS::Rooted<JS::Value> temp(cx);
794
0
    nsString const & currentValue = mIcon;
795
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
796
0
      return false;
797
0
    }
798
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->icon_id, temp, JSPROP_ENUMERATE)) {
799
0
      return false;
800
0
    }
801
0
    break;
802
0
  } while(false);
803
0
804
0
  do {
805
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
806
0
    JS::Rooted<JS::Value> temp(cx);
807
0
    nsString const & currentValue = mLang;
808
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
809
0
      return false;
810
0
    }
811
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->lang_id, temp, JSPROP_ENUMERATE)) {
812
0
      return false;
813
0
    }
814
0
    break;
815
0
  } while(false);
816
0
817
0
  do {
818
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
819
0
    JS::Rooted<JS::Value> temp(cx);
820
0
    NotificationBehavior const & currentValue = mMozbehavior;
821
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
822
0
      return false;
823
0
    }
824
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->mozbehavior_id, temp, JSPROP_ENUMERATE)) {
825
0
      return false;
826
0
    }
827
0
    break;
828
0
  } while(false);
829
0
830
0
  do {
831
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
832
0
    JS::Rooted<JS::Value> temp(cx);
833
0
    bool const & currentValue = mRequireInteraction;
834
0
    temp.setBoolean(currentValue);
835
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->requireInteraction_id, temp, JSPROP_ENUMERATE)) {
836
0
      return false;
837
0
    }
838
0
    break;
839
0
  } while(false);
840
0
841
0
  do {
842
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
843
0
    JS::Rooted<JS::Value> temp(cx);
844
0
    nsString const & currentValue = mTag;
845
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
846
0
      return false;
847
0
    }
848
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->tag_id, temp, JSPROP_ENUMERATE)) {
849
0
      return false;
850
0
    }
851
0
    break;
852
0
  } while(false);
853
0
854
0
  return true;
855
0
}
856
857
void
858
NotificationOptions::TraceDictionary(JSTracer* trc)
859
0
{
860
0
  JS::UnsafeTraceRoot(trc, &mData, "NotificationOptions.mData");
861
0
}
862
863
namespace binding_detail {
864
} // namespace binding_detail
865
866
867
void
868
NotificationPermissionCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, NotificationPermission permission, ErrorResult& aRv)
869
0
{
870
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
871
0
  JS::AutoValueVector argv(cx);
872
0
  if (!argv.resize(1)) {
873
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
874
0
    return;
875
0
  }
876
0
  unsigned argc = 1;
877
0
878
0
  do {
879
0
    if (!ToJSValue(cx, permission, argv[0])) {
880
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
881
0
      return;
882
0
    }
883
0
    break;
884
0
  } while (false);
885
0
886
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
887
0
  if (!JS::Call(cx, aThisVal, callable,
888
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
889
0
    aRv.NoteJSContextException(cx);
890
0
    return;
891
0
  }
892
0
}
893
894
895
896
namespace binding_detail {
897
} // namespace binding_detail
898
899
900
namespace Notification_Binding {
901
902
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
903
              "Can't inherit from an interface with a different ownership model.");
904
905
static bool
906
get_permission(JSContext* cx, unsigned argc, JS::Value* vp)
907
0
{
908
0
  AUTO_PROFILER_LABEL_FAST("get Notification.permission", DOM, cx);
909
0
910
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
911
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
912
0
913
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
914
0
  if (global.Failed()) {
915
0
    return false;
916
0
  }
917
0
918
0
  FastErrorResult rv;
919
0
  NotificationPermission result(mozilla::dom::Notification::GetPermission(global, rv));
920
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
921
0
    return false;
922
0
  }
923
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
924
0
  if (!ToJSValue(cx, result, args.rval())) {
925
0
    return false;
926
0
  }
927
0
  return true;
928
0
}
929
930
static bool
931
requestPermission(JSContext* cx, unsigned argc, JS::Value* vp)
932
0
{
933
0
  AUTO_PROFILER_LABEL_FAST("Notification.requestPermission", DOM, cx);
934
0
935
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
936
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
937
0
938
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
939
0
  if (global.Failed()) {
940
0
    return false;
941
0
  }
942
0
943
0
  Optional<OwningNonNull<NotificationPermissionCallback>> arg0;
944
0
  if (args.hasDefined(0)) {
945
0
    arg0.Construct();
946
0
    if (args[0].isObject()) {
947
0
      if (JS::IsCallable(&args[0].toObject())) {
948
0
      { // scope for tempRoot and tempGlobalRoot if needed
949
0
        JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
950
0
        JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx));
951
0
        arg0.Value() = new NotificationPermissionCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal());
952
0
      }
953
0
      } else {
954
0
        ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of Notification.requestPermission");
955
0
        return false;
956
0
      }
957
0
    } else {
958
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of Notification.requestPermission");
959
0
      return false;
960
0
    }
961
0
  }
962
0
  FastErrorResult rv;
963
0
  auto result(StrongOrRawPtr<Promise>(mozilla::dom::Notification::RequestPermission(global, NonNullHelper(Constify(arg0)), rv)));
964
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
965
0
    return false;
966
0
  }
967
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
968
0
  if (!ToJSValue(cx, result, args.rval())) {
969
0
    return false;
970
0
  }
971
0
  return true;
972
0
}
973
974
975
static const JSJitInfo requestPermission_methodinfo = {
976
  { (JSJitGetterOp)requestPermission },
977
  { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
978
  JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
979
  false, false, 0
980
};
981
982
static bool
983
get(JSContext* cx, unsigned argc, JS::Value* vp)
984
0
{
985
0
  AUTO_PROFILER_LABEL_FAST("Notification.get", DOM, cx);
986
0
987
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
988
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
989
0
990
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
991
0
  if (global.Failed()) {
992
0
    return false;
993
0
  }
994
0
995
0
  binding_detail::FastGetNotificationOptions arg0;
996
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of Notification.get", false)) {
997
0
    return false;
998
0
  }
999
0
  FastErrorResult rv;
1000
0
  auto result(StrongOrRawPtr<Promise>(mozilla::dom::Notification::Get(global, Constify(arg0), rv)));
1001
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1002
0
    return false;
1003
0
  }
1004
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1005
0
  if (!ToJSValue(cx, result, args.rval())) {
1006
0
    return false;
1007
0
  }
1008
0
  return true;
1009
0
}
1010
1011
1012
static const JSJitInfo get_methodinfo = {
1013
  { (JSJitGetterOp)get },
1014
  { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
1015
  JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
1016
  false, false, 0
1017
};
1018
1019
MOZ_CAN_RUN_SCRIPT static bool
1020
get_onclick(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1021
0
{
1022
0
  AUTO_PROFILER_LABEL_FAST("get Notification.onclick", DOM, cx);
1023
0
1024
0
  RefPtr<EventHandlerNonNull> result(self->GetOnclick());
1025
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1026
0
  if (result) {
1027
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
1028
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
1029
0
      return false;
1030
0
    }
1031
0
    return true;
1032
0
  } else {
1033
0
    args.rval().setNull();
1034
0
    return true;
1035
0
  }
1036
0
}
1037
1038
MOZ_CAN_RUN_SCRIPT static bool
1039
set_onclick(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitSetterCallArgs args)
1040
0
{
1041
0
  AUTO_PROFILER_LABEL_FAST("set Notification.onclick", DOM, cx);
1042
0
1043
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
1044
0
  if (args[0].isObject()) {
1045
0
    { // scope for tempRoot and tempGlobalRoot if needed
1046
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
1047
0
    }
1048
0
  } else {
1049
0
    arg0 = nullptr;
1050
0
  }
1051
0
  self->SetOnclick(Constify(arg0));
1052
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1053
0
1054
0
  return true;
1055
0
}
1056
1057
static const JSJitInfo onclick_getterinfo = {
1058
  { (JSJitGetterOp)get_onclick },
1059
  { prototypes::id::Notification },
1060
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1061
  JSJitInfo::Getter,
1062
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1063
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1064
  false,  /* isInfallible. False in setters. */
1065
  false,  /* isMovable.  Not relevant for setters. */
1066
  false, /* isEliminatable.  Not relevant for setters. */
1067
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1068
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1069
  false,  /* isTypedMethod.  Only relevant for methods. */
1070
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1071
};
1072
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1073
static_assert(0 < 1, "There is no slot for us");
1074
static const JSJitInfo onclick_setterinfo = {
1075
  { (JSJitGetterOp)set_onclick },
1076
  { prototypes::id::Notification },
1077
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1078
  JSJitInfo::Setter,
1079
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1080
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1081
  false,  /* isInfallible. False in setters. */
1082
  false,  /* isMovable.  Not relevant for setters. */
1083
  false, /* isEliminatable.  Not relevant for setters. */
1084
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1085
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1086
  false,  /* isTypedMethod.  Only relevant for methods. */
1087
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1088
};
1089
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1090
static_assert(0 < 1, "There is no slot for us");
1091
1092
MOZ_CAN_RUN_SCRIPT static bool
1093
get_onshow(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1094
0
{
1095
0
  AUTO_PROFILER_LABEL_FAST("get Notification.onshow", DOM, cx);
1096
0
1097
0
  RefPtr<EventHandlerNonNull> result(self->GetOnshow());
1098
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1099
0
  if (result) {
1100
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
1101
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
1102
0
      return false;
1103
0
    }
1104
0
    return true;
1105
0
  } else {
1106
0
    args.rval().setNull();
1107
0
    return true;
1108
0
  }
1109
0
}
1110
1111
MOZ_CAN_RUN_SCRIPT static bool
1112
set_onshow(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitSetterCallArgs args)
1113
0
{
1114
0
  AUTO_PROFILER_LABEL_FAST("set Notification.onshow", DOM, cx);
1115
0
1116
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
1117
0
  if (args[0].isObject()) {
1118
0
    { // scope for tempRoot and tempGlobalRoot if needed
1119
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
1120
0
    }
1121
0
  } else {
1122
0
    arg0 = nullptr;
1123
0
  }
1124
0
  self->SetOnshow(Constify(arg0));
1125
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1126
0
1127
0
  return true;
1128
0
}
1129
1130
static const JSJitInfo onshow_getterinfo = {
1131
  { (JSJitGetterOp)get_onshow },
1132
  { prototypes::id::Notification },
1133
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1134
  JSJitInfo::Getter,
1135
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1136
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1137
  false,  /* isInfallible. False in setters. */
1138
  false,  /* isMovable.  Not relevant for setters. */
1139
  false, /* isEliminatable.  Not relevant for setters. */
1140
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1141
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1142
  false,  /* isTypedMethod.  Only relevant for methods. */
1143
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1144
};
1145
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1146
static_assert(0 < 1, "There is no slot for us");
1147
static const JSJitInfo onshow_setterinfo = {
1148
  { (JSJitGetterOp)set_onshow },
1149
  { prototypes::id::Notification },
1150
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1151
  JSJitInfo::Setter,
1152
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1153
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1154
  false,  /* isInfallible. False in setters. */
1155
  false,  /* isMovable.  Not relevant for setters. */
1156
  false, /* isEliminatable.  Not relevant for setters. */
1157
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1158
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1159
  false,  /* isTypedMethod.  Only relevant for methods. */
1160
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1161
};
1162
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1163
static_assert(0 < 1, "There is no slot for us");
1164
1165
MOZ_CAN_RUN_SCRIPT static bool
1166
get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1167
0
{
1168
0
  AUTO_PROFILER_LABEL_FAST("get Notification.onerror", DOM, cx);
1169
0
1170
0
  RefPtr<EventHandlerNonNull> result(self->GetOnerror());
1171
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1172
0
  if (result) {
1173
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
1174
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
1175
0
      return false;
1176
0
    }
1177
0
    return true;
1178
0
  } else {
1179
0
    args.rval().setNull();
1180
0
    return true;
1181
0
  }
1182
0
}
1183
1184
MOZ_CAN_RUN_SCRIPT static bool
1185
set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitSetterCallArgs args)
1186
0
{
1187
0
  AUTO_PROFILER_LABEL_FAST("set Notification.onerror", DOM, cx);
1188
0
1189
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
1190
0
  if (args[0].isObject()) {
1191
0
    { // scope for tempRoot and tempGlobalRoot if needed
1192
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
1193
0
    }
1194
0
  } else {
1195
0
    arg0 = nullptr;
1196
0
  }
1197
0
  self->SetOnerror(Constify(arg0));
1198
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1199
0
1200
0
  return true;
1201
0
}
1202
1203
static const JSJitInfo onerror_getterinfo = {
1204
  { (JSJitGetterOp)get_onerror },
1205
  { prototypes::id::Notification },
1206
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1207
  JSJitInfo::Getter,
1208
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1209
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1210
  false,  /* isInfallible. False in setters. */
1211
  false,  /* isMovable.  Not relevant for setters. */
1212
  false, /* isEliminatable.  Not relevant for setters. */
1213
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1214
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1215
  false,  /* isTypedMethod.  Only relevant for methods. */
1216
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1217
};
1218
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1219
static_assert(0 < 1, "There is no slot for us");
1220
static const JSJitInfo onerror_setterinfo = {
1221
  { (JSJitGetterOp)set_onerror },
1222
  { prototypes::id::Notification },
1223
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1224
  JSJitInfo::Setter,
1225
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1226
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1227
  false,  /* isInfallible. False in setters. */
1228
  false,  /* isMovable.  Not relevant for setters. */
1229
  false, /* isEliminatable.  Not relevant for setters. */
1230
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1231
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1232
  false,  /* isTypedMethod.  Only relevant for methods. */
1233
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1234
};
1235
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1236
static_assert(0 < 1, "There is no slot for us");
1237
1238
MOZ_CAN_RUN_SCRIPT static bool
1239
get_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1240
0
{
1241
0
  AUTO_PROFILER_LABEL_FAST("get Notification.onclose", DOM, cx);
1242
0
1243
0
  RefPtr<EventHandlerNonNull> result(self->GetOnclose());
1244
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1245
0
  if (result) {
1246
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
1247
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
1248
0
      return false;
1249
0
    }
1250
0
    return true;
1251
0
  } else {
1252
0
    args.rval().setNull();
1253
0
    return true;
1254
0
  }
1255
0
}
1256
1257
MOZ_CAN_RUN_SCRIPT static bool
1258
set_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitSetterCallArgs args)
1259
0
{
1260
0
  AUTO_PROFILER_LABEL_FAST("set Notification.onclose", DOM, cx);
1261
0
1262
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
1263
0
  if (args[0].isObject()) {
1264
0
    { // scope for tempRoot and tempGlobalRoot if needed
1265
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
1266
0
    }
1267
0
  } else {
1268
0
    arg0 = nullptr;
1269
0
  }
1270
0
  self->SetOnclose(Constify(arg0));
1271
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1272
0
1273
0
  return true;
1274
0
}
1275
1276
static const JSJitInfo onclose_getterinfo = {
1277
  { (JSJitGetterOp)get_onclose },
1278
  { prototypes::id::Notification },
1279
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1280
  JSJitInfo::Getter,
1281
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1282
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1283
  false,  /* isInfallible. False in setters. */
1284
  false,  /* isMovable.  Not relevant for setters. */
1285
  false, /* isEliminatable.  Not relevant for setters. */
1286
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1287
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1288
  false,  /* isTypedMethod.  Only relevant for methods. */
1289
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1290
};
1291
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1292
static_assert(0 < 1, "There is no slot for us");
1293
static const JSJitInfo onclose_setterinfo = {
1294
  { (JSJitGetterOp)set_onclose },
1295
  { prototypes::id::Notification },
1296
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1297
  JSJitInfo::Setter,
1298
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1299
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1300
  false,  /* isInfallible. False in setters. */
1301
  false,  /* isMovable.  Not relevant for setters. */
1302
  false, /* isEliminatable.  Not relevant for setters. */
1303
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1304
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1305
  false,  /* isTypedMethod.  Only relevant for methods. */
1306
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1307
};
1308
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1309
static_assert(0 < 1, "There is no slot for us");
1310
1311
MOZ_CAN_RUN_SCRIPT static bool
1312
get_title(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1313
0
{
1314
0
  AUTO_PROFILER_LABEL_FAST("get Notification.title", DOM, cx);
1315
0
1316
0
  DOMString result;
1317
0
  self->GetTitle(result);
1318
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1319
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
1320
0
    return false;
1321
0
  }
1322
0
  return true;
1323
0
}
1324
1325
static const JSJitInfo title_getterinfo = {
1326
  { (JSJitGetterOp)get_title },
1327
  { prototypes::id::Notification },
1328
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1329
  JSJitInfo::Getter,
1330
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1331
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1332
  false,  /* isInfallible. False in setters. */
1333
  true,  /* isMovable.  Not relevant for setters. */
1334
  true, /* isEliminatable.  Not relevant for setters. */
1335
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1336
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1337
  false,  /* isTypedMethod.  Only relevant for methods. */
1338
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1339
};
1340
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1341
static_assert(0 < 1, "There is no slot for us");
1342
1343
MOZ_CAN_RUN_SCRIPT static bool
1344
get_dir(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1345
0
{
1346
0
  AUTO_PROFILER_LABEL_FAST("get Notification.dir", DOM, cx);
1347
0
1348
0
  NotificationDirection result(self->Dir());
1349
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1350
0
  if (!ToJSValue(cx, result, args.rval())) {
1351
0
    return false;
1352
0
  }
1353
0
  return true;
1354
0
}
1355
1356
static const JSJitInfo dir_getterinfo = {
1357
  { (JSJitGetterOp)get_dir },
1358
  { prototypes::id::Notification },
1359
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1360
  JSJitInfo::Getter,
1361
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1362
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
1363
  false,  /* isInfallible. False in setters. */
1364
  true,  /* isMovable.  Not relevant for setters. */
1365
  true, /* isEliminatable.  Not relevant for setters. */
1366
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1367
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1368
  false,  /* isTypedMethod.  Only relevant for methods. */
1369
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1370
};
1371
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1372
static_assert(0 < 1, "There is no slot for us");
1373
1374
MOZ_CAN_RUN_SCRIPT static bool
1375
get_lang(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1376
0
{
1377
0
  AUTO_PROFILER_LABEL_FAST("get Notification.lang", DOM, cx);
1378
0
1379
0
  DOMString result;
1380
0
  self->GetLang(result);
1381
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1382
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
1383
0
    return false;
1384
0
  }
1385
0
  return true;
1386
0
}
1387
1388
static const JSJitInfo lang_getterinfo = {
1389
  { (JSJitGetterOp)get_lang },
1390
  { prototypes::id::Notification },
1391
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1392
  JSJitInfo::Getter,
1393
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1394
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1395
  false,  /* isInfallible. False in setters. */
1396
  true,  /* isMovable.  Not relevant for setters. */
1397
  true, /* isEliminatable.  Not relevant for setters. */
1398
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1399
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1400
  false,  /* isTypedMethod.  Only relevant for methods. */
1401
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1402
};
1403
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1404
static_assert(0 < 1, "There is no slot for us");
1405
1406
MOZ_CAN_RUN_SCRIPT static bool
1407
get_body(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1408
0
{
1409
0
  AUTO_PROFILER_LABEL_FAST("get Notification.body", DOM, cx);
1410
0
1411
0
  DOMString result;
1412
0
  self->GetBody(result);
1413
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1414
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
1415
0
    return false;
1416
0
  }
1417
0
  return true;
1418
0
}
1419
1420
static const JSJitInfo body_getterinfo = {
1421
  { (JSJitGetterOp)get_body },
1422
  { prototypes::id::Notification },
1423
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1424
  JSJitInfo::Getter,
1425
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1426
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1427
  false,  /* isInfallible. False in setters. */
1428
  true,  /* isMovable.  Not relevant for setters. */
1429
  true, /* isEliminatable.  Not relevant for setters. */
1430
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1431
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1432
  false,  /* isTypedMethod.  Only relevant for methods. */
1433
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1434
};
1435
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1436
static_assert(0 < 1, "There is no slot for us");
1437
1438
MOZ_CAN_RUN_SCRIPT static bool
1439
get_tag(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1440
0
{
1441
0
  AUTO_PROFILER_LABEL_FAST("get Notification.tag", DOM, cx);
1442
0
1443
0
  DOMString result;
1444
0
  self->GetTag(result);
1445
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1446
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
1447
0
    return false;
1448
0
  }
1449
0
  return true;
1450
0
}
1451
1452
static const JSJitInfo tag_getterinfo = {
1453
  { (JSJitGetterOp)get_tag },
1454
  { prototypes::id::Notification },
1455
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1456
  JSJitInfo::Getter,
1457
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
1458
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1459
  false,  /* isInfallible. False in setters. */
1460
  true,  /* isMovable.  Not relevant for setters. */
1461
  true, /* isEliminatable.  Not relevant for setters. */
1462
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1463
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1464
  false,  /* isTypedMethod.  Only relevant for methods. */
1465
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1466
};
1467
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1468
static_assert(0 < 1, "There is no slot for us");
1469
1470
MOZ_CAN_RUN_SCRIPT static bool
1471
get_icon(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1472
0
{
1473
0
  AUTO_PROFILER_LABEL_FAST("get Notification.icon", DOM, cx);
1474
0
1475
0
  DOMString result;
1476
0
  self->GetIcon(result);
1477
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1478
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
1479
0
    return false;
1480
0
  }
1481
0
  return true;
1482
0
}
1483
1484
static const JSJitInfo icon_getterinfo = {
1485
  { (JSJitGetterOp)get_icon },
1486
  { prototypes::id::Notification },
1487
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1488
  JSJitInfo::Getter,
1489
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1490
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1491
  false,  /* isInfallible. False in setters. */
1492
  true,  /* isMovable.  Not relevant for setters. */
1493
  true, /* isEliminatable.  Not relevant for setters. */
1494
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1495
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1496
  false,  /* isTypedMethod.  Only relevant for methods. */
1497
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1498
};
1499
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1500
static_assert(0 < 1, "There is no slot for us");
1501
1502
MOZ_CAN_RUN_SCRIPT static bool
1503
get_requireInteraction(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1504
0
{
1505
0
  AUTO_PROFILER_LABEL_FAST("get Notification.requireInteraction", DOM, cx);
1506
0
1507
0
  bool result(self->RequireInteraction());
1508
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1509
0
  args.rval().setBoolean(result);
1510
0
  return true;
1511
0
}
1512
1513
static const JSJitInfo requireInteraction_getterinfo = {
1514
  { (JSJitGetterOp)get_requireInteraction },
1515
  { prototypes::id::Notification },
1516
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1517
  JSJitInfo::Getter,
1518
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
1519
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1520
  true,  /* isInfallible. False in setters. */
1521
  true,  /* isMovable.  Not relevant for setters. */
1522
  true, /* isEliminatable.  Not relevant for setters. */
1523
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1524
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1525
  false,  /* isTypedMethod.  Only relevant for methods. */
1526
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1527
};
1528
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1529
static_assert(0 < 1, "There is no slot for us");
1530
1531
MOZ_CAN_RUN_SCRIPT static bool
1532
get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, JSJitGetterCallArgs args)
1533
0
{
1534
0
  AUTO_PROFILER_LABEL_FAST("get Notification.data", DOM, cx);
1535
0
1536
0
  JS::Rooted<JS::Value> result(cx);
1537
0
  self->GetData(cx, &result);
1538
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1539
0
  JS::ExposeValueToActiveJS(result);
1540
0
  args.rval().set(result);
1541
0
  if (!MaybeWrapValue(cx, args.rval())) {
1542
0
    return false;
1543
0
  }
1544
0
  return true;
1545
0
}
1546
1547
static const JSJitInfo data_getterinfo = {
1548
  { (JSJitGetterOp)get_data },
1549
  { prototypes::id::Notification },
1550
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1551
  JSJitInfo::Getter,
1552
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
1553
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1554
  false,  /* isInfallible. False in setters. */
1555
  true,  /* isMovable.  Not relevant for setters. */
1556
  true, /* isEliminatable.  Not relevant for setters. */
1557
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1558
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1559
  false,  /* isTypedMethod.  Only relevant for methods. */
1560
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1561
};
1562
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1563
static_assert(0 < 1, "There is no slot for us");
1564
1565
MOZ_CAN_RUN_SCRIPT static bool
1566
close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Notification* self, const JSJitMethodCallArgs& args)
1567
0
{
1568
0
  AUTO_PROFILER_LABEL_FAST("Notification.close", DOM, cx);
1569
0
1570
0
  self->Close();
1571
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1572
0
  args.rval().setUndefined();
1573
0
  return true;
1574
0
}
1575
1576
static const JSJitInfo close_methodinfo = {
1577
  { (JSJitGetterOp)close },
1578
  { prototypes::id::Notification },
1579
  { PrototypeTraits<prototypes::id::Notification>::Depth },
1580
  JSJitInfo::Method,
1581
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1582
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1583
  true,  /* isInfallible. False in setters. */
1584
  false,  /* isMovable.  Not relevant for setters. */
1585
  false, /* isEliminatable.  Not relevant for setters. */
1586
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1587
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1588
  false,  /* isTypedMethod.  Only relevant for methods. */
1589
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1590
};
1591
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1592
static_assert(0 < 1, "There is no slot for us");
1593
1594
static bool
1595
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1596
0
{
1597
0
  mozilla::dom::Notification* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Notification>(obj);
1598
0
  // We don't want to preserve if we don't have a wrapper, and we
1599
0
  // obviously can't preserve if we're not initialized.
1600
0
  if (self && self->GetWrapperPreserveColor()) {
1601
0
    PreserveWrapper(self);
1602
0
  }
1603
0
  return true;
1604
0
}
1605
1606
static void
1607
_finalize(js::FreeOp* fop, JSObject* obj)
1608
0
{
1609
0
  mozilla::dom::Notification* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Notification>(obj);
1610
0
  if (self) {
1611
0
    ClearWrapper(self, self, obj);
1612
0
    AddForDeferredFinalization<mozilla::dom::Notification>(self);
1613
0
  }
1614
0
}
1615
1616
static size_t
1617
_objectMoved(JSObject* obj, JSObject* old)
1618
0
{
1619
0
  mozilla::dom::Notification* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Notification>(obj);
1620
0
  if (self) {
1621
0
    UpdateWrapper(self, self, obj, old);
1622
0
  }
1623
0
1624
0
  return 0;
1625
0
}
1626
1627
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1628
#if defined(__clang__)
1629
#pragma clang diagnostic push
1630
#pragma clang diagnostic ignored "-Wmissing-braces"
1631
#endif
1632
static const JSFunctionSpec sStaticMethods_specs[] = {
1633
  JS_FNSPEC("requestPermission", StaticMethodPromiseWrapper, &requestPermission_methodinfo, 0, JSPROP_ENUMERATE, nullptr),
1634
  JS_FS_END,
1635
  JS_FNSPEC("get", StaticMethodPromiseWrapper, &get_methodinfo, 0, JSPROP_ENUMERATE, nullptr),
1636
  JS_FS_END
1637
};
1638
#if defined(__clang__)
1639
#pragma clang diagnostic pop
1640
#endif
1641
1642
// Can't be const because the pref-enabled boolean needs to be writable
1643
static PrefableDisablers sStaticMethods_disablers0 = {
1644
  true, false, 0, &mozilla::dom::Notification::RequestPermissionEnabledForScope
1645
};
1646
1647
// Can't be const because the pref-enabled boolean needs to be writable
1648
static PrefableDisablers sStaticMethods_disablers2 = {
1649
  true, false, 0, &mozilla::dom::Notification::IsGetEnabled
1650
};
1651
1652
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
1653
  { &sStaticMethods_disablers0, &sStaticMethods_specs[0] },
1654
  { &sStaticMethods_disablers2, &sStaticMethods_specs[2] },
1655
  { nullptr, nullptr }
1656
};
1657
1658
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1659
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1660
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1661
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1662
1663
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1664
#if defined(__clang__)
1665
#pragma clang diagnostic push
1666
#pragma clang diagnostic ignored "-Wmissing-braces"
1667
#endif
1668
static const JSPropertySpec sStaticAttributes_specs[] = {
1669
  { "permission", JSPROP_ENUMERATE, get_permission, nullptr, nullptr, nullptr },
1670
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1671
};
1672
#if defined(__clang__)
1673
#pragma clang diagnostic pop
1674
#endif
1675
1676
1677
static const Prefable<const JSPropertySpec> sStaticAttributes[] = {
1678
  { nullptr, &sStaticAttributes_specs[0] },
1679
  { nullptr, nullptr }
1680
};
1681
1682
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1683
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1684
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1685
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1686
1687
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1688
#if defined(__clang__)
1689
#pragma clang diagnostic push
1690
#pragma clang diagnostic ignored "-Wmissing-braces"
1691
#endif
1692
static const JSFunctionSpec sMethods_specs[] = {
1693
  JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1694
  JS_FS_END
1695
};
1696
#if defined(__clang__)
1697
#pragma clang diagnostic pop
1698
#endif
1699
1700
1701
static const Prefable<const JSFunctionSpec> sMethods[] = {
1702
  { nullptr, &sMethods_specs[0] },
1703
  { nullptr, nullptr }
1704
};
1705
1706
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1707
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1708
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1709
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1710
1711
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1712
#if defined(__clang__)
1713
#pragma clang diagnostic push
1714
#pragma clang diagnostic ignored "-Wmissing-braces"
1715
#endif
1716
static const JSPropertySpec sAttributes_specs[] = {
1717
  { "onclick", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onclick_getterinfo, GenericSetter<NormalThisPolicy>, &onclick_setterinfo },
1718
  { "onshow", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onshow_getterinfo, GenericSetter<NormalThisPolicy>, &onshow_setterinfo },
1719
  { "onerror", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onerror_getterinfo, GenericSetter<NormalThisPolicy>, &onerror_setterinfo },
1720
  { "onclose", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onclose_getterinfo, GenericSetter<NormalThisPolicy>, &onclose_setterinfo },
1721
  { "title", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &title_getterinfo, nullptr, nullptr },
1722
  { "dir", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &dir_getterinfo, nullptr, nullptr },
1723
  { "lang", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &lang_getterinfo, nullptr, nullptr },
1724
  { "body", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &body_getterinfo, nullptr, nullptr },
1725
  { "tag", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &tag_getterinfo, nullptr, nullptr },
1726
  { "icon", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &icon_getterinfo, nullptr, nullptr },
1727
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
1728
  { "requireInteraction", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &requireInteraction_getterinfo, nullptr, nullptr },
1729
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
1730
  { "data", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &data_getterinfo, nullptr, nullptr },
1731
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1732
};
1733
#if defined(__clang__)
1734
#pragma clang diagnostic pop
1735
#endif
1736
1737
// Can't be const because the pref-enabled boolean needs to be writable
1738
static PrefableDisablers sAttributes_disablers11 = {
1739
  true, false, 0, &mozilla::dom::DOMPrefs::dom_webnotifications_requireinteraction_enabled
1740
};
1741
1742
static const Prefable<const JSPropertySpec> sAttributes[] = {
1743
  { nullptr, &sAttributes_specs[0] },
1744
  { &sAttributes_disablers11, &sAttributes_specs[11] },
1745
  { nullptr, &sAttributes_specs[13] },
1746
  { nullptr, nullptr }
1747
};
1748
1749
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1750
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1751
static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1752
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1753
1754
1755
static uint16_t sNativeProperties_sortedPropertyIndices[16];
1756
static PropertyInfo sNativeProperties_propertyInfos[16];
1757
1758
static const NativePropertiesN<4> sNativeProperties = {
1759
  true,  0 /* sStaticMethods */,
1760
  true,  1 /* sStaticAttributes */,
1761
  true,  2 /* sMethods */,
1762
  true,  3 /* sAttributes */,
1763
  false, 0,
1764
  false, 0,
1765
  false, 0,
1766
  -1,
1767
  16,
1768
  sNativeProperties_sortedPropertyIndices,
1769
  {
1770
    { sStaticMethods, &sNativeProperties_propertyInfos[0] },
1771
    { sStaticAttributes, &sNativeProperties_propertyInfos[2] },
1772
    { sMethods, &sNativeProperties_propertyInfos[3] },
1773
    { sAttributes, &sNativeProperties_propertyInfos[4] }
1774
  }
1775
};
1776
static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1777
    "We have a property info count that is oversized");
1778
1779
static bool
1780
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1781
0
{
1782
0
  AUTO_PROFILER_LABEL_FAST("Notification constructor", DOM, cx);
1783
0
1784
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1785
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1786
0
  if (!args.isConstructing()) {
1787
0
    // XXXbz wish I could get the name from the callee instead of
1788
0
    // Adding more relocations
1789
0
    return ThrowConstructorWithoutNew(cx, "Notification");
1790
0
  }
1791
0
1792
0
  JS::Rooted<JSObject*> desiredProto(cx);
1793
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1794
0
    return false;
1795
0
  }
1796
0
1797
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1798
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Notification");
1799
0
  }
1800
0
  GlobalObject global(cx, obj);
1801
0
  if (global.Failed()) {
1802
0
    return false;
1803
0
  }
1804
0
1805
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1806
0
  binding_detail::FakeString arg0;
1807
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1808
0
    return false;
1809
0
  }
1810
0
  RootedDictionary<binding_detail::FastNotificationOptions> arg1(cx);
1811
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Notification.constructor", false)) {
1812
0
    return false;
1813
0
  }
1814
0
  Maybe<JSAutoRealm> ar;
1815
0
  if (objIsXray) {
1816
0
    obj = js::CheckedUnwrap(obj);
1817
0
    if (!obj) {
1818
0
      return false;
1819
0
    }
1820
0
    ar.emplace(cx, obj);
1821
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1822
0
      return false;
1823
0
    }
1824
0
    if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg1.mData))) {
1825
0
      return false;
1826
0
    }
1827
0
  }
1828
0
  FastErrorResult rv;
1829
0
  auto result(StrongOrRawPtr<mozilla::dom::Notification>(mozilla::dom::Notification::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
1830
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1831
0
    return false;
1832
0
  }
1833
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1834
0
  static_assert(!IsPointer<decltype(result)>::value,
1835
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1836
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1837
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1838
0
    return false;
1839
0
  }
1840
0
  return true;
1841
0
}
1842
1843
static const js::ClassOps sInterfaceObjectClassOps = {
1844
    nullptr,               /* addProperty */
1845
    nullptr,               /* delProperty */
1846
    nullptr,               /* enumerate */
1847
    nullptr,               /* newEnumerate */
1848
    nullptr,               /* resolve */
1849
    nullptr,               /* mayResolve */
1850
    nullptr,               /* finalize */
1851
    _constructor, /* call */
1852
    nullptr,               /* hasInstance */
1853
    _constructor, /* construct */
1854
    nullptr,               /* trace */
1855
};
1856
1857
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1858
  {
1859
    "Function",
1860
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1861
    &sInterfaceObjectClassOps,
1862
    JS_NULL_CLASS_SPEC,
1863
    JS_NULL_CLASS_EXT,
1864
    &sInterfaceObjectClassObjectOps
1865
  },
1866
  eInterface,
1867
  true,
1868
  prototypes::id::Notification,
1869
  PrototypeTraits<prototypes::id::Notification>::Depth,
1870
  sNativePropertyHooks,
1871
  "function Notification() {\n    [native code]\n}",
1872
  EventTarget_Binding::GetConstructorObject
1873
};
1874
1875
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1876
  {
1877
    "NotificationPrototype",
1878
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1879
    JS_NULL_CLASS_OPS,
1880
    JS_NULL_CLASS_SPEC,
1881
    JS_NULL_CLASS_EXT,
1882
    JS_NULL_OBJECT_OPS
1883
  },
1884
  eInterfacePrototype,
1885
  false,
1886
  prototypes::id::Notification,
1887
  PrototypeTraits<prototypes::id::Notification>::Depth,
1888
  sNativePropertyHooks,
1889
  "[object NotificationPrototype]",
1890
  EventTarget_Binding::GetProtoObject
1891
};
1892
1893
bool
1894
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1895
0
{
1896
0
  return mozilla::dom::Notification::PrefEnabled(aCx, aObj);
1897
0
}
1898
1899
static const js::ClassOps sClassOps = {
1900
  _addProperty, /* addProperty */
1901
  nullptr,               /* delProperty */
1902
  nullptr,               /* enumerate */
1903
  nullptr, /* newEnumerate */
1904
  nullptr, /* resolve */
1905
  nullptr, /* mayResolve */
1906
  _finalize, /* finalize */
1907
  nullptr, /* call */
1908
  nullptr,               /* hasInstance */
1909
  nullptr,               /* construct */
1910
  nullptr, /* trace */
1911
};
1912
1913
static const js::ClassExtension sClassExtension = {
1914
  nullptr, /* weakmapKeyDelegateOp */
1915
  _objectMoved /* objectMovedOp */
1916
};
1917
1918
static const DOMJSClass sClass = {
1919
  { "Notification",
1920
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1921
    &sClassOps,
1922
    JS_NULL_CLASS_SPEC,
1923
    &sClassExtension,
1924
    JS_NULL_OBJECT_OPS
1925
  },
1926
  { prototypes::id::EventTarget, prototypes::id::Notification, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1927
  IsBaseOf<nsISupports, mozilla::dom::Notification >::value,
1928
  sNativePropertyHooks,
1929
  FindAssociatedGlobalForNative<mozilla::dom::Notification>::Get,
1930
  GetProtoObjectHandle,
1931
  GetCCParticipant<mozilla::dom::Notification>::Get()
1932
};
1933
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1934
              "Must have the right minimal number of reserved slots.");
1935
static_assert(1 >= 1,
1936
              "Must have enough reserved slots.");
1937
1938
const JSClass*
1939
GetJSClass()
1940
0
{
1941
0
  return sClass.ToJSClass();
1942
0
}
1943
1944
bool
1945
Wrap(JSContext* aCx, mozilla::dom::Notification* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1946
0
{
1947
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Notification>::value,
1948
0
                "Shouldn't have wrappercached things that are not refcounted.");
1949
0
  MOZ_ASSERT(static_cast<mozilla::dom::Notification*>(aObject) ==
1950
0
             reinterpret_cast<mozilla::dom::Notification*>(aObject),
1951
0
             "Multiple inheritance for mozilla::dom::Notification is broken.");
1952
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
1953
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
1954
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
1955
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1956
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1957
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1958
0
             "You should probably not be using Wrap() directly; use "
1959
0
             "GetOrCreateDOMReflector instead");
1960
0
1961
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1962
0
             "nsISupports must be on our primary inheritance chain");
1963
0
1964
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1965
0
  if (!global) {
1966
0
    return false;
1967
0
  }
1968
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1969
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1970
0
1971
0
  // That might have ended up wrapping us already, due to the wonders
1972
0
  // of XBL.  Check for that, and bail out as needed.
1973
0
  aReflector.set(aCache->GetWrapper());
1974
0
  if (aReflector) {
1975
#ifdef DEBUG
1976
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1977
#endif // DEBUG
1978
    return true;
1979
0
  }
1980
0
1981
0
  JSAutoRealm ar(aCx, global);
1982
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1983
0
  if (!canonicalProto) {
1984
0
    return false;
1985
0
  }
1986
0
  JS::Rooted<JSObject*> proto(aCx);
1987
0
  if (aGivenProto) {
1988
0
    proto = aGivenProto;
1989
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1990
0
    // coming in, we changed compartments to that of "parent" so may need
1991
0
    // to wrap the proto here.
1992
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1993
0
      if (!JS_WrapObject(aCx, &proto)) {
1994
0
        return false;
1995
0
      }
1996
0
    }
1997
0
  } else {
1998
0
    proto = canonicalProto;
1999
0
  }
2000
0
2001
0
  BindingJSObjectCreator<mozilla::dom::Notification> creator(aCx);
2002
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
2003
0
  if (!aReflector) {
2004
0
    return false;
2005
0
  }
2006
0
2007
0
  aCache->SetWrapper(aReflector);
2008
0
  creator.InitializationSucceeded();
2009
0
2010
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
2011
0
             aCache->GetWrapperPreserveColor() == aReflector);
2012
0
  // If proto != canonicalProto, we have to preserve our wrapper;
2013
0
  // otherwise we won't be able to properly recreate it later, since
2014
0
  // we won't know what proto to use.  Note that we don't check
2015
0
  // aGivenProto here, since it's entirely possible (and even
2016
0
  // somewhat common) to have a non-null aGivenProto which is the
2017
0
  // same as canonicalProto.
2018
0
  if (proto != canonicalProto) {
2019
0
    PreserveWrapper(aObject);
2020
0
  }
2021
0
2022
0
  return true;
2023
0
}
2024
2025
const NativePropertyHooks sNativePropertyHooks[] = { {
2026
  nullptr,
2027
  nullptr,
2028
  nullptr,
2029
  { sNativeProperties.Upcast(), nullptr },
2030
  prototypes::id::Notification,
2031
  constructors::id::Notification,
2032
  EventTarget_Binding::sNativePropertyHooks,
2033
  &DefaultXrayExpandoObjectClass
2034
} };
2035
2036
void
2037
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
2038
0
{
2039
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
2040
0
  if (!parentProto) {
2041
0
    return;
2042
0
  }
2043
0
2044
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
2045
0
  if (!constructorProto) {
2046
0
    return;
2047
0
  }
2048
0
2049
0
  static bool sIdsInited = false;
2050
0
  if (!sIdsInited && NS_IsMainThread()) {
2051
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
2052
0
      return;
2053
0
    }
2054
0
    sIdsInited = true;
2055
0
  }
2056
0
2057
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Notification);
2058
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Notification);
2059
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
2060
0
                              &sPrototypeClass.mBase, protoCache,
2061
0
                              nullptr,
2062
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
2063
0
                              interfaceCache,
2064
0
                              sNativeProperties.Upcast(),
2065
0
                              nullptr,
2066
0
                              "Notification", aDefineOnGlobal,
2067
0
                              nullptr,
2068
0
                              false);
2069
0
}
2070
2071
JSObject*
2072
GetConstructorObject(JSContext* aCx)
2073
0
{
2074
0
  return GetConstructorObjectHandle(aCx);
2075
0
}
2076
2077
} // namespace Notification_Binding
2078
2079
2080
2081
} // namespace dom
2082
} // namespace mozilla