Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/DOMPointBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM DOMPoint.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "DOMPointBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/Preferences.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/DOMPoint.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/ScriptSettings.h"
14
#include "mozilla/dom/XrayExpandoClass.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
namespace binding_detail {}; // Just to make sure it's known as a namespace
20
using namespace mozilla::dom::binding_detail;
21
22
23
24
DOMPointInit::DOMPointInit()
25
0
{
26
0
  // Safe to pass a null context if we pass a null value
27
0
  Init(nullptr, JS::NullHandleValue);
28
0
}
29
30
31
32
bool
33
DOMPointInit::InitIds(JSContext* cx, DOMPointInitAtoms* atomsCache)
34
0
{
35
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
36
0
37
0
  // Initialize these in reverse order so that any failure leaves the first one
38
0
  // uninitialized.
39
0
  if (!atomsCache->z_id.init(cx, "z") ||
40
0
      !atomsCache->y_id.init(cx, "y") ||
41
0
      !atomsCache->x_id.init(cx, "x") ||
42
0
      !atomsCache->w_id.init(cx, "w")) {
43
0
    return false;
44
0
  }
45
0
  return true;
46
0
}
47
48
bool
49
DOMPointInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
50
0
{
51
0
  // Passing a null JSContext is OK only if we're initing from null,
52
0
  // Since in that case we will not have to do any property gets
53
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
54
0
  // checkers by static analysis tools
55
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
56
0
  DOMPointInitAtoms* atomsCache = nullptr;
57
0
  if (cx) {
58
0
    atomsCache = GetAtomCache<DOMPointInitAtoms>(cx);
59
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60
0
      return false;
61
0
    }
62
0
  }
63
0
64
0
  if (!IsConvertibleToDictionary(val)) {
65
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
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->w_id, temp.ptr())) {
79
0
      return false;
80
0
    }
81
0
  }
82
0
  if (!isNull && !temp->isUndefined()) {
83
0
    if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mW)) {
84
0
      return false;
85
0
    }
86
0
  } else {
87
0
    mW = 1.0;
88
0
  }
89
0
  mIsAnyMemberPresent = true;
90
0
91
0
  if (!isNull) {
92
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->x_id, temp.ptr())) {
93
0
      return false;
94
0
    }
95
0
  }
96
0
  if (!isNull && !temp->isUndefined()) {
97
0
    if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mX)) {
98
0
      return false;
99
0
    }
100
0
  } else {
101
0
    mX = 0.0;
102
0
  }
103
0
  mIsAnyMemberPresent = true;
104
0
105
0
  if (!isNull) {
106
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->y_id, temp.ptr())) {
107
0
      return false;
108
0
    }
109
0
  }
110
0
  if (!isNull && !temp->isUndefined()) {
111
0
    if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mY)) {
112
0
      return false;
113
0
    }
114
0
  } else {
115
0
    mY = 0.0;
116
0
  }
117
0
  mIsAnyMemberPresent = true;
118
0
119
0
  if (!isNull) {
120
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->z_id, temp.ptr())) {
121
0
      return false;
122
0
    }
123
0
  }
124
0
  if (!isNull && !temp->isUndefined()) {
125
0
    if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mZ)) {
126
0
      return false;
127
0
    }
128
0
  } else {
129
0
    mZ = 0.0;
130
0
  }
131
0
  mIsAnyMemberPresent = true;
132
0
  return true;
133
0
}
134
135
bool
136
DOMPointInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
137
0
{
138
0
  DOMPointInitAtoms* atomsCache = GetAtomCache<DOMPointInitAtoms>(cx);
139
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
140
0
    return false;
141
0
  }
142
0
143
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
144
0
  if (!obj) {
145
0
    return false;
146
0
  }
147
0
  rval.set(JS::ObjectValue(*obj));
148
0
149
0
  do {
150
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
151
0
    JS::Rooted<JS::Value> temp(cx);
152
0
    double const & currentValue = mW;
153
0
    temp.set(JS_NumberValue(double(currentValue)));
154
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->w_id, temp, JSPROP_ENUMERATE)) {
155
0
      return false;
156
0
    }
157
0
    break;
158
0
  } while(false);
159
0
160
0
  do {
161
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
162
0
    JS::Rooted<JS::Value> temp(cx);
163
0
    double const & currentValue = mX;
164
0
    temp.set(JS_NumberValue(double(currentValue)));
165
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->x_id, temp, JSPROP_ENUMERATE)) {
166
0
      return false;
167
0
    }
168
0
    break;
169
0
  } while(false);
170
0
171
0
  do {
172
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
173
0
    JS::Rooted<JS::Value> temp(cx);
174
0
    double const & currentValue = mY;
175
0
    temp.set(JS_NumberValue(double(currentValue)));
176
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->y_id, temp, JSPROP_ENUMERATE)) {
177
0
      return false;
178
0
    }
179
0
    break;
180
0
  } while(false);
181
0
182
0
  do {
183
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
184
0
    JS::Rooted<JS::Value> temp(cx);
185
0
    double const & currentValue = mZ;
186
0
    temp.set(JS_NumberValue(double(currentValue)));
187
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->z_id, temp, JSPROP_ENUMERATE)) {
188
0
      return false;
189
0
    }
190
0
    break;
191
0
  } while(false);
192
0
193
0
  return true;
194
0
}
195
196
void
197
DOMPointInit::TraceDictionary(JSTracer* trc)
198
0
{
199
0
}
200
201
DOMPointInit&
202
DOMPointInit::operator=(const DOMPointInit& aOther)
203
0
{
204
0
  DictionaryBase::operator=(aOther);
205
0
  mW = aOther.mW;
206
0
  mX = aOther.mX;
207
0
  mY = aOther.mY;
208
0
  mZ = aOther.mZ;
209
0
  return *this;
210
0
}
211
212
namespace binding_detail {
213
} // namespace binding_detail
214
215
216
namespace DOMPoint_Binding {
217
218
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<DOMPointReadOnly_Binding::NativeType>::value,
219
              "Can't inherit from an interface with a different ownership model.");
220
221
static bool
222
fromPoint(JSContext* cx, unsigned argc, JS::Value* vp)
223
0
{
224
0
  AUTO_PROFILER_LABEL_FAST("DOMPoint.fromPoint", DOM, cx);
225
0
226
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
227
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
228
0
229
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
230
0
  if (global.Failed()) {
231
0
    return false;
232
0
  }
233
0
234
0
  binding_detail::FastDOMPointInit arg0;
235
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of DOMPoint.fromPoint", false)) {
236
0
    return false;
237
0
  }
238
0
  auto result(StrongOrRawPtr<mozilla::dom::DOMPoint>(mozilla::dom::DOMPoint::FromPoint(global, Constify(arg0))));
239
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
240
0
  static_assert(!IsPointer<decltype(result)>::value,
241
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
242
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
243
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
244
0
    return false;
245
0
  }
