Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MozDocumentObserverBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MozDocumentObserver.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "MozDocumentObserverBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/NonRefcountedDOMObject.h"
10
#include "mozilla/extensions/DocumentObserver.h"
11
#include "mozilla/extensions/WebExtensionContentScript.h"
12
#include "nsContentUtils.h"
13
#include "nsILoadInfo.h"
14
#include "nsPIDOMWindow.h"
15
#include "nsThreadUtils.h"
16
17
namespace mozilla {
18
namespace dom {
19
20
namespace binding_detail {}; // Just to make sure it's known as a namespace
21
using namespace mozilla::dom::binding_detail;
22
23
24
namespace MozDocumentObserver_Binding {
25
26
MOZ_CAN_RUN_SCRIPT static bool
27
observe(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::DocumentObserver* self, const JSJitMethodCallArgs& args)
28
0
{
29
0
  AUTO_PROFILER_LABEL_FAST("MozDocumentObserver.observe", DOM, cx);
30
0
31
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
32
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MozDocumentObserver.observe");
33
0
  }
34
0
  binding_detail::AutoSequence<OwningNonNull<mozilla::extensions::MozDocumentMatcher>> arg0;
35
0
  if (args[0].isObject()) {
36
0
    JS::ForOfIterator iter(cx);
37
0
    if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
38
0
      return false;
39
0
    }
40
0
    if (!iter.valueIsIterable()) {
41
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of MozDocumentObserver.observe");
42
0
      return false;
43
0
    }
44
0
    binding_detail::AutoSequence<OwningNonNull<mozilla::extensions::MozDocumentMatcher>> &arr = arg0;
45
0
    JS::Rooted<JS::Value> temp(cx);
46
0
    while (true) {
47
0
      bool done;
48
0
      if (!iter.next(&temp, &done)) {
49
0
        return false;
50
0
      }
51
0
      if (done) {
52
0
        break;
53
0
      }
54
0
      OwningNonNull<mozilla::extensions::MozDocumentMatcher>* slotPtr = arr.AppendElement(mozilla::fallible);
55
0
      if (!slotPtr) {
56
0
        JS_ReportOutOfMemory(cx);
57
0
        return false;
58
0
      }
59
0
      OwningNonNull<mozilla::extensions::MozDocumentMatcher>& slot = *slotPtr;
60
0
      if (temp.isObject()) {
61
0
        static_assert(IsRefcounted<mozilla::extensions::MozDocumentMatcher>::value, "We can only store refcounted classes.");{
62
0
          nsresult rv = UnwrapObject<prototypes::id::MozDocumentMatcher, mozilla::extensions::MozDocumentMatcher>(&temp, slot);
63
0
          if (NS_FAILED(rv)) {
64
0
            ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of argument 1 of MozDocumentObserver.observe", "MozDocumentMatcher");
65
0
            return false;
66
0
          }
67
0
        }
68
0
      } else {
69
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 1 of MozDocumentObserver.observe");
70
0
        return false;
71
0
      }
72
0
    }
73
0
  } else {
74
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of MozDocumentObserver.observe");
75
0
    return false;
76
0
  }
77
0
  FastErrorResult rv;
78
0
  self->Observe(Constify(arg0), rv);
79
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
80
0
    return false;
81
0
  }
82
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
83
0
  args.rval().setUndefined();
84
0
  return true;
85
0
}
86
87
static const JSJitInfo observe_methodinfo = {
88
  { (JSJitGetterOp)observe },
89
  { prototypes::id::MozDocumentObserver },
90
  { PrototypeTraits<prototypes::id::MozDocumentObserver>::Depth },
91
  JSJitInfo::Method,
92
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
93
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
94
  false,  /* isInfallible. False in setters. */
95
  false,  /* isMovable.  Not relevant for setters. */
96
  false, /* isEliminatable.  Not relevant for setters. */
97
  false, /* isAlwaysInSlot.  Only relevant for getters. */
98
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
99
  false,  /* isTypedMethod.  Only relevant for methods. */
100
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
101
};
102
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
103
static_assert(0 < 1, "There is no slot for us");
104
105
MOZ_CAN_RUN_SCRIPT static bool
106
disconnect(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::extensions::DocumentObserver* self, const JSJitMethodCallArgs& args)
107
0
{
108
0
  AUTO_PROFILER_LABEL_FAST("MozDocumentObserver.disconnect", DOM, cx);
109
0
110
0
  self->Disconnect();
111
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
112
0
  args.rval().setUndefined();
113
0
  return true;
114
0
}
115
116
static const JSJitInfo disconnect_methodinfo = {
117
  { (JSJitGetterOp)disconnect },
118
  { prototypes::id::MozDocumentObserver },
119
  { PrototypeTraits<prototypes::id::MozDocumentObserver>::Depth },
120
  JSJitInfo::Method,
121
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
122
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
123
  true,  /* isInfallible. False in setters. */
124
  false,  /* isMovable.  Not relevant for setters. */
125
  false, /* isEliminatable.  Not relevant for setters. */
126
  false, /* isAlwaysInSlot.  Only relevant for getters. */
127
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
128
  false,  /* isTypedMethod.  Only relevant for methods. */
129
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
130
};
131
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
132
static_assert(0 < 1, "There is no slot for us");
133
134
static bool
135
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
136
0
{
137
0
  mozilla::extensions::DocumentObserver* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::extensions::DocumentObserver>(obj);
138
0
  // We don't want to preserve if we don't have a wrapper, and we
139
0
  // obviously can't preserve if we're not initialized.
140
0
  if (self && self->GetWrapperPreserveColor()) {
141
0
    PreserveWrapper(self);
142
0
  }
143
0
  return true;
144
0
}
145
146
static void
147
_finalize(js::FreeOp* fop, JSObject* obj)
148
0
{
149
0
  mozilla::extensions::DocumentObserver* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::extensions::DocumentObserver>(obj);
150
0
  if (self) {
151
0
    ClearWrapper(self, self, obj);
152
0
    AddForDeferredFinalization<mozilla::extensions::DocumentObserver>(self);
153
0
  }
154
0
}
155
156
static size_t
157
_objectMoved(JSObject* obj, JSObject* old)
158
0
{
159
0
  mozilla::extensions::DocumentObserver* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::extensions::DocumentObserver>(obj);
160
0
  if (self) {
161
0
    UpdateWrapper(self, self, obj, old);
162
0
  }
163
0
164
0
  return 0;
165
0
}
166
167
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
168
#if defined(__clang__)
169
#pragma clang diagnostic push
170
#pragma clang diagnostic ignored "-Wmissing-braces"
171
#endif
172
static const JSFunctionSpec sMethods_specs[] = {
173
  JS_FNSPEC("observe", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&observe_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
174
  JS_FNSPEC("disconnect", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&disconnect_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
175
  JS_FS_END
176
};
177
#if defined(__clang__)
178
#pragma clang diagnostic pop
179
#endif
180
181
182
static const Prefable<const JSFunctionSpec> sMethods[] = {
183
  { nullptr, &sMethods_specs[0] },
184
  { nullptr, nullptr }
185
};
186
187
188
static const NativePropertiesN<1> sNativeProperties = {
189
  false, 0,
190
  false, 0,
191
  true,  0 /* sMethods */,
192
  false, 0,
193
  false, 0,
194
  false, 0,
195
  false, 0,
196
  -1,
197
  0,
198
  nullptr,
199
  {
200
    { sMethods, nullptr }
201
  }
202
};
203
204
static bool
205
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
206
0
{
207
0
  AUTO_PROFILER_LABEL_FAST("MozDocumentObserver constructor", DOM, cx);
208
0
209
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
210
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
211
0
  if (!args.isConstructing()) {
212
0
    // XXXbz wish I could get the name from the callee instead of
213
0
    // Adding more relocations
214
0
    return ThrowConstructorWithoutNew(cx, "MozDocumentObserver");
215
0
  }
216
0
217
0
  JS::Rooted<JSObject*> desiredProto(cx);
218
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
219
0
    return false;
220
0
  }
221
0
222
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
223
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MozDocumentObserver");
224
0
  }
225
0
  GlobalObject global(cx, obj);
226
0
  if (global.Failed()) {
227
0
    return false;
228
0
  }
229
0
230
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
231
0
  RootedCallback<OwningNonNull<binding_detail::FastMozDocumentCallback>> arg0(cx);
232
0
  if (args[0].isObject()) {
233
0
    { // scope for tempRoot and tempGlobalRoot if needed
234
0
      arg0 = new binding_detail::FastMozDocumentCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
235
0
    }
236
0
  } else {
237
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of MozDocumentObserver.constructor");
238
0
    return false;
239
0
  }
240
0
  Maybe<JSAutoRealm> ar;
241
0
  if (objIsXray) {
242
0
    obj = js::CheckedUnwrap(obj);
243
0
    if (!obj) {
244
0
      return false;
245
0
    }
246
0
    ar.emplace(cx, obj);
247
0
    if (!JS_WrapObject(cx, &desiredProto)) {
248
0
      return false;
249
0
    }
250
0
  }
251
0
  FastErrorResult rv;
252
0
  auto result(StrongOrRawPtr<mozilla::extensions::DocumentObserver>(mozilla::extensions::DocumentObserver::Constructor(global, MOZ_KnownLive(NonNullHelper(arg0)), rv)));
253
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
254
0
    return false;
255
0
  }
