Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/TCPSocketErrorEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM TCPSocketErrorEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "EventBinding.h"
5
#include "TCPSocketErrorEventBinding.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/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/PrimitiveConversions.h"
12
#include "mozilla/dom/ScriptSettings.h"
13
#include "mozilla/dom/SimpleGlobalObject.h"
14
#include "mozilla/dom/TCPSocket.h"
15
#include "mozilla/dom/TCPSocketErrorEvent.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
26
TCPSocketErrorEventInit::TCPSocketErrorEventInit()
27
  : EventInit(FastDictionaryInitializer())
28
0
{
29
0
  // Safe to pass a null context if we pass a null value
30
0
  Init(nullptr, JS::NullHandleValue);
31
0
}
32
33
34
35
bool
36
TCPSocketErrorEventInit::InitIds(JSContext* cx, TCPSocketErrorEventInitAtoms* atomsCache)
37
0
{
38
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
39
0
40
0
  // Initialize these in reverse order so that any failure leaves the first one
41
0
  // uninitialized.
42
0
  if (!atomsCache->name_id.init(cx, "name") ||
43
0
      !atomsCache->message_id.init(cx, "message")) {
44
0
    return false;
45
0
  }
46
0
  return true;
47
0
}
48
49
bool
50
TCPSocketErrorEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
51
0
{
52
0
  // Passing a null JSContext is OK only if we're initing from null,
53
0
  // Since in that case we will not have to do any property gets
54
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
55
0
  // checkers by static analysis tools
56
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
57
0
  TCPSocketErrorEventInitAtoms* atomsCache = nullptr;
58
0
  if (cx) {
59
0
    atomsCache = GetAtomCache<TCPSocketErrorEventInitAtoms>(cx);
60
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
61
0
      return false;
62
0
    }
63
0
  }
64
0
65
0
  // Per spec, we init the parent's members first
66
0
  if (!EventInit::Init(cx, val)) {
67
0
    return false;
68
0
  }
69
0
70
0
  bool isNull = val.isNullOrUndefined();
71
0
  // We only need these if !isNull, in which case we have |cx|.
72
0
  Maybe<JS::Rooted<JSObject *> > object;
73
0
  Maybe<JS::Rooted<JS::Value> > temp;
74
0
  if (!isNull) {
75
0
    MOZ_ASSERT(cx);
76
0
    object.emplace(cx, &val.toObject());
77
0
    temp.emplace(cx);
78
0
  }
79
0
  if (!isNull) {
80
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->message_id, temp.ptr())) {
81
0
      return false;
82
0
    }
83
0
  }
84
0
  if (!isNull && !temp->isUndefined()) {
85
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mMessage)) {
86
0
      return false;
87
0
    }
88
0
  } else {
89
0
    static const char16_t data[] = { 0 };
90
0
    mMessage.Rebind(data, ArrayLength(data) - 1);
91
0
  }
92
0
  mIsAnyMemberPresent = true;
93
0
94
0
  if (!isNull) {
95
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
96
0
      return false;
97
0
    }
98
0
  }
99
0
  if (!isNull && !temp->isUndefined()) {
100
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
101
0
      return false;
102
0
    }
103
0
  } else {
104
0
    static const char16_t data[] = { 0 };
105
0
    mName.Rebind(data, ArrayLength(data) - 1);
106
0
  }
107
0
  mIsAnyMemberPresent = true;
108
0
  return true;
109
0
}
110
111
bool
112
TCPSocketErrorEventInit::Init(const nsAString& aJSON)
113
0
{
114
0
  AutoJSAPI jsapi;
115
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
116
0
  if (!cleanGlobal) {
117
0
    return false;
118
0
  }
119
0
  if (!jsapi.Init(cleanGlobal)) {
120
0
    return false;
121
0
  }
122
0
  JSContext* cx = jsapi.cx();
123
0
  JS::Rooted<JS::Value> json(cx);
124
0
  bool ok = ParseJSON(cx, aJSON, &json);
125
0
  NS_ENSURE_TRUE(ok, false);
126
0
  return Init(cx, json);
127
0
}
128
129
bool
130
TCPSocketErrorEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
131
0
{
132
0
  TCPSocketErrorEventInitAtoms* atomsCache = GetAtomCache<TCPSocketErrorEventInitAtoms>(cx);
133
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
134
0
    return false;
135
0
  }