246
0
  return true;
247
0
}
248
249
MOZ_CAN_RUN_SCRIPT static bool
250
get_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitGetterCallArgs args)
251
0
{
252
0
  AUTO_PROFILER_LABEL_FAST("get DOMPoint.x", DOM, cx);
253
0
254
0
  double result(self->X());
255
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
256
0
  args.rval().set(JS_NumberValue(double(result)));
257
0
  return true;
258
0
}
259
260
MOZ_CAN_RUN_SCRIPT static bool
261
set_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitSetterCallArgs args)
262
0
{
263
0
  AUTO_PROFILER_LABEL_FAST("set DOMPoint.x", DOM, cx);
264
0
265
0
  double arg0;
266
0
  if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
267
0
    return false;
268
0
  }
269
0
  self->SetX(arg0);
270
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
271
0
272
0
  return true;
273
0
}
274
275
static const JSJitInfo x_getterinfo = {
276
  { (JSJitGetterOp)get_x },
277
  { prototypes::id::DOMPoint },
278
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
279
  JSJitInfo::Getter,
280
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
281
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
282
  true,  /* isInfallible. False in setters. */
283
  false,  /* isMovable.  Not relevant for setters. */
284
  false, /* isEliminatable.  Not relevant for setters. */
285
  false, /* isAlwaysInSlot.  Only relevant for getters. */
286
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
287
  false,  /* isTypedMethod.  Only relevant for methods. */
288
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
289
};
290
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
291
static_assert(0 < 1, "There is no slot for us");
292
static const JSJitInfo x_setterinfo = {
293
  { (JSJitGetterOp)set_x },
294
  { prototypes::id::DOMPoint },
295
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
296
  JSJitInfo::Setter,
297
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
298
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
299
  false,  /* isInfallible. False in setters. */
300
  false,  /* isMovable.  Not relevant for setters. */
301
  false, /* isEliminatable.  Not relevant for setters. */
302
  false, /* isAlwaysInSlot.  Only relevant for getters. */
303
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
304
  false,  /* isTypedMethod.  Only relevant for methods. */
305
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
306
};
307
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
308
static_assert(0 < 1, "There is no slot for us");
309
310
MOZ_CAN_RUN_SCRIPT static bool
311
get_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitGetterCallArgs args)
312
0
{
313
0
  AUTO_PROFILER_LABEL_FAST("get DOMPoint.y", DOM, cx);
314
0
315
0
  double result(self->Y());
316
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
317
0
  args.rval().set(JS_NumberValue(double(result)));
318
0
  return true;
319
0
}
320
321
MOZ_CAN_RUN_SCRIPT static bool
322
set_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitSetterCallArgs args)
323
0
{
324
0
  AUTO_PROFILER_LABEL_FAST("set DOMPoint.y", DOM, cx);
325
0
326
0
  double arg0;
327
0
  if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
328
0
    return false;
329
0
  }
330
0
  self->SetY(arg0);
331
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
332
0
333
0
  return true;
334
0
}
335
336
static const JSJitInfo y_getterinfo = {
337
  { (JSJitGetterOp)get_y },
338
  { prototypes::id::DOMPoint },
339
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
340
  JSJitInfo::Getter,
341
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
342
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
343
  true,  /* isInfallible. False in setters. */
344
  false,  /* isMovable.  Not relevant for setters. */
345
  false, /* isEliminatable.  Not relevant for setters. */
346
  false, /* isAlwaysInSlot.  Only relevant for getters. */
347
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
348
  false,  /* isTypedMethod.  Only relevant for methods. */
349
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
350
};
351
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
352
static_assert(0 < 1, "There is no slot for us");
353
static const JSJitInfo y_setterinfo = {
354
  { (JSJitGetterOp)set_y },
355
  { prototypes::id::DOMPoint },
356
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
357
  JSJitInfo::Setter,
358
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
359
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
360
  false,  /* isInfallible. False in setters. */
361
  false,  /* isMovable.  Not relevant for setters. */
362
  false, /* isEliminatable.  Not relevant for setters. */
363
  false, /* isAlwaysInSlot.  Only relevant for getters. */
364
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
365
  false,  /* isTypedMethod.  Only relevant for methods. */
366
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
367
};
368
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
369
static_assert(0 < 1, "There is no slot for us");
370
371
MOZ_CAN_RUN_SCRIPT static bool
372
get_z(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitGetterCallArgs args)
373
0
{
374
0
  AUTO_PROFILER_LABEL_FAST("get DOMPoint.z", DOM, cx);
375
0
376
0
  double result(self->Z());
377
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
378
0
  args.rval().set(JS_NumberValue(double(result)));
379
0
  return true;
380
0
}
381
382
MOZ_CAN_RUN_SCRIPT static bool
383
set_z(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitSetterCallArgs args)
384
0
{
385
0
  AUTO_PROFILER_LABEL_FAST("set DOMPoint.z", DOM, cx);
386
0
387
0
  double arg0;
388
0
  if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
389
0
    return false;
390
0
  }
391
0
  self->SetZ(arg0);
392
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
393
0
394
0
  return true;
395
0
}
396
397
static const JSJitInfo z_getterinfo = {
398
  { (JSJitGetterOp)get_z },
399
  { prototypes::id::DOMPoint },
400
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
401
  JSJitInfo::Getter,
402
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
403
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
404
  true,  /* isInfallible. False in setters. */
405
  false,  /* isMovable.  Not relevant for setters. */
406
  false, /* isEliminatable.  Not relevant for setters. */
407
  false, /* isAlwaysInSlot.  Only relevant for getters. */
408
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
409
  false,  /* isTypedMethod.  Only relevant for methods. */
410
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
411
};
412
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
413
static_assert(0 < 1, "There is no slot for us");
414
static const JSJitInfo z_setterinfo = {
415
  { (JSJitGetterOp)set_z },
416
  { prototypes::id::DOMPoint },
417
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
418
  JSJitInfo::Setter,
419
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
420
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
421
  false,  /* isInfallible. False in setters. */
422
  false,  /* isMovable.  Not relevant for setters. */
423
  false, /* isEliminatable.  Not relevant for setters. */
424
  false, /* isAlwaysInSlot.  Only relevant for getters. */
425
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
426
  false,  /* isTypedMethod.  Only relevant for methods. */
427
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
428
};
429
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
430
static_assert(0 < 1, "There is no slot for us");
431
432
MOZ_CAN_RUN_SCRIPT static bool
433
get_w(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitGetterCallArgs args)
434
0
{
435
0
  AUTO_PROFILER_LABEL_FAST("get DOMPoint.w", DOM, cx);
436
0
437
0
  double result(self->W());
438
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
439
0
  args.rval().set(JS_NumberValue(double(result)));
440
0
  return true;
441
0
}
442
443
MOZ_CAN_RUN_SCRIPT static bool
444
set_w(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPoint* self, JSJitSetterCallArgs args)
445
0
{
446
0
  AUTO_PROFILER_LABEL_FAST("set DOMPoint.w", DOM, cx);
447
0
448
0
  double arg0;
449
0
  if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
450
0
    return false;
451
0
  }