256
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
257
0
  static_assert(!IsPointer<decltype(result)>::value,
258
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
259
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
260
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
261
0
    return false;
262
0
  }
263
0
  return true;
264
0
}
265
266
static const js::ClassOps sInterfaceObjectClassOps = {
267
    nullptr,               /* addProperty */
268
    nullptr,               /* delProperty */
269
    nullptr,               /* enumerate */
270
    nullptr,               /* newEnumerate */
271
    nullptr,               /* resolve */
272
    nullptr,               /* mayResolve */
273
    nullptr,               /* finalize */
274
    _constructor, /* call */
275
    nullptr,               /* hasInstance */
276
    _constructor, /* construct */
277
    nullptr,               /* trace */
278
};
279
280
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
281
  {
282
    "Function",
283
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
284
    &sInterfaceObjectClassOps,
285
    JS_NULL_CLASS_SPEC,
286
    JS_NULL_CLASS_EXT,
287
    &sInterfaceObjectClassObjectOps
288
  },
289
  eInterface,
290
  true,
291
  prototypes::id::MozDocumentObserver,
292
  PrototypeTraits<prototypes::id::MozDocumentObserver>::Depth,
293
  &sEmptyNativePropertyHooks,
294
  "function MozDocumentObserver() {\n    [native code]\n}",