136
0
137
0
  // Per spec, we define the parent's members first
138
0
  if (!EventInit::ToObjectInternal(cx, rval)) {
139
0
    return false;
140
0
  }
141
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
142
0
143
0
  do {
144
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
145
0
    JS::Rooted<JS::Value> temp(cx);
146
0
    nsString const & currentValue = mMessage;
147
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
148
0
      return false;
149
0
    }
150
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->message_id, temp, JSPROP_ENUMERATE)) {
151
0
      return false;
152
0
    }
153
0
    break;
154
0
  } while(false);
155
0
156
0
  do {
157
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
158
0
    JS::Rooted<JS::Value> temp(cx);
159
0
    nsString const & currentValue = mName;
160
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
161
0
      return false;
162
0
    }
163
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
164
0
      return false;
165
0
    }
166
0
    break;
167
0
  } while(false);
168
0
169
0
  return true;
170
0
}
171
172
bool
173
TCPSocketErrorEventInit::ToJSON(nsAString& aJSON) const
174
0
{
175
0
  AutoJSAPI jsapi;
176
0
  jsapi.Init();
177
0
  JSContext *cx = jsapi.cx();
178
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
179
0
  // because we'll only be creating objects, in ways that have no
180
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
181
0
  // which likewise guarantees no side-effects for the sorts of
182
0
  // things we will pass it.
183
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
184
0
  JS::Rooted<JS::Value> val(cx);
185
0
  if (!ToObjectInternal(cx, &val)) {
186
0
    return false;
187
0
  }
188
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
189
0
  return StringifyToJSON(cx, obj, aJSON);
190
0
}
191
192
void
193
TCPSocketErrorEventInit::TraceDictionary(JSTracer* trc)
194
0
{
195
0
  EventInit::TraceDictionary(trc);
196
0
}
197
198
TCPSocketErrorEventInit&
199
TCPSocketErrorEventInit::operator=(const TCPSocketErrorEventInit& aOther)
200
0
{
201
0
  EventInit::operator=(aOther);
202
0
  mMessage = aOther.mMessage;
203
0
  mName = aOther.mName;
204
0
  return *this;
205
0
}
206
207
namespace binding_detail {
208
} // namespace binding_detail
209
210
211
namespace TCPSocketErrorEvent_Binding {
212
213
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value,
214
              "Can't inherit from an interface with a different ownership model.");
215
216
MOZ_CAN_RUN_SCRIPT static bool
217
get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocketErrorEvent* self, JSJitGetterCallArgs args)
218
0
{
219
0
  AUTO_PROFILER_LABEL_FAST("get TCPSocketErrorEvent.name", DOM, cx);
220
0
221
0
  DOMString result;
222
0
  self->GetName(result);
223
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
224
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
225
0
    return false;
226
0
  }
227
0
  return true;
228
0
}
229
230
static const JSJitInfo name_getterinfo = {
231
  { (JSJitGetterOp)get_name },
232
  { prototypes::id::TCPSocketErrorEvent },
233
  { PrototypeTraits<prototypes::id::TCPSocketErrorEvent>::Depth },
234
  JSJitInfo::Getter,
235
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
236
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
237
  false,  /* isInfallible. False in setters. */
238
  false,  /* isMovable.  Not relevant for setters. */
239
  false, /* isEliminatable.  Not relevant for setters. */
240
  false, /* isAlwaysInSlot.  Only relevant for getters. */
241
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
242
  false,  /* isTypedMethod.  Only relevant for methods. */
243
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
244
};
245
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
246
static_assert(0 < 1, "There is no slot for us");
247
248
MOZ_CAN_RUN_SCRIPT static bool
249
get_message(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocketErrorEvent* self, JSJitGetterCallArgs args)
250
0
{
251
0
  AUTO_PROFILER_LABEL_FAST("get TCPSocketErrorEvent.message", DOM, cx);
252
0
253
0
  DOMString result;
254
0
  self->GetMessage(result);
255
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
256
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
257
0
    return false;
258
0
  }
