Coverage Report

Created: 2018-09-25 14:53

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