Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MessageChannelBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MessageChannel.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "MessageChannelBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/dom/BindingUtils.h"
7
#include "mozilla/dom/DOMJSClass.h"
8
#include "mozilla/dom/MessageChannel.h"
9
#include "mozilla/dom/MessagePort.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/XrayExpandoClass.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
namespace binding_detail {}; // Just to make sure it's known as a namespace
17
using namespace mozilla::dom::binding_detail;
18
19
20
namespace MessageChannel_Binding {
21
22
MOZ_CAN_RUN_SCRIPT static bool
23
get_port1(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageChannel* self, JSJitGetterCallArgs args)
24
0
{
25
0
  AUTO_PROFILER_LABEL_FAST("get MessageChannel.port1", DOM, cx);
26
0
27
0
  auto result(StrongOrRawPtr<mozilla::dom::MessagePort>(self->Port1()));
28
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
29
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
30
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
31
0
    return false;
32
0
  }
33
0
  return true;
34
0
}
35
36
static const JSJitInfo port1_getterinfo = {
37
  { (JSJitGetterOp)get_port1 },
38
  { prototypes::id::MessageChannel },
39
  { PrototypeTraits<prototypes::id::MessageChannel>::Depth },
40
  JSJitInfo::Getter,
41
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
42
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
43
  false,  /* isInfallible. False in setters. */
44
  false,  /* isMovable.  Not relevant for setters. */
45
  false, /* isEliminatable.  Not relevant for setters. */
46
  false, /* isAlwaysInSlot.  Only relevant for getters. */
47
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
48
  false,  /* isTypedMethod.  Only relevant for methods. */
49
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
50
};
51
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
52
static_assert(0 < 1, "There is no slot for us");
53
54
MOZ_CAN_RUN_SCRIPT static bool
55
get_port2(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageChannel* self, JSJitGetterCallArgs args)
56
0
{
57
0
  AUTO_PROFILER_LABEL_FAST("get MessageChannel.port2", DOM, cx);
58
0
59
0
  auto result(StrongOrRawPtr<mozilla::dom::MessagePort>(self->Port2()));
60
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
61
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
62
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
63
0
    return false;
64
0
  }
65
0
  return true;
66
0
}
67
68
static const JSJitInfo port2_getterinfo = {
69
  { (JSJitGetterOp)get_port2 },
70
  { prototypes::id::MessageChannel },
71
  { PrototypeTraits<prototypes::id::MessageChannel>::Depth },
72
  JSJitInfo::Getter,
73
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
74
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
75
  false,  /* isInfallible. False in setters. */
76
  false,  /* isMovable.  Not relevant for setters. */
77
  false, /* isEliminatable.  Not relevant for setters. */
78
  false, /* isAlwaysInSlot.  Only relevant for getters. */
79
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
80
  false,  /* isTypedMethod.  Only relevant for methods. */
81
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
82
};
83
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
84
static_assert(0 < 1, "There is no slot for us");
85
86
static bool
87
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
88
0
{
89
0
  mozilla::dom::MessageChannel* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageChannel>(obj);
90
0
  // We don't want to preserve if we don't have a wrapper, and we
91
0
  // obviously can't preserve if we're not initialized.
92
0
  if (self && self->GetWrapperPreserveColor()) {
93
0
    PreserveWrapper(self);
94
0
  }
95
0
  return true;
96
0
}
97
98
static void
99
_finalize(js::FreeOp* fop, JSObject* obj)
100
0
{
101
0
  mozilla::dom::MessageChannel* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageChannel>(obj);
102
0
  if (self) {
103
0
    ClearWrapper(self, self, obj);
104
0
    AddForDeferredFinalization<mozilla::dom::MessageChannel>(self);
105
0
  }
106
0
}
107
108
static size_t
109
_objectMoved(JSObject* obj, JSObject* old)
110
0
{
111
0
  mozilla::dom::MessageChannel* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageChannel>(obj);
112
0
  if (self) {
113
0
    UpdateWrapper(self, self, obj, old);
114
0
  }
115
0
116
0
  return 0;
117
0
}
118
119
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
120
#if defined(__clang__)
121
#pragma clang diagnostic push
122
#pragma clang diagnostic ignored "-Wmissing-braces"
123
#endif
124
static const JSPropertySpec sAttributes_specs[] = {
125
  { "port1", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &port1_getterinfo, nullptr, nullptr },
126
  { "port2", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &port2_getterinfo, nullptr, nullptr },
127
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
128
};
129
#if defined(__clang__)
130
#pragma clang diagnostic pop
131
#endif
132
133
134
static const Prefable<const JSPropertySpec> sAttributes[] = {
135
  { nullptr, &sAttributes_specs[0] },
136
  { nullptr, nullptr }
137
};
138
139
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
140
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
141
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
142
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
143
144
145
static uint16_t sNativeProperties_sortedPropertyIndices[2];
146
static PropertyInfo sNativeProperties_propertyInfos[2];
147
148
static const NativePropertiesN<1> sNativeProperties = {
149
  false, 0,
150
  false, 0,
151
  false, 0,
152
  true,  0 /* sAttributes */,
153
  false, 0,
154
  false, 0,
155
  false, 0,
156
  -1,
157
  2,
158
  sNativeProperties_sortedPropertyIndices,
159
  {
160
    { sAttributes, &sNativeProperties_propertyInfos[0] }
161
  }
162
};
163
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
164
    "We have a property info count that is oversized");