259
0
  return true;
260
0
}
261
262
static const JSJitInfo message_getterinfo = {
263
  { (JSJitGetterOp)get_message },
264
  { prototypes::id::TCPSocketErrorEvent },
265
  { PrototypeTraits<prototypes::id::TCPSocketErrorEvent>::Depth },
266
  JSJitInfo::Getter,
267
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
268
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
269
  false,  /* isInfallible. False in setters. */
270
  false,  /* isMovable.  Not relevant for setters. */
271
  false, /* isEliminatable.  Not relevant for setters. */
272
  false, /* isAlwaysInSlot.  Only relevant for getters. */
273
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
274
  false,  /* isTypedMethod.  Only relevant for methods. */
275
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
276
};
277
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
278
static_assert(0 < 1, "There is no slot for us");
279
280
MOZ_CAN_RUN_SCRIPT static bool
281
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocketErrorEvent* self, JSJitGetterCallArgs args)
282
0
{
283
0
  AUTO_PROFILER_LABEL_FAST("get TCPSocketErrorEvent.isTrusted", DOM, cx);
284
0
285
0
  bool result(self->IsTrusted());
286
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
287
0
  args.rval().setBoolean(result);
288
0
  return true;
289
0
}
290
291
static const JSJitInfo isTrusted_getterinfo = {
292
  { (JSJitGetterOp)get_isTrusted },
293
  { prototypes::id::TCPSocketErrorEvent },
294
  { PrototypeTraits<prototypes::id::TCPSocketErrorEvent>::Depth },
295
  JSJitInfo::Getter,
296
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
297
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
298
  true,  /* isInfallible. False in setters. */
299
  true,  /* isMovable.  Not relevant for setters. */
300
  true, /* isEliminatable.  Not relevant for setters. */
301
  false, /* isAlwaysInSlot.  Only relevant for getters. */
302
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
303
  false,  /* isTypedMethod.  Only relevant for methods. */
304
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
305
};
306
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
307
static_assert(0 < 1, "There is no slot for us");
308
309
static bool
310
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
311
0
{
312
0
  mozilla::dom::TCPSocketErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocketErrorEvent>(obj);
313
0
  // We don't want to preserve if we don't have a wrapper, and we
314
0
  // obviously can't preserve if we're not initialized.
315
0
  if (self && self->GetWrapperPreserveColor()) {
316
0
    PreserveWrapper(self);
317
0
  }
318
0
  return true;
319
0
}
320
321
static void
322
_finalize(js::FreeOp* fop, JSObject* obj)
323
0
{
324
0
  mozilla::dom::TCPSocketErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocketErrorEvent>(obj);
325
0
  if (self) {
326
0
    ClearWrapper(self, self, obj);
327
0
    AddForDeferredFinalization<mozilla::dom::TCPSocketErrorEvent>(self);
328
0
  }
329
0
}
330
331
static size_t
332
_objectMoved(JSObject* obj, JSObject* old)
333
0
{
334
0
  mozilla::dom::TCPSocketErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocketErrorEvent>(obj);
335
0
  if (self) {
336
0
    UpdateWrapper(self, self, obj, old);
337
0
  }
338
0
339
0
  return 0;
340
0
}
341
342
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
343
#if defined(__clang__)
344
#pragma clang diagnostic push
345
#pragma clang diagnostic ignored "-Wmissing-braces"
346
#endif
347
static const JSPropertySpec sAttributes_specs[] = {
348
  { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr },
349
  { "message", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &message_getterinfo, nullptr, nullptr },
350
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
351
};
352
#if defined(__clang__)
353
#pragma clang diagnostic pop
354
#endif
355
356
357
static const Prefable<const JSPropertySpec> sAttributes[] = {
358
  { nullptr, &sAttributes_specs[0] },
359
  { nullptr, nullptr }
360
};
361
362
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
363
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
364
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
365
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
366
367
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
368
#if defined(__clang__)
369
#pragma clang diagnostic push
370
#pragma clang diagnostic ignored "-Wmissing-braces"
371
#endif
372
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
373
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
374
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
375
};
376
#if defined(__clang__)
377
#pragma clang diagnostic pop
378
#endif
379
380
381
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
382
  { nullptr, &sUnforgeableAttributes_specs[0] },