452
0
  self->SetW(arg0);
453
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
454
0
455
0
  return true;
456
0
}
457
458
static const JSJitInfo w_getterinfo = {
459
  { (JSJitGetterOp)get_w },
460
  { prototypes::id::DOMPoint },
461
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
462
  JSJitInfo::Getter,
463
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
464
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
465
  true,  /* isInfallible. False in setters. */
466
  false,  /* isMovable.  Not relevant for setters. */
467
  false, /* isEliminatable.  Not relevant for setters. */
468
  false, /* isAlwaysInSlot.  Only relevant for getters. */
469
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
470
  false,  /* isTypedMethod.  Only relevant for methods. */
471
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
472
};
473
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
474
static_assert(0 < 1, "There is no slot for us");
475
static const JSJitInfo w_setterinfo = {
476
  { (JSJitGetterOp)set_w },
477
  { prototypes::id::DOMPoint },
478
  { PrototypeTraits<prototypes::id::DOMPoint>::Depth },
479
  JSJitInfo::Setter,
480
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
481
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
482
  false,  /* isInfallible. False in setters. */
483
  false,  /* isMovable.  Not relevant for setters. */
484
  false, /* isEliminatable.  Not relevant for setters. */
485
  false, /* isAlwaysInSlot.  Only relevant for getters. */
486
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
487
  false,  /* isTypedMethod.  Only relevant for methods. */
488
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
489
};
490
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
491
static_assert(0 < 1, "There is no slot for us");
492
493
static bool
494
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
495
0
{
496
0
  mozilla::dom::DOMPoint* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMPoint>(obj);
497
0
  // We don't want to preserve if we don't have a wrapper, and we
498
0
  // obviously can't preserve if we're not initialized.
499
0
  if (self && self->GetWrapperPreserveColor()) {
500
0
    PreserveWrapper(self);
501
0
  }
502
0
  return true;
503
0
}
504
505
static void
506
_finalize(js::FreeOp* fop, JSObject* obj)
507
0
{
508
0
  mozilla::dom::DOMPoint* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMPoint>(obj);
509
0
  if (self) {
510
0
    ClearWrapper(self, self, obj);
511
0
    AddForDeferredFinalization<mozilla::dom::DOMPoint>(self);
512
0
  }
513
0
}
514
515
static size_t
516
_objectMoved(JSObject* obj, JSObject* old)
517
0
{
518
0
  mozilla::dom::DOMPoint* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMPoint>(obj);
519
0
  if (self) {
520
0
    UpdateWrapper(self, self, obj, old);
521
0
  }
522
0
523
0
  return 0;
524
0
}
525
526
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
527
#if defined(__clang__)
528
#pragma clang diagnostic push
529
#pragma clang diagnostic ignored "-Wmissing-braces"
530
#endif
531
static const JSFunctionSpec sStaticMethods_specs[] = {
532
  JS_FNSPEC("fromPoint", fromPoint, nullptr, 0, JSPROP_ENUMERATE, nullptr),
533
  JS_FS_END
534
};
535
#if defined(__clang__)
536
#pragma clang diagnostic pop
537
#endif
538
539
540
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
541
  { nullptr, &sStaticMethods_specs[0] },
542
  { nullptr, nullptr }
543
};
544
545
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
546
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
547
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
548
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
549
550
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
551
#if defined(__clang__)
552
#pragma clang diagnostic push
553
#pragma clang diagnostic ignored "-Wmissing-braces"
554
#endif
555
static const JSPropertySpec sAttributes_specs[] = {
556
  { "x", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &x_getterinfo, GenericSetter<NormalThisPolicy>, &x_setterinfo },
557
  { "y", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &y_getterinfo, GenericSetter<NormalThisPolicy>, &y_setterinfo },
558
  { "z", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &z_getterinfo, GenericSetter<NormalThisPolicy>, &z_setterinfo },
559
  { "w", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &w_getterinfo, GenericSetter<NormalThisPolicy>, &w_setterinfo },
560
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
561
};
562
#if defined(__clang__)
563
#pragma clang diagnostic pop
564
#endif
565
566
567
static const Prefable<const JSPropertySpec> sAttributes[] = {
568
  { nullptr, &sAttributes_specs[0] },
569
  { nullptr, nullptr }
570
};
571
572
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
573
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
574
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
575
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
576
577
578
static uint16_t sNativeProperties_sortedPropertyIndices[5];
579
static PropertyInfo sNativeProperties_propertyInfos[5];
580
581
static const NativePropertiesN<2> sNativeProperties = {
582
  true,  0 /* sStaticMethods */,
583
  false, 0,
584
  false, 0,
585
  true,  1 /* sAttributes */,
586
  false, 0,
587
  false, 0,
588
  false, 0,
589
  -1,
590
  5,
591
  sNativeProperties_sortedPropertyIndices,
592
  {
593
    { sStaticMethods, &sNativeProperties_propertyInfos[0] },
594
    { sAttributes, &sNativeProperties_propertyInfos[1] }
595
  }
596
};
597
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
598
    "We have a property info count that is oversized");
599
600
static bool
601
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
602
0
{
603
0
  AUTO_PROFILER_LABEL_FAST("DOMPoint constructor", DOM, cx);
604
0
605
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
606
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
607
0
  if (!args.isConstructing()) {
608
0
    // XXXbz wish I could get the name from the callee instead of
609
0
    // Adding more relocations
610
0
    return ThrowConstructorWithoutNew(cx, "DOMPoint");
611
0
  }
612
0
613
0
  JS::Rooted<JSObject*> desiredProto(cx);
614
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
615
0
    return false;
616
0
  }
617
0
618
0
  GlobalObject global(cx, obj);
619
0
  if (global.Failed()) {
620
0
    return false;
621
0
  }
622
0
623
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
624
0
  double arg0;
625
0
  if (args.hasDefined(0)) {
626
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
627
0
      return false;
628
0
    }
629
0
  } else {
630
0
    arg0 = 0.0;
631
0
  }
632
0
  double arg1;
633
0
  if (args.hasDefined(1)) {
634
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) {
635
0
      return false;
636
0
    }
637
0
  } else {
638
0
    arg1 = 0.0;
639
0
  }
640
0
  double arg2;
641
0
  if (args.hasDefined(2)) {
642
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[2], &arg2)) {
643
0
      return false;
644
0
    }
645
0
  } else {
646
0
    arg2 = 0.0;
647
0
  }
648
0
  double arg3;
649
0
  if (args.hasDefined(3)) {
650
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[3], &arg3)) {
651
0
      return false;
652
0
    }
653
0
  } else {
654
0
    arg3 = 1.0;
655
0
  }