165
166
static bool
167
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
168
0
{
169
0
  AUTO_PROFILER_LABEL_FAST("MessageChannel constructor", DOM, cx);
170
0
171
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
172
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
173
0
  if (!args.isConstructing()) {
174
0
    // XXXbz wish I could get the name from the callee instead of
175
0
    // Adding more relocations
176
0
    return ThrowConstructorWithoutNew(cx, "MessageChannel");
177
0
  }
178
0
179
0
  JS::Rooted<JSObject*> desiredProto(cx);
180
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
181
0
    return false;
182
0
  }
183
0
184
0
  GlobalObject global(cx, obj);
185
0
  if (global.Failed()) {
186
0
    return false;
187
0
  }
188
0
189
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
190
0
  Maybe<JSAutoRealm> ar;
191
0
  if (objIsXray) {
192
0
    obj = js::CheckedUnwrap(obj);
193
0
    if (!obj) {
194
0
      return false;
195
0
    }
196
0
    ar.emplace(cx, obj);
197
0
    if (!JS_WrapObject(cx, &desiredProto)) {
198
0
      return false;
199
0
    }
200
0
  }
201
0
  FastErrorResult rv;
202
0
  auto result(StrongOrRawPtr<mozilla::dom::MessageChannel>(mozilla::dom::MessageChannel::Constructor(global, rv)));
203
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
204
0
    return false;
205
0
  }
206
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
207
0
  static_assert(!IsPointer<decltype(result)>::value,
208
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
209
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
210
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
211
0
    return false;
212
0
  }
213
0
  return true;
214
0
}
215
216
static const js::ClassOps sInterfaceObjectClassOps = {
217
    nullptr,               /* addProperty */
218
    nullptr,               /* delProperty */
219
    nullptr,               /* enumerate */
220
    nullptr,               /* newEnumerate */
221
    nullptr,               /* resolve */
222
    nullptr,               /* mayResolve */
223
    nullptr,               /* finalize */
224
    _constructor, /* call */
225
    nullptr,               /* hasInstance */
226
    _constructor, /* construct */
227
    nullptr,               /* trace */
228
};
229
230
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
231
  {
232
    "Function",
233
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
234
    &sInterfaceObjectClassOps,
235
    JS_NULL_CLASS_SPEC,
236
    JS_NULL_CLASS_EXT,
237
    &sInterfaceObjectClassObjectOps
238
  },
239
  eInterface,
240
  true,
241
  prototypes::id::MessageChannel,
242
  PrototypeTraits<prototypes::id::MessageChannel>::Depth,
243
  sNativePropertyHooks,
244
  "function MessageChannel() {\n    [native code]\n}",
245
  JS::GetRealmFunctionPrototype
246
};
247
248
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
249
  {
250
    "MessageChannelPrototype",
251
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
252
    JS_NULL_CLASS_OPS,
253
    JS_NULL_CLASS_SPEC,
254
    JS_NULL_CLASS_EXT,
255
    JS_NULL_OBJECT_OPS
256
  },
257
  eInterfacePrototype,
258
  false,
259
  prototypes::id::MessageChannel,
260
  PrototypeTraits<prototypes::id::MessageChannel>::Depth,
261
  sNativePropertyHooks,
262
  "[object MessageChannelPrototype]",
263
  JS::GetRealmObjectPrototype
264
};
265
266
static const js::ClassOps sClassOps = {
267
  _addProperty, /* addProperty */
268
  nullptr,               /* delProperty */
269
  nullptr,               /* enumerate */
270
  nullptr, /* newEnumerate */
271
  nullptr, /* resolve */
272
  nullptr, /* mayResolve */
273
  _finalize, /* finalize */
274
  nullptr, /* call */
275
  nullptr,               /* hasInstance */
276
  nullptr,               /* construct */
277
  nullptr, /* trace */
278
};
279
280
static const js::ClassExtension sClassExtension = {
281
  nullptr, /* weakmapKeyDelegateOp */
282
  _objectMoved /* objectMovedOp */
283
};
284
285
static const DOMJSClass sClass = {
286
  { "MessageChannel",
287
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
288
    &sClassOps,
289
    JS_NULL_CLASS_SPEC,
290
    &sClassExtension,
291
    JS_NULL_OBJECT_OPS
292
  },
293
  { prototypes::id::MessageChannel, 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 },
294
  IsBaseOf<nsISupports, mozilla::dom::MessageChannel >::value,
295
  sNativePropertyHooks,
296
  FindAssociatedGlobalForNative<mozilla::dom::MessageChannel>::Get,
297
  GetProtoObjectHandle,
298
  GetCCParticipant<mozilla::dom::MessageChannel>::Get()
299
};
300
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
301
              "Must have the right minimal number of reserved slots.");