383
  { nullptr, nullptr }
384
};
385
386
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
387
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
388
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
389
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
390
391
392
static uint16_t sNativeProperties_sortedPropertyIndices[3];
393
static PropertyInfo sNativeProperties_propertyInfos[3];
394
395
static const NativePropertiesN<2> sNativeProperties = {
396
  false, 0,
397
  false, 0,
398
  false, 0,
399
  true,  0 /* sAttributes */,
400
  false, 0,
401
  true,  1 /* sUnforgeableAttributes */,
402
  false, 0,
403
  -1,
404
  3,
405
  sNativeProperties_sortedPropertyIndices,
406
  {
407
    { sAttributes, &sNativeProperties_propertyInfos[0] },
408
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[2] }
409
  }
410
};
411
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
412
    "We have a property info count that is oversized");
413
414
static bool
415
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
416
0
{
417
0
  AUTO_PROFILER_LABEL_FAST("TCPSocketErrorEvent constructor", DOM, cx);
418
0
419
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
420
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
421
0
  if (!args.isConstructing()) {
422
0
    // XXXbz wish I could get the name from the callee instead of
423
0
    // Adding more relocations
424
0
    return ThrowConstructorWithoutNew(cx, "TCPSocketErrorEvent");
425
0
  }
426
0
427
0
  JS::Rooted<JSObject*> desiredProto(cx);
428
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
429
0
    return false;
430
0
  }
431
0
432
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
433
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TCPSocketErrorEvent");
434
0
  }
435
0
  GlobalObject global(cx, obj);
436
0
  if (global.Failed()) {
437
0
    return false;
438
0
  }
439
0
440
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
441
0
  binding_detail::FakeString arg0;
442
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
443
0
    return false;
444
0
  }
445
0
  binding_detail::FastTCPSocketErrorEventInit arg1;
446
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of TCPSocketErrorEvent.constructor", false)) {
447
0
    return false;
448
0
  }
449
0
  Maybe<JSAutoRealm> ar;
450
0
  if (objIsXray) {
451
0
    obj = js::CheckedUnwrap(obj);
452
0
    if (!obj) {
453
0
      return false;
454
0
    }
455
0
    ar.emplace(cx, obj);
456
0
    if (!JS_WrapObject(cx, &desiredProto)) {
457
0
      return false;
458
0
    }
459
0
  }
460
0
  FastErrorResult rv;