295
  JS::GetRealmFunctionPrototype
296
};
297
298
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
299
  {
300
    "MozDocumentObserverPrototype",
301
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
302
    JS_NULL_CLASS_OPS,
303
    JS_NULL_CLASS_SPEC,
304
    JS_NULL_CLASS_EXT,
305
    JS_NULL_OBJECT_OPS
306
  },
307
  eInterfacePrototype,
308
  false,
309
  prototypes::id::MozDocumentObserver,
310
  PrototypeTraits<prototypes::id::MozDocumentObserver>::Depth,
311
  &sEmptyNativePropertyHooks,
312
  "[object MozDocumentObserverPrototype]",
313
  JS::GetRealmObjectPrototype
314
};
315
316
bool
317
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
318
0
{
319
0
  return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
320
0
}
321
322
static const js::ClassOps sClassOps = {
323
  _addProperty, /* addProperty */
324
  nullptr,               /* delProperty */
325
  nullptr,               /* enumerate */
326
  nullptr, /* newEnumerate */
327
  nullptr, /* resolve */
328
  nullptr, /* mayResolve */
329
  _finalize, /* finalize */
330
  nullptr, /* call */
331
  nullptr,               /* hasInstance */
332
  nullptr,               /* construct */
333
  nullptr, /* trace */
334
};
335
336
static const js::ClassExtension sClassExtension = {
337
  nullptr, /* weakmapKeyDelegateOp */
338
  _objectMoved /* objectMovedOp */
339
};
340
341
static const DOMJSClass sClass = {
342
  { "MozDocumentObserver",
343
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
344
    &sClassOps,
345
    JS_NULL_CLASS_SPEC,
346
    &sClassExtension,
347
    JS_NULL_OBJECT_OPS
348
  },
349
  { prototypes::id::MozDocumentObserver, 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 },
350
  IsBaseOf<nsISupports, mozilla::extensions::DocumentObserver >::value,
351
  &sEmptyNativePropertyHooks,
352
  FindAssociatedGlobalForNative<mozilla::extensions::DocumentObserver>::Get,
353
  GetProtoObjectHandle,
354
  GetCCParticipant<mozilla::extensions::DocumentObserver>::Get()
355
};
356
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
357
              "Must have the right minimal number of reserved slots.");