656
0
  Maybe<JSAutoRealm> ar;
657
0
  if (objIsXray) {
658
0
    obj = js::CheckedUnwrap(obj);
659
0
    if (!obj) {
660
0
      return false;
661
0
    }
662
0
    ar.emplace(cx, obj);
663
0
    if (!JS_WrapObject(cx, &desiredProto)) {
664
0
      return false;
665
0
    }
666
0
  }
667
0
  FastErrorResult rv;
668
0
  auto result(StrongOrRawPtr<mozilla::dom::DOMPoint>(mozilla::dom::DOMPoint::Constructor(global, arg0, arg1, arg2, arg3, rv)));
669
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
670
0
    return false;
671
0
  }
672
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
673
0
  static_assert(!IsPointer<decltype(result)>::value,
674
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
675
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
676
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
677
0
    return false;
678
0
  }
679
0
  return true;
680
0
}
681
682
static const js::ClassOps sInterfaceObjectClassOps = {
683
    nullptr,               /* addProperty */
684
    nullptr,               /* delProperty */
685
    nullptr,               /* enumerate */
686
    nullptr,               /* newEnumerate */
687
    nullptr,               /* resolve */
688
    nullptr,               /* mayResolve */
689
    nullptr,               /* finalize */
690
    _constructor, /* call */
691
    nullptr,               /* hasInstance */
692
    _constructor, /* construct */
693
    nullptr,               /* trace */
694
};
695
696
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
697
  {
698
    "Function",
699
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
700
    &sInterfaceObjectClassOps,
701
    JS_NULL_CLASS_SPEC,
702
    JS_NULL_CLASS_EXT,
703
    &sInterfaceObjectClassObjectOps
704
  },
705
  eInterface,
706
  true,
707
  prototypes::id::DOMPoint,
708
  PrototypeTraits<prototypes::id::DOMPoint>::Depth,
709
  sNativePropertyHooks,
710
  "function DOMPoint() {\n    [native code]\n}",
711
  DOMPointReadOnly_Binding::GetConstructorObject
712
};
713
714
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
715
  {
716
    "DOMPointPrototype",
717
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
718
    JS_NULL_CLASS_OPS,
719
    JS_NULL_CLASS_SPEC,
720
    JS_NULL_CLASS_EXT,
721
    JS_NULL_OBJECT_OPS
722
  },
723
  eInterfacePrototype,
724
  false,
725
  prototypes::id::DOMPoint,
726
  PrototypeTraits<prototypes::id::DOMPoint>::Depth,
727
  sNativePropertyHooks,
728
  "[object DOMPointPrototype]",
729
  DOMPointReadOnly_Binding::GetProtoObject
730
};
731
732
bool
733
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
734
0
{
735
0
  static bool sPrefValue;
736
0
  static bool sPrefCacheSetUp = false;
737
0
  if (!sPrefCacheSetUp) {
738
0
    sPrefCacheSetUp = true;
739
0
    Preferences::AddBoolVarCache(&sPrefValue, "layout.css.DOMPoint.enabled");
740
0
  }
741
0
742
0
  return sPrefValue;
743
0
}
744
745
static const js::ClassOps sClassOps = {
746
  _addProperty, /* addProperty */
747
  nullptr,               /* delProperty */
748
  nullptr,               /* enumerate */
749
  nullptr, /* newEnumerate */
750
  nullptr, /* resolve */
751
  nullptr, /* mayResolve */
752
  _finalize, /* finalize */
753
  nullptr, /* call */
754
  nullptr,               /* hasInstance */
755
  nullptr,               /* construct */
756
  nullptr, /* trace */
757
};
758
759
static const js::ClassExtension sClassExtension = {
760
  nullptr, /* weakmapKeyDelegateOp */
761
  _objectMoved /* objectMovedOp */
762
};
763
764
static const DOMJSClass sClass = {
765
  { "DOMPoint",
766
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
767
    &sClassOps,
768
    JS_NULL_CLASS_SPEC,
769
    &sClassExtension,
770
    JS_NULL_OBJECT_OPS
771
  },
772
  { prototypes::id::DOMPointReadOnly, prototypes::id::DOMPoint, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
773
  IsBaseOf<nsISupports, mozilla::dom::DOMPoint >::value,
774
  sNativePropertyHooks,
775
  FindAssociatedGlobalForNative<mozilla::dom::DOMPoint>::Get,
776
  GetProtoObjectHandle,
777
  GetCCParticipant<mozilla::dom::DOMPoint>::Get()
778
};
779
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
780
              "Must have the right minimal number of reserved slots.");
781
static_assert(1 >= 1,
782
              "Must have enough reserved slots.");
783
784
const JSClass*
785
GetJSClass()
786
0
{
787
0
  return sClass.ToJSClass();
788
0
}
789
790
bool
791
Wrap(JSContext* aCx, mozilla::dom::DOMPoint* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
792
0
{
793
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DOMPoint>::value,
794
0
                "Shouldn't have wrappercached things that are not refcounted.");
795
0
  MOZ_ASSERT(static_cast<mozilla::dom::DOMPoint*>(aObject) ==
796
0
             reinterpret_cast<mozilla::dom::DOMPoint*>(aObject),
797
0
             "Multiple inheritance for mozilla::dom::DOMPoint is broken.");
798
0
  MOZ_ASSERT(static_cast<mozilla::dom::DOMPointReadOnly*>(aObject) ==
799
0
             reinterpret_cast<mozilla::dom::DOMPointReadOnly*>(aObject),
800
0
             "Multiple inheritance for mozilla::dom::DOMPointReadOnly is broken.");
801
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
802
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
803
0
  MOZ_ASSERT(!aCache->GetWrapper(),
804
0
             "You should probably not be using Wrap() directly; use "
805
0
             "GetOrCreateDOMReflector instead");
806
0
807
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
808
0
             "nsISupports must be on our primary inheritance chain");
809
0
810
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
811
0
  if (!global) {
812
0
    return false;
813
0
  }
814
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
815
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
816
0
817
0
  // That might have ended up wrapping us already, due to the wonders
818
0
  // of XBL.  Check for that, and bail out as needed.
819
0
  aReflector.set(aCache->GetWrapper());
820
0
  if (aReflector) {
821
#ifdef DEBUG
822
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
823
#endif // DEBUG
824
    return true;
825
0
  }
826
0
827
0
  JSAutoRealm ar(aCx, global);
828
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
829
0
  if (!canonicalProto) {
830
0
    return false;
831
0
  }
832
0
  JS::Rooted<JSObject*> proto(aCx);
833
0
  if (aGivenProto) {
834
0
    proto = aGivenProto;
835
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
836
0
    // coming in, we changed compartments to that of "parent" so may need
837
0
    // to wrap the proto here.
838
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
839
0
      if (!JS_WrapObject(aCx, &proto)) {
840
0
        return false;
841
0
      }
842
0
    }