461
0
  auto result(StrongOrRawPtr<mozilla::dom::TCPSocketErrorEvent>(mozilla::dom::TCPSocketErrorEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(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
  static_assert(!IsPointer<decltype(result)>::value,
467
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
468
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
469
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
470
0
    return false;
471
0
  }
472
0
  return true;
473
0
}
474
475
static const js::ClassOps sInterfaceObjectClassOps = {
476
    nullptr,               /* addProperty */
477
    nullptr,               /* delProperty */
478
    nullptr,               /* enumerate */
479
    nullptr,               /* newEnumerate */
480
    nullptr,               /* resolve */
481
    nullptr,               /* mayResolve */
482
    nullptr,               /* finalize */
483
    _constructor, /* call */
484
    nullptr,               /* hasInstance */
485
    _constructor, /* construct */
486
    nullptr,               /* trace */
487
};
488
489
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
490
  {
491
    "Function",
492
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
493
    &sInterfaceObjectClassOps,
494
    JS_NULL_CLASS_SPEC,
495
    JS_NULL_CLASS_EXT,
496
    &sInterfaceObjectClassObjectOps
497
  },
498
  eInterface,
499
  true,
500
  prototypes::id::TCPSocketErrorEvent,
501
  PrototypeTraits<prototypes::id::TCPSocketErrorEvent>::Depth,
502
  sNativePropertyHooks,
503
  "function TCPSocketErrorEvent() {\n    [native code]\n}",
504
  Event_Binding::GetConstructorObject
505
};
506
507
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
508
  {
509
    "TCPSocketErrorEventPrototype",
510
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
511
    JS_NULL_CLASS_OPS,
512
    JS_NULL_CLASS_SPEC,
513
    JS_NULL_CLASS_EXT,
514
    JS_NULL_OBJECT_OPS
515
  },
516
  eInterfacePrototype,
517
  false,
518
  prototypes::id::TCPSocketErrorEvent,
519
  PrototypeTraits<prototypes::id::TCPSocketErrorEvent>::Depth,
520
  sNativePropertyHooks,
521
  "[object TCPSocketErrorEventPrototype]",
522
  Event_Binding::GetProtoObject
523
};
524
525
bool
526
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
527
0
{
528
0
  return mozilla::dom::TCPSocket::ShouldTCPSocketExist(aCx, aObj);
529
0
}
530
531
static const js::ClassOps sClassOps = {
532
  _addProperty, /* addProperty */
533
  nullptr,               /* delProperty */
534
  nullptr,               /* enumerate */
535
  nullptr, /* newEnumerate */
536
  nullptr, /* resolve */
537
  nullptr, /* mayResolve */
538
  _finalize, /* finalize */
539
  nullptr, /* call */
540
  nullptr,               /* hasInstance */
541
  nullptr,               /* construct */
542
  nullptr, /* trace */
543
};
544
545
static const js::ClassExtension sClassExtension = {
546
  nullptr, /* weakmapKeyDelegateOp */
547
  _objectMoved /* objectMovedOp */
548
};
549
550
static const DOMJSClass sClass = {
551
  { "TCPSocketErrorEvent",
552
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
553
    &sClassOps,
554
    JS_NULL_CLASS_SPEC,
555
    &sClassExtension,
556
    JS_NULL_OBJECT_OPS
557
  },
558
  { prototypes::id::Event, prototypes::id::TCPSocketErrorEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
559
  IsBaseOf<nsISupports, mozilla::dom::TCPSocketErrorEvent >::value,
560
  sNativePropertyHooks,
561
  FindAssociatedGlobalForNative<mozilla::dom::TCPSocketErrorEvent>::Get,
562
  GetProtoObjectHandle,
563
  GetCCParticipant<mozilla::dom::TCPSocketErrorEvent>::Get()
564
};
565
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
566
              "Must have the right minimal number of reserved slots.");
567
static_assert(1 >= 1,
568
              "Must have enough reserved slots.");
569
570
const JSClass*
571
GetJSClass()
572
0
{
573
0
  return sClass.ToJSClass();
574
0
}
575
576
bool
577
Wrap(JSContext* aCx, mozilla::dom::TCPSocketErrorEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
578
0
{
579
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::TCPSocketErrorEvent>::value,
580
0
                "Shouldn't have wrappercached things that are not refcounted.");
581
0
  MOZ_ASSERT(static_cast<mozilla::dom::TCPSocketErrorEvent*>(aObject) ==
582
0
             reinterpret_cast<mozilla::dom::TCPSocketErrorEvent*>(aObject),
583
0
             "Multiple inheritance for mozilla::dom::TCPSocketErrorEvent is broken.");
584
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
585
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
586
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
587
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
588
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
589
0
  MOZ_ASSERT(!aCache->GetWrapper(),
590
0
             "You should probably not be using Wrap() directly; use "
591
0
             "GetOrCreateDOMReflector instead");
592
0
593
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
594
0
             "nsISupports must be on our primary inheritance chain");
595
0
596
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
597
0
  if (!global) {
598
0
    return false;
599
0
  }
600
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
601
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
602
0
603
0
  // That might have ended up wrapping us already, due to the wonders
604
0
  // of XBL.  Check for that, and bail out as needed.
605
0
  aReflector.set(aCache->GetWrapper());
606
0
  if (aReflector) {
607
#ifdef DEBUG
608
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
609
#endif // DEBUG
610
    return true;
611
0
  }
612
0
613
0
  JSAutoRealm ar(aCx, global);
614
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
615
0
  if (!canonicalProto) {
616
0
    return false;
617
0
  }
618
0
  JS::Rooted<JSObject*> proto(aCx);