358
static_assert(1 >= 1,
359
              "Must have enough reserved slots.");
360
361
const JSClass*
362
GetJSClass()
363
0
{
364
0
  return sClass.ToJSClass();
365
0
}
366
367
bool
368
Wrap(JSContext* aCx, mozilla::extensions::DocumentObserver* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
369
0
{
370
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::extensions::DocumentObserver>::value,
371
0
                "Shouldn't have wrappercached things that are not refcounted.");
372
0
  MOZ_ASSERT(static_cast<mozilla::extensions::DocumentObserver*>(aObject) ==
373
0
             reinterpret_cast<mozilla::extensions::DocumentObserver*>(aObject),
374
0
             "Multiple inheritance for mozilla::extensions::DocumentObserver is broken.");
375
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
376
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
377
0
  MOZ_ASSERT(!aCache->GetWrapper(),
378
0
             "You should probably not be using Wrap() directly; use "
379
0
             "GetOrCreateDOMReflector instead");
380
0
381
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
382
0
             "nsISupports must be on our primary inheritance chain");
383
0
384
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
385
0
  if (!global) {
386
0
    return false;
387
0
  }
388
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
389
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
390
0
391
0
  // That might have ended up wrapping us already, due to the wonders
392
0
  // of XBL.  Check for that, and bail out as needed.
393
0
  aReflector.set(aCache->GetWrapper());
394
0
  if (aReflector) {
395
#ifdef DEBUG
396
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
397
#endif // DEBUG
398
    return true;
399
0
  }
400
0
401
0
  JSAutoRealm ar(aCx, global);
402
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
403
0
  if (!canonicalProto) {
404
0
    return false;
405
0
  }
406
0
  JS::Rooted<JSObject*> proto(aCx);
407
0
  if (aGivenProto) {
408
0
    proto = aGivenProto;
409
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
410
0
    // coming in, we changed compartments to that of "parent" so may need
411
0
    // to wrap the proto here.
412
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
413
0
      if (!JS_WrapObject(aCx, &proto)) {
414
0
        return false;
415
0
      }
416
0
    }
417
0
  } else {
418
0
    proto = canonicalProto;
419
0
  }
420
0
421
0
  BindingJSObjectCreator<mozilla::extensions::DocumentObserver> creator(aCx);
422
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
423
0
  if (!aReflector) {
424
0
    return false;
425
0
  }
426
0
427
0
  aCache->SetWrapper(aReflector);
428
0
  creator.InitializationSucceeded();
429
0
430
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
431
0
             aCache->GetWrapperPreserveColor() == aReflector);
432
0
  // If proto != canonicalProto, we have to preserve our wrapper;
433
0
  // otherwise we won't be able to properly recreate it later, since
434
0
  // we won't know what proto to use.  Note that we don't check
435
0
  // aGivenProto here, since it's entirely possible (and even
436
0
  // somewhat common) to have a non-null aGivenProto which is the
437
0
  // same as canonicalProto.
438
0
  if (proto != canonicalProto) {
439
0
    PreserveWrapper(aObject);
440
0
  }
441
0
442
0
  return true;
443
0
}
444
445
void
446
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
447
0
{
448
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
449
0
  if (!parentProto) {
450
0
    return;
451
0
  }
452
0
453
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
454
0
  if (!constructorProto) {
455
0
    return;
456
0
  }
457
0
458
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MozDocumentObserver);
459
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MozDocumentObserver);
460
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
461
0
                              &sPrototypeClass.mBase, protoCache,
462
0
                              nullptr,
463
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
464
0
                              interfaceCache,
465
0
                              sNativeProperties.Upcast(),
466
0
                              nullptr,
467
0
                              "MozDocumentObserver", aDefineOnGlobal,
468
0
                              nullptr,
469
0
                              false);
