Coverage Report

Created: 2018-09-25 14:53

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