843
0
  } else {
844
0
    proto = canonicalProto;
845
0
  }
846
0
847
0
  BindingJSObjectCreator<mozilla::dom::DOMPoint> creator(aCx);
848
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
849
0
  if (!aReflector) {
850
0
    return false;
851
0
  }
852
0
853
0
  aCache->SetWrapper(aReflector);
854
0
  creator.InitializationSucceeded();
855
0
856
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
857
0
             aCache->GetWrapperPreserveColor() == aReflector);
858
0
  // If proto != canonicalProto, we have to preserve our wrapper;
859
0
  // otherwise we won't be able to properly recreate it later, since
860
0
  // we won't know what proto to use.  Note that we don't check
861
0
  // aGivenProto here, since it's entirely possible (and even
862
0
  // somewhat common) to have a non-null aGivenProto which is the
863
0
  // same as canonicalProto.
864
0
  if (proto != canonicalProto) {
865
0
    PreserveWrapper(aObject);
866
0
  }
867
0
868
0
  return true;
869
0
}
870
871
const NativePropertyHooks sNativePropertyHooks[] = { {
872
  nullptr,
873
  nullptr,
874
  nullptr,
875
  { sNativeProperties.Upcast(), nullptr },
876
  prototypes::id::DOMPoint,
877
  constructors::id::DOMPoint,
878
  DOMPointReadOnly_Binding::sNativePropertyHooks,
879
  &DefaultXrayExpandoObjectClass
880
} };
881
882
void
883
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
884
0
{
885
0
  JS::Handle<JSObject*> parentProto(DOMPointReadOnly_Binding::GetProtoObjectHandle(aCx));
886
0
  if (!parentProto) {
887
0
    return;
888
0
  }
889
0
890
0
  JS::Handle<JSObject*> constructorProto(DOMPointReadOnly_Binding::GetConstructorObjectHandle(aCx));
891
0
  if (!constructorProto) {
892
0
    return;
893
0
  }
894
0
895
0
  static bool sIdsInited = false;
896
0
  if (!sIdsInited && NS_IsMainThread()) {
897
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
898
0
      return;
899
0
    }
900
0
    sIdsInited = true;
901
0
  }
902
0
903
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMPoint);
904
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMPoint);
905
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
906
0
                              &sPrototypeClass.mBase, protoCache,
907
0
                              nullptr,
908
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
909
0
                              interfaceCache,
910
0
                              sNativeProperties.Upcast(),
911
0
                              nullptr,
912
0
                              "DOMPoint", aDefineOnGlobal,
913
0
                              nullptr,
914
0
                              false);
915
0
}
916
917
JSObject*
918
GetConstructorObject(JSContext* aCx)
919
0
{
920
0
  return GetConstructorObjectHandle(aCx);
921
0
}
922
923
} // namespace DOMPoint_Binding
924
925
926
927
namespace DOMPointReadOnly_Binding {
928
929
static bool
930
fromPoint(JSContext* cx, unsigned argc, JS::Value* vp)
931
0
{
932
0
  AUTO_PROFILER_LABEL_FAST("DOMPointReadOnly.fromPoint", DOM, cx);
933
0
934
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
935
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
936
0
937
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
938
0
  if (global.Failed()) {
939
0
    return false;
940
0
  }
941
0
942
0
  binding_detail::FastDOMPointInit arg0;
943
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of DOMPointReadOnly.fromPoint", false)) {
944
0
    return false;
945
0
  }
946
0
  auto result(StrongOrRawPtr<mozilla::dom::DOMPointReadOnly>(mozilla::dom::DOMPointReadOnly::FromPoint(global, Constify(arg0))));
947
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
948
0
  static_assert(!IsPointer<decltype(result)>::value,
949
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
950
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
951
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
952
0
    return false;
953
0
  }
954
0
  return true;
955
0
}
956
957
MOZ_CAN_RUN_SCRIPT static bool
958
get_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPointReadOnly* self, JSJitGetterCallArgs args)
959
0
{
960
0
  AUTO_PROFILER_LABEL_FAST("get DOMPointReadOnly.x", DOM, cx);
961
0
962
0
  double result(self->X());
963
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
964
0
  args.rval().set(JS_NumberValue(double(result)));
965
0
  return true;
966
0
}
967
968
static const JSJitInfo x_getterinfo = {
969
  { (JSJitGetterOp)get_x },
970
  { prototypes::id::DOMPointReadOnly },
971
  { PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth },
972
  JSJitInfo::Getter,
973
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
974
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
975
  true,  /* isInfallible. False in setters. */
976
  false,  /* isMovable.  Not relevant for setters. */
977
  false, /* isEliminatable.  Not relevant for setters. */
978
  false, /* isAlwaysInSlot.  Only relevant for getters. */
979
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
980
  false,  /* isTypedMethod.  Only relevant for methods. */
981
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
982
};
983
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
984
static_assert(0 < 1, "There is no slot for us");
985
986
MOZ_CAN_RUN_SCRIPT static bool
987
get_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPointReadOnly* self, JSJitGetterCallArgs args)
988
0
{
989
0
  AUTO_PROFILER_LABEL_FAST("get DOMPointReadOnly.y", DOM, cx);
990
0
991
0
  double result(self->Y());
992
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
993
0
  args.rval().set(JS_NumberValue(double(result)));
994
0
  return true;
995
0
}
996
997
static const JSJitInfo y_getterinfo = {
998
  { (JSJitGetterOp)get_y },
999
  { prototypes::id::DOMPointReadOnly },
1000
  { PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth },
1001
  JSJitInfo::Getter,
1002
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1003
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
1004
  true,  /* isInfallible. False in setters. */
1005
  false,  /* isMovable.  Not relevant for setters. */
1006
  false, /* isEliminatable.  Not relevant for setters. */
1007
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1008
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1009
  false,  /* isTypedMethod.  Only relevant for methods. */
1010
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1011
};
1012
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1013
static_assert(0 < 1, "There is no slot for us");
1014
1015
MOZ_CAN_RUN_SCRIPT static bool
1016
get_z(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPointReadOnly* self, JSJitGetterCallArgs args)
1017
0
{
1018
0
  AUTO_PROFILER_LABEL_FAST("get DOMPointReadOnly.z", DOM, cx);
1019
0
1020
0
  double result(self->Z());
1021
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1022
0
  args.rval().set(JS_NumberValue(double(result)));
1023
0
  return true;
1024
0
}
1025
1026
static const JSJitInfo z_getterinfo = {
1027
  { (JSJitGetterOp)get_z },
1028
  { prototypes::id::DOMPointReadOnly },
1029
  { PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth },
1030
  JSJitInfo::Getter,
1031
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1032
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
1033
  true,  /* isInfallible. False in setters. */
1034
  false,  /* isMovable.  Not relevant for setters. */
1035
  false, /* isEliminatable.  Not relevant for setters. */
1036
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1037
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1038
  false,  /* isTypedMethod.  Only relevant for methods. */
1039
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1040
};
1041
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1042
static_assert(0 < 1, "There is no slot for us");
1043
1044
MOZ_CAN_RUN_SCRIPT static bool
1045
get_w(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPointReadOnly* self, JSJitGetterCallArgs args)
1046
0
{
1047
0
  AUTO_PROFILER_LABEL_FAST("get DOMPointReadOnly.w", DOM, cx);
1048
0
1049
0
  double result(self->W());
1050
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1051
0
  args.rval().set(JS_NumberValue(double(result)));
1052
0
  return true;
1053
0
}
1054
1055
static const JSJitInfo w_getterinfo = {
1056
  { (JSJitGetterOp)get_w },
1057
  { prototypes::id::DOMPointReadOnly },
1058
  { PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth },
1059
  JSJitInfo::Getter,
1060
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1061
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
1062
  true,  /* isInfallible. False in setters. */
1063
  false,  /* isMovable.  Not relevant for setters. */
1064
  false, /* isEliminatable.  Not relevant for setters. */
1065
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1066
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1067
  false,  /* isTypedMethod.  Only relevant for methods. */
1068
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1069
};
1070
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1071
static_assert(0 < 1, "There is no slot for us");
1072
1073
MOZ_CAN_RUN_SCRIPT static bool
1074
toJSON(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPointReadOnly* self, const JSJitMethodCallArgs& args)
1075
0
{
1076
0
  AUTO_PROFILER_LABEL_FAST("DOMPointReadOnly.toJSON", DOM, cx);
1077
0
1078
0
  JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx));