470
0
}
471
472
JSObject*
473
GetConstructorObject(JSContext* aCx)
474
0
{
475
0
  return GetConstructorObjectHandle(aCx);
476
0
}
477
478
} // namespace MozDocumentObserver_Binding
479
480
481
482
void
483
MozDocumentCallback::OnNewDocument(extensions::MozDocumentMatcher& matcher, nsPIDOMWindowOuter* window, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JS::Realm* aRealm)
484
0
{
485
0
  CallSetup s(this, aRv, "MozDocumentCallback.onNewDocument", aExceptionHandling, aRealm);
486
0
  JSContext* cx = s.GetContext();
487
0
  if (!cx) {
488
0
    MOZ_ASSERT(aRv.Failed());
489
0
    return;
490
0
  }
491
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
492
0
  JS::AutoValueVector argv(cx);
493
0
  if (!argv.resize(2)) {
494
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
495
0
    return;
496
0
  }
497
0
  unsigned argc = 2;
498
0
499
0
  do {
500
0
    if (!WrapObject(cx, window, argv[1])) {
501
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
502
0
      return;
503
0
    }
504
0
    break;
505
0
  } while (false);
506
0
507
0
  do {
508
0
    if (!GetOrCreateDOMReflector(cx, matcher, argv[0])) {
509
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
510
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
511
0
      return;
512
0
    }
513
0
    break;
514
0
  } while (false);
515
0
516
0
  JS::Rooted<JS::Value> callable(cx);
517
0
  MozDocumentCallbackAtoms* atomsCache = GetAtomCache<MozDocumentCallbackAtoms>(cx);
518
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
519
0
      !GetCallableProperty(cx, atomsCache->onNewDocument_id, &callable)) {
520
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
521
0
    return;
522
0
  }
523
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
524
0
  if (!JS::Call(cx, thisValue, callable,
525
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
526
0
    aRv.NoteJSContextException(cx);
527
0
    return;
528
0
  }
529
0
}
530
531
void
532
MozDocumentCallback::OnPreloadDocument(extensions::MozDocumentMatcher& matcher, nsILoadInfo* loadInfo, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JS::Realm* aRealm)
533
0
{
534
0
  CallSetup s(this, aRv, "MozDocumentCallback.onPreloadDocument", aExceptionHandling, aRealm);
535
0
  JSContext* cx = s.GetContext();
536
0
  if (!cx) {
537
0
    MOZ_ASSERT(aRv.Failed());
538
0
    return;
539
0
  }
540
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
541
0
  JS::AutoValueVector argv(cx);
542
0
  if (!argv.resize(2)) {
543
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
544
0
    return;
545
0
  }
546
0
  unsigned argc = 2;
547
0
548
0
  do {
549
0
    if (!WrapObject(cx, loadInfo, &NS_GET_IID(nsILoadInfo), argv[1])) {
550
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
551
0
      return;
552
0
    }
553
0
    break;
554
0
  } while (false);
555
0
556
0
  do {
557
0
    if (!GetOrCreateDOMReflector(cx, matcher, argv[0])) {
558
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
559
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
560
0
      return;
561
0
    }
562
0
    break;
563
0
  } while (false);
564
0
565
0
  JS::Rooted<JS::Value> callable(cx);
566
0
  MozDocumentCallbackAtoms* atomsCache = GetAtomCache<MozDocumentCallbackAtoms>(cx);
567
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
568
0
      !GetCallableProperty(cx, atomsCache->onPreloadDocument_id, &callable)) {
569
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
570
0
    return;
571
0
  }
572
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
573
0
  if (!JS::Call(cx, thisValue, callable,
574
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
575
0
    aRv.NoteJSContextException(cx);
576
0
    return;
577
0
  }
578
0
}
579
580
bool
581
MozDocumentCallback::InitIds(JSContext* cx, MozDocumentCallbackAtoms* atomsCache)
582
0
{
583
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
584
0
585
0
  // Initialize these in reverse order so that any failure leaves the first one
586
0
  // uninitialized.
587
0
  if (!atomsCache->onPreloadDocument_id.init(cx, "onPreloadDocument") ||
588
0
      !atomsCache->onNewDocument_id.init(cx, "onNewDocument")) {
589
0
    return false;
590
0
  }
591
0
  return true;
592
0
}
593
594
595
596
namespace binding_detail {
597
} // namespace binding_detail
598
599
600
} // namespace dom
601
} // namespace mozilla