Coverage Report

Created: 2018-09-25 14:53

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