1079
0
  if (!result) {
1080
0
    return false;
1081
0
  }
1082
0
  if (!DOMPointReadOnly_Binding::CollectJSONAttributes(cx, obj, self, result)) {
1083
0
    return false;
1084
0
  }
1085
0
  args.rval().setObject(*result);
1086
0
  return true;
1087
0
}
1088
1089
static const JSJitInfo toJSON_methodinfo = {
1090
  { (JSJitGetterOp)toJSON },
1091
  { prototypes::id::DOMPointReadOnly },
1092
  { PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth },
1093
  JSJitInfo::Method,
1094
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1095
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1096
  false,  /* isInfallible. False in setters. */
1097
  false,  /* isMovable.  Not relevant for setters. */
1098
  false, /* isEliminatable.  Not relevant for setters. */
1099
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1100
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1101
  false,  /* isTypedMethod.  Only relevant for methods. */
1102
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1103
};
1104
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1105
static_assert(0 < 1, "There is no slot for us");
1106
1107
static bool
1108
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1109
0
{
1110
0
  mozilla::dom::DOMPointReadOnly* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMPointReadOnly>(obj);
1111
0
  // We don't want to preserve if we don't have a wrapper, and we
1112
0
  // obviously can't preserve if we're not initialized.
1113
0
  if (self && self->GetWrapperPreserveColor()) {
1114
0
    PreserveWrapper(self);
1115
0
  }
1116
0
  return true;
1117
0
}
1118
1119
static void
1120
_finalize(js::FreeOp* fop, JSObject* obj)
1121
0
{
1122
0
  mozilla::dom::DOMPointReadOnly* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMPointReadOnly>(obj);
1123
0
  if (self) {
1124
0
    ClearWrapper(self, self, obj);
1125
0
    AddForDeferredFinalization<mozilla::dom::DOMPointReadOnly>(self);
1126
0
  }
1127
0
}
1128
1129
static size_t
1130
_objectMoved(JSObject* obj, JSObject* old)
1131
0
{
1132
0
  mozilla::dom::DOMPointReadOnly* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMPointReadOnly>(obj);
1133
0
  if (self) {
1134
0
    UpdateWrapper(self, self, obj, old);
1135
0
  }
1136
0
1137
0
  return 0;
1138
0
}
1139
1140
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1141
#if defined(__clang__)
1142
#pragma clang diagnostic push
1143
#pragma clang diagnostic ignored "-Wmissing-braces"
1144
#endif
1145
static const JSFunctionSpec sStaticMethods_specs[] = {
1146
  JS_FNSPEC("fromPoint", fromPoint, nullptr, 0, JSPROP_ENUMERATE, nullptr),
1147
  JS_FS_END
1148
};
1149
#if defined(__clang__)
1150
#pragma clang diagnostic pop
1151
#endif
1152
1153
1154
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
1155
  { nullptr, &sStaticMethods_specs[0] },
1156
  { nullptr, nullptr }
1157
};
1158
1159
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1160
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1161
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1162
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1163
1164
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1165
#if defined(__clang__)
1166
#pragma clang diagnostic push
1167
#pragma clang diagnostic ignored "-Wmissing-braces"
1168
#endif
1169
static const JSFunctionSpec sMethods_specs[] = {
1170
  JS_FNSPEC("toJSON", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&toJSON_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1171
  JS_FS_END
1172
};
1173
#if defined(__clang__)
1174
#pragma clang diagnostic pop
1175
#endif
1176
1177
1178
static const Prefable<const JSFunctionSpec> sMethods[] = {
1179
  { nullptr, &sMethods_specs[0] },
1180
  { nullptr, nullptr }
1181
};
1182
1183
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1184
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1185
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1186
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1187
1188
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1189
#if defined(__clang__)
1190
#pragma clang diagnostic push
1191
#pragma clang diagnostic ignored "-Wmissing-braces"
1192
#endif
1193
static const JSPropertySpec sAttributes_specs[] = {
1194
  { "x", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &x_getterinfo, nullptr, nullptr },
1195
  { "y", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &y_getterinfo, nullptr, nullptr },
1196
  { "z", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &z_getterinfo, nullptr, nullptr },
1197
  { "w", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &w_getterinfo, nullptr, nullptr },
1198
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1199
};
1200
#if defined(__clang__)
1201
#pragma clang diagnostic pop
1202
#endif
1203
1204
1205
static const Prefable<const JSPropertySpec> sAttributes[] = {
1206
  { nullptr, &sAttributes_specs[0] },
1207
  { nullptr, nullptr }
1208
};
1209
1210
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1211
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1212
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1213
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1214
1215
1216
static uint16_t sNativeProperties_sortedPropertyIndices[6];
1217
static PropertyInfo sNativeProperties_propertyInfos[6];
1218
1219
static const NativePropertiesN<3> sNativeProperties = {
1220
  true,  0 /* sStaticMethods */,
1221
  false, 0,
1222
  true,  1 /* sMethods */,
1223
  true,  2 /* sAttributes */,
1224
  false, 0,
1225
  false, 0,
1226
  false, 0,
1227
  -1,
1228
  6,
1229
  sNativeProperties_sortedPropertyIndices,
1230
  {
1231
    { sStaticMethods, &sNativeProperties_propertyInfos[0] },
1232
    { sMethods, &sNativeProperties_propertyInfos[1] },
1233
    { sAttributes, &sNativeProperties_propertyInfos[2] }
1234
  }
1235
};
1236
static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1237
    "We have a property info count that is oversized");