302
static_assert(1 >= 1,
303
              "Must have enough reserved slots.");
304
305
const JSClass*
306
GetJSClass()
307
0
{
308
0
  return sClass.ToJSClass();
309
0
}
310
311
bool
312
Wrap(JSContext* aCx, mozilla::dom::MessageChannel* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
313
0
{
314
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MessageChannel>::value,
315
0
                "Shouldn't have wrappercached things that are not refcounted.");
316
0
  MOZ_ASSERT(static_cast<mozilla::dom::MessageChannel*>(aObject) ==
317
0
             reinterpret_cast<mozilla::dom::MessageChannel*>(aObject),
318
0
             "Multiple inheritance for mozilla::dom::MessageChannel is broken.");
319
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
320
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
321
0
  MOZ_ASSERT(!aCache->GetWrapper(),
322
0
             "You should probably not be using Wrap() directly; use "
323
0
             "GetOrCreateDOMReflector instead");
324
0
325
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
326
0
             "nsISupports must be on our primary inheritance chain");
327
0
328
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
329
0
  if (!global) {
330
0
    return false;
331
0
  }
332
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
333
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
334
0
335
0
  // That might have ended up wrapping us already, due to the wonders
336
0
  // of XBL.  Check for that, and bail out as needed.
337
0
  aReflector.set(aCache->GetWrapper());
338
0
  if (aReflector) {
339
#ifdef DEBUG
340
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
341
#endif // DEBUG
342
    return true;
343
0
  }
344
0
345
0
  JSAutoRealm ar(aCx, global);
346
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
347
0
  if (!canonicalProto) {
348
0
    return false;
349
0
  }
350
0
  JS::Rooted<JSObject*> proto(aCx);
351
0
  if (aGivenProto) {
352
0
    proto = aGivenProto;
353
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
354
0
    // coming in, we changed compartments to that of "parent" so may need
355
0
    // to wrap the proto here.
356
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
357
0
      if (!JS_WrapObject(aCx, &proto)) {
358
0
        return false;
359
0
      }
360
0
    }
361
0
  } else {
362
0
    proto = canonicalProto;
363
0
  }
364
0
365
0
  BindingJSObjectCreator<mozilla::dom::MessageChannel> creator(aCx);
366
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
367
0
  if (!aReflector) {
368
0
    return false;
369
0
  }
370
0
371
0
  aCache->SetWrapper(aReflector);
372
0
  creator.InitializationSucceeded();
373
0
374
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
375
0
             aCache->GetWrapperPreserveColor() == aReflector);
376
0
  // If proto != canonicalProto, we have to preserve our wrapper;
377
0
  // otherwise we won't be able to properly recreate it later, since
378
0
  // we won't know what proto to use.  Note that we don't check
379
0
  // aGivenProto here, since it's entirely possible (and even
380
0
  // somewhat common) to have a non-null aGivenProto which is the
381
0
  // same as canonicalProto.
382
0
  if (proto != canonicalProto) {
383
0
    PreserveWrapper(aObject);
384
0
  }
385
0
386
0
  return true;
387
0
}
388
389
const NativePropertyHooks sNativePropertyHooks[] = { {
390
  nullptr,
391
  nullptr,
392
  nullptr,
393
  { sNativeProperties.Upcast(), nullptr },
394
  prototypes::id::MessageChannel,
395
  constructors::id::MessageChannel,
396
  nullptr,
397
  &DefaultXrayExpandoObjectClass
398
} };
399
400
void
401
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
402
0
{
403
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
404
0
  if (!parentProto) {
405
0
    return;
406
0
  }
407
0
408
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
409
0
  if (!constructorProto) {
410
0
    return;
411
0
  }
412
0
413
0
  static bool sIdsInited = false;
414
0
  if (!sIdsInited && NS_IsMainThread()) {
415
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
416
0
      return;
417
0
    }
418
0
    sIdsInited = true;
419
0
  }
420
0
421
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessageChannel);
422
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessageChannel);
423
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
424
0
                              &sPrototypeClass.mBase, protoCache,
425
0
                              nullptr,
426
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
427
0
                              interfaceCache,
428
0
                              sNativeProperties.Upcast(),
429
0
                              nullptr,
430
0
                              "MessageChannel", aDefineOnGlobal,
431
0
                              nullptr,
432
0
                              false);
433
0
}
434
435
JSObject*
436
GetConstructorObject(JSContext* aCx)
437
0
{
438
0
  return GetConstructorObjectHandle(aCx);
439
0
}
440
441
} // namespace MessageChannel_Binding
442
443
444
445
} // namespace dom
446
} // namespace mozilla