619
0
  if (aGivenProto) {
620
0
    proto = aGivenProto;
621
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
622
0
    // coming in, we changed compartments to that of "parent" so may need
623
0
    // to wrap the proto here.
624
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
625
0
      if (!JS_WrapObject(aCx, &proto)) {
626
0
        return false;
627
0
      }
628
0
    }
629
0
  } else {
630
0
    proto = canonicalProto;
631
0
  }
632
0
633
0
  BindingJSObjectCreator<mozilla::dom::TCPSocketErrorEvent> creator(aCx);
634
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
635
0
  if (!aReflector) {
636
0
    return false;
637
0
  }
638
0
639
0
  aCache->SetWrapper(aReflector);
640
0
641
0
  // Important: do unforgeable property setup after we have handed
642
0
  // over ownership of the C++ object to obj as needed, so that if
643
0
  // we fail and it ends up GCed it won't have problems in the
644
0
  // finalizer trying to drop its ownership of the C++ object.
645
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
646
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
647
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
648
0
    aCache->ReleaseWrapper(aObject);
649
0
    aCache->ClearWrapper();
650
0
    return false;
651
0
  }
652
0
  creator.InitializationSucceeded();
653
0
654
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
655
0
             aCache->GetWrapperPreserveColor() == aReflector);
656
0
  // If proto != canonicalProto, we have to preserve our wrapper;
657
0
  // otherwise we won't be able to properly recreate it later, since
658
0
  // we won't know what proto to use.  Note that we don't check
659
0
  // aGivenProto here, since it's entirely possible (and even
660
0
  // somewhat common) to have a non-null aGivenProto which is the
661
0
  // same as canonicalProto.
662
0
  if (proto != canonicalProto) {
663
0
    PreserveWrapper(aObject);
664
0
  }
665
0
666
0
  return true;
667
0
}
668
669
const NativePropertyHooks sNativePropertyHooks[] = { {
670
  nullptr,
671
  nullptr,
672
  nullptr,
673
  { sNativeProperties.Upcast(), nullptr },
674
  prototypes::id::TCPSocketErrorEvent,
675
  constructors::id::TCPSocketErrorEvent,
676
  Event_Binding::sNativePropertyHooks,
677
  &DefaultXrayExpandoObjectClass
678
} };
679
680
void
681
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
682
0
{
683
0
  JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx));
684
0
  if (!parentProto) {
685
0
    return;
686
0
  }
687
0
688
0
  JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx));
689
0
  if (!constructorProto) {
690
0
    return;
691
0
  }
692
0
693
0
  static bool sIdsInited = false;
694
0
  if (!sIdsInited && NS_IsMainThread()) {
695
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
696
0
      return;
697
0
    }
698
0
    sIdsInited = true;
699
0
  }
700
0
701
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TCPSocketErrorEvent);
702
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TCPSocketErrorEvent);
703
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
704
0
                              &sPrototypeClass.mBase, protoCache,
705
0
                              nullptr,
706
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
707
0
                              interfaceCache,
708
0
                              sNativeProperties.Upcast(),
709
0
                              nullptr,
710
0
                              "TCPSocketErrorEvent", aDefineOnGlobal,
711
0
                              nullptr,
712
0
                              false);
713
0
714
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
715
0
  {
716
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
717
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
718
0
    if (!unforgeableHolder) {
719
0
      *protoCache = nullptr;
720
0
      if (interfaceCache) {
721
0
        *interfaceCache = nullptr;
722
0
      }
723
0
      return;
724
0
    }
725
0
  }
726
0
727
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
728
0
    *protoCache = nullptr;
729
0
    if (interfaceCache) {
730
0
      *interfaceCache = nullptr;
731
0
    }
732
0
    return;
733
0
  }
734
0
735
0
  if (*protoCache) {
736
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
737
0
                        JS::ObjectValue(*unforgeableHolder));
738
0
  }
739
0
}
740
741
JSObject*
742
GetConstructorObject(JSContext* aCx)
743
0
{
744
0
  return GetConstructorObjectHandle(aCx);
745
0
}
746
747
} // namespace TCPSocketErrorEvent_Binding
748
749
750
751
} // namespace dom
752
} // namespace mozilla