1238
1239
MOZ_CAN_RUN_SCRIPT bool
1240
CollectJSONAttributes(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMPointReadOnly* self, JS::Rooted<JSObject*>& result)
1241
0
{
1242
0
  { // scope for "temp"
1243
0
    JS::Rooted<JS::Value> temp(cx);
1244
0
    if (!get_x(cx, obj, self, JSJitGetterCallArgs(&temp))) {
1245
0
      return false;
1246
0
    }
1247
0
    if (!JS_DefineProperty(cx, result, "x", temp, JSPROP_ENUMERATE)) {
1248
0
      return false;
1249
0
    }
1250
0
  }
1251
0
  { // scope for "temp"
1252
0
    JS::Rooted<JS::Value> temp(cx);
1253
0
    if (!get_y(cx, obj, self, JSJitGetterCallArgs(&temp))) {
1254
0
      return false;
1255
0
    }
1256
0
    if (!JS_DefineProperty(cx, result, "y", temp, JSPROP_ENUMERATE)) {
1257
0
      return false;
1258
0
    }
1259
0
  }
1260
0
  { // scope for "temp"
1261
0
    JS::Rooted<JS::Value> temp(cx);
1262
0
    if (!get_z(cx, obj, self, JSJitGetterCallArgs(&temp))) {
1263
0
      return false;
1264
0
    }
1265
0
    if (!JS_DefineProperty(cx, result, "z", temp, JSPROP_ENUMERATE)) {
1266
0
      return false;
1267
0
    }
1268
0
  }
1269
0
  { // scope for "temp"
1270
0
    JS::Rooted<JS::Value> temp(cx);
1271
0
    if (!get_w(cx, obj, self, JSJitGetterCallArgs(&temp))) {
1272
0
      return false;
1273
0
    }
1274
0
    if (!JS_DefineProperty(cx, result, "w", temp, JSPROP_ENUMERATE)) {
1275
0
      return false;
1276
0
    }
1277
0
  }
1278
0
  return true;
1279
0
}
1280
1281
static bool
1282
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1283
0
{
1284
0
  AUTO_PROFILER_LABEL_FAST("DOMPointReadOnly constructor", DOM, cx);
1285
0
1286
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1287
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1288
0
  if (!args.isConstructing()) {
1289
0
    // XXXbz wish I could get the name from the callee instead of
1290
0
    // Adding more relocations
1291
0
    return ThrowConstructorWithoutNew(cx, "DOMPointReadOnly");
1292
0
  }
1293
0
1294
0
  JS::Rooted<JSObject*> desiredProto(cx);
1295
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1296
0
    return false;
1297
0
  }
1298
0
1299
0
  GlobalObject global(cx, obj);
1300
0
  if (global.Failed()) {
1301
0
    return false;
1302
0
  }
1303
0
1304
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1305
0
  double arg0;
1306
0
  if (args.hasDefined(0)) {
1307
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
1308
0
      return false;
1309
0
    }
1310
0
  } else {
1311
0
    arg0 = 0.0;
1312
0
  }
1313
0
  double arg1;
1314
0
  if (args.hasDefined(1)) {
1315
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) {
1316
0
      return false;
1317
0
    }
1318
0
  } else {
1319
0
    arg1 = 0.0;
1320
0
  }
1321
0
  double arg2;
1322
0
  if (args.hasDefined(2)) {
1323
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[2], &arg2)) {
1324
0
      return false;
1325
0
    }
1326
0
  } else {
1327
0
    arg2 = 0.0;
1328
0
  }
1329
0
  double arg3;
1330
0
  if (args.hasDefined(3)) {
1331
0
    if (!ValueToPrimitive<double, eDefault>(cx, args[3], &arg3)) {
1332
0
      return false;
1333
0
    }
1334
0
  } else {
1335
0
    arg3 = 1.0;
1336
0
  }
1337
0
  Maybe<JSAutoRealm> ar;
1338
0
  if (objIsXray) {
1339
0
    obj = js::CheckedUnwrap(obj);
1340
0
    if (!obj) {
1341
0
      return false;
1342
0
    }
1343
0
    ar.emplace(cx, obj);
1344
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1345
0
      return false;
1346
0
    }
1347
0
  }
1348
0
  FastErrorResult rv;
1349
0
  auto result(StrongOrRawPtr<mozilla::dom::DOMPointReadOnly>(mozilla::dom::DOMPointReadOnly::Constructor(global, arg0, arg1, arg2, arg3, rv)));
1350
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1351
0
    return false;
1352
0
  }
1353
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1354
0
  static_assert(!IsPointer<decltype(result)>::value,
1355
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1356
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1357
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1358
0
    return false;
1359
0
  }
1360
0
  return true;
1361
0
}
1362
1363
static const js::ClassOps sInterfaceObjectClassOps = {
1364
    nullptr,               /* addProperty */
1365
    nullptr,               /* delProperty */
1366
    nullptr,               /* enumerate */
1367
    nullptr,               /* newEnumerate */
1368
    nullptr,               /* resolve */
1369
    nullptr,               /* mayResolve */
1370
    nullptr,               /* finalize */
1371
    _constructor, /* call */
1372
    nullptr,               /* hasInstance */
1373
    _constructor, /* construct */
1374
    nullptr,               /* trace */
1375
};
1376
1377
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1378
  {
1379
    "Function",
1380
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1381
    &sInterfaceObjectClassOps,
1382
    JS_NULL_CLASS_SPEC,
1383
    JS_NULL_CLASS_EXT,
1384
    &sInterfaceObjectClassObjectOps
1385
  },
1386
  eInterface,
1387
  true,
1388
  prototypes::id::DOMPointReadOnly,
1389
  PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth,
1390
  sNativePropertyHooks,
1391
  "function DOMPointReadOnly() {\n    [native code]\n}",
1392
  JS::GetRealmFunctionPrototype
1393
};
1394
1395
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1396
  {
1397
    "DOMPointReadOnlyPrototype",
1398
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1399
    JS_NULL_CLASS_OPS,
1400
    JS_NULL_CLASS_SPEC,
1401
    JS_NULL_CLASS_EXT,
1402
    JS_NULL_OBJECT_OPS
1403
  },
1404
  eInterfacePrototype,
1405
  false,
1406
  prototypes::id::DOMPointReadOnly,
1407
  PrototypeTraits<prototypes::id::DOMPointReadOnly>::Depth,
1408
  sNativePropertyHooks,
1409
  "[object DOMPointReadOnlyPrototype]",
1410
  JS::GetRealmObjectPrototype
