Coverage Report

Created: 2018-09-25 14:53

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