1411
};
1412
1413
bool
1414
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1415
0
{
1416
0
  static bool sPrefValue;
1417
0
  static bool sPrefCacheSetUp = false;
1418
0
  if (!sPrefCacheSetUp) {
1419
0
    sPrefCacheSetUp = true;
1420
0
    Preferences::AddBoolVarCache(&sPrefValue, "layout.css.DOMPoint.enabled");
1421
0
  }
1422
0
1423
0
  return sPrefValue;
1424
0
}
1425
1426
static const js::ClassOps sClassOps = {
1427
  _addProperty, /* addProperty */
1428
  nullptr,               /* delProperty */
1429
  nullptr,               /* enumerate */
1430
  nullptr, /* newEnumerate */
1431
  nullptr, /* resolve */
1432
  nullptr, /* mayResolve */
1433
  _finalize, /* finalize */
1434
  nullptr, /* call */
1435
  nullptr,               /* hasInstance */
1436
  nullptr,               /* construct */
1437
  nullptr, /* trace */
1438
};
1439
1440
static const js::ClassExtension sClassExtension = {
1441
  nullptr, /* weakmapKeyDelegateOp */
1442
  _objectMoved /* objectMovedOp */
1443
};
1444
1445
static const DOMJSClass sClass = {
1446
  { "DOMPointReadOnly",
1447
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1448
    &sClassOps,
1449
    JS_NULL_CLASS_SPEC,
1450
    &sClassExtension,
1451
    JS_NULL_OBJECT_OPS
1452
  },
1453
  { prototypes::id::DOMPointReadOnly, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1454
  IsBaseOf<nsISupports, mozilla::dom::DOMPointReadOnly >::value,
1455
  sNativePropertyHooks,
1456
  FindAssociatedGlobalForNative<mozilla::dom::DOMPointReadOnly>::Get,
1457
  GetProtoObjectHandle,
1458
  GetCCParticipant<mozilla::dom::DOMPointReadOnly>::Get()
1459
};
1460
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1461
              "Must have the right minimal number of reserved slots.");
1462
static_assert(1 >= 1,
1463
              "Must have enough reserved slots.");
1464
1465
const JSClass*
1466
GetJSClass()
1467
0
{
1468
0
  return sClass.ToJSClass();
1469
0
}
1470
1471
bool
1472
Wrap(JSContext* aCx, mozilla::dom::DOMPointReadOnly* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1473
0
{
1474
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DOMPointReadOnly>::value,
1475
0
                "Shouldn't have wrappercached things that are not refcounted.");
1476
0
  MOZ_ASSERT(static_cast<mozilla::dom::DOMPointReadOnly*>(aObject) ==
1477
0
             reinterpret_cast<mozilla::dom::DOMPointReadOnly*>(aObject),
1478
0
             "Multiple inheritance for mozilla::dom::DOMPointReadOnly is broken.");
1479
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1480
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1481
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1482
0
             "You should probably not be using Wrap() directly; use "
1483
0
             "GetOrCreateDOMReflector instead");
1484
0
1485
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1486
0
             "nsISupports must be on our primary inheritance chain");
1487
0
1488
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1489
0
  if (!global) {
1490
0
    return false;
1491
0
  }
1492
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1493
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1494
0
1495
0
  // That might have ended up wrapping us already, due to the wonders
1496
0
  // of XBL.  Check for that, and bail out as needed.
1497
0
  aReflector.set(aCache->GetWrapper());
1498
0
  if (aReflector) {
1499
#ifdef DEBUG
1500
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1501
#endif // DEBUG
1502
    return true;
1503
0
  }
1504
0
1505
0
  JSAutoRealm ar(aCx, global);
1506
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1507
0
  if (!canonicalProto) {
1508
0
    return false;
1509
0
  }
1510
0
  JS::Rooted<JSObject*> proto(aCx);
1511
0
  if (aGivenProto) {
1512
0
    proto = aGivenProto;
1513
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1514
0
    // coming in, we changed compartments to that of "parent" so may need
1515
0
    // to wrap the proto here.
1516
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1517
0
      if (!JS_WrapObject(aCx, &proto)) {
1518
0
        return false;
1519
0
      }
1520
0
    }
1521
0
  } else {
1522
0
    proto = canonicalProto;
1523
0
  }
1524
0
1525
0
  BindingJSObjectCreator<mozilla::dom::DOMPointReadOnly> creator(aCx);
1526
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1527
0
  if (!aReflector) {
1528
0
    return false;
1529
0
  }
1530
0
1531
0
  aCache->SetWrapper(aReflector);
1532
0
  creator.InitializationSucceeded();
1533
0
1534
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1535
0
             aCache->GetWrapperPreserveColor() == aReflector);
1536
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1537
0
  // otherwise we won't be able to properly recreate it later, since
1538
0
  // we won't know what proto to use.  Note that we don't check
1539
0
  // aGivenProto here, since it's entirely possible (and even
1540
0
  // somewhat common) to have a non-null aGivenProto which is the
1541
0
  // same as canonicalProto.
1542
0
  if (proto != canonicalProto) {
1543
0
    PreserveWrapper(aObject);
1544
0
  }
1545
0
1546
0
  return true;
1547
0
}
1548
1549
const NativePropertyHooks sNativePropertyHooks[] = { {
1550
  nullptr,
1551
  nullptr,
1552
  nullptr,
1553
  { sNativeProperties.Upcast(), nullptr },
1554
  prototypes::id::DOMPointReadOnly,
1555
  constructors::id::DOMPointReadOnly,
1556
  nullptr,
1557
  &DefaultXrayExpandoObjectClass
1558
} };
1559
1560
void
1561
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1562
0
{
1563
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1564
0
  if (!parentProto) {
1565
0
    return;
1566
0
  }
1567
0
1568
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1569
0
  if (!constructorProto) {
1570
0
    return;
1571
0
  }
1572
0
1573
0
  static bool sIdsInited = false;
1574
0
  if (!sIdsInited && NS_IsMainThread()) {
1575
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1576
0
      return;
1577
0
    }
1578
0
    sIdsInited = true;
1579
0
  }
1580
0
1581
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMPointReadOnly);
1582
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMPointReadOnly);
1583
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1584
0
                              &sPrototypeClass.mBase, protoCache,
1585
0
                              nullptr,
1586
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1587
0
                              interfaceCache,
1588
0
                              sNativeProperties.Upcast(),
1589
0
                              nullptr,
1590
0
                              "DOMPointReadOnly", aDefineOnGlobal,
1591
0
                              nullptr,
1592
0
                              false);
1593
0
}
1594
1595
JSObject*
1596
GetProtoObject(JSContext* aCx)
1597
0
{
1598
0
  return GetProtoObjectHandle(aCx);
1599
0
}
1600
1601
JSObject*
1602
GetConstructorObject(JSContext* aCx)
1603
0
{
1604
0
  return GetConstructorObjectHandle(aCx);
1605
0
}
1606
1607
} // namespace DOMPointReadOnly_Binding
1608
1609
1610
1611
} // namespace dom
1612
} // namespace mozilla