Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/BoxObjectBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM BoxObject.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "BoxObjectBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/dom/BindingUtils.h"
7
#include "mozilla/dom/BoxObject.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/Element.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/Nullable.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/XrayExpandoClass.h"
14
#include "nsISupports.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
namespace BoxObject_Binding {
24
25
MOZ_CAN_RUN_SCRIPT static bool
26
get_element(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
27
0
{
28
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.element", DOM, cx);
29
0
30
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetElement()));
31
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
32
0
  if (!result) {
33
0
    args.rval().setNull();
34
0
    return true;
35
0
  }
36
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
37
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
38
0
    return false;
39
0
  }
40
0
  return true;
41
0
}
42
43
static const JSJitInfo element_getterinfo = {
44
  { (JSJitGetterOp)get_element },
45
  { prototypes::id::BoxObject },
46
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
47
  JSJitInfo::Getter,
48
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
49
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
50
  false,  /* isInfallible. False in setters. */
51
  false,  /* isMovable.  Not relevant for setters. */
52
  false, /* isEliminatable.  Not relevant for setters. */
53
  false, /* isAlwaysInSlot.  Only relevant for getters. */
54
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
55
  false,  /* isTypedMethod.  Only relevant for methods. */
56
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
57
};
58
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
59
static_assert(0 < 1, "There is no slot for us");
60
61
MOZ_CAN_RUN_SCRIPT static bool
62
get_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
63
0
{
64
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.x", DOM, cx);
65
0
66
0
  int32_t result(self->X());
67
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
68
0
  args.rval().setInt32(int32_t(result));
69
0
  return true;
70
0
}
71
72
static const JSJitInfo x_getterinfo = {
73
  { (JSJitGetterOp)get_x },
74
  { prototypes::id::BoxObject },
75
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
76
  JSJitInfo::Getter,
77
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
78
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
79
  true,  /* isInfallible. False in setters. */
80
  false,  /* isMovable.  Not relevant for setters. */
81
  false, /* isEliminatable.  Not relevant for setters. */
82
  false, /* isAlwaysInSlot.  Only relevant for getters. */
83
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
84
  false,  /* isTypedMethod.  Only relevant for methods. */
85
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
86
};
87
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
88
static_assert(0 < 1, "There is no slot for us");
89
90
MOZ_CAN_RUN_SCRIPT static bool
91
get_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
92
0
{
93
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.y", DOM, cx);
94
0
95
0
  int32_t result(self->Y());
96
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
97
0
  args.rval().setInt32(int32_t(result));
98
0
  return true;
99
0
}
100
101
static const JSJitInfo y_getterinfo = {
102
  { (JSJitGetterOp)get_y },
103
  { prototypes::id::BoxObject },
104
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
105
  JSJitInfo::Getter,
106
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
107
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
108
  true,  /* isInfallible. False in setters. */
109
  false,  /* isMovable.  Not relevant for setters. */
110
  false, /* isEliminatable.  Not relevant for setters. */
111
  false, /* isAlwaysInSlot.  Only relevant for getters. */
112
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
113
  false,  /* isTypedMethod.  Only relevant for methods. */
114
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
115
};
116
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
117
static_assert(0 < 1, "There is no slot for us");
118
119
MOZ_CAN_RUN_SCRIPT static bool
120
get_screenX(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
121
0
{
122
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.screenX", DOM, cx);
123
0
124
0
  FastErrorResult rv;
125
0
  int32_t result(self->GetScreenX(rv));
126
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
127
0
    return false;
128
0
  }
129
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
130
0
  args.rval().setInt32(int32_t(result));
131
0
  return true;
132
0
}
133
134
static const JSJitInfo screenX_getterinfo = {
135
  { (JSJitGetterOp)get_screenX },
136
  { prototypes::id::BoxObject },
137
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
138
  JSJitInfo::Getter,
139
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
140
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
141
  false,  /* isInfallible. False in setters. */
142
  false,  /* isMovable.  Not relevant for setters. */
143
  false, /* isEliminatable.  Not relevant for setters. */
144
  false, /* isAlwaysInSlot.  Only relevant for getters. */
145
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
146
  false,  /* isTypedMethod.  Only relevant for methods. */
147
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
148
};
149
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
150
static_assert(0 < 1, "There is no slot for us");
151
152
MOZ_CAN_RUN_SCRIPT static bool
153
get_screenY(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
154
0
{
155
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.screenY", DOM, cx);
156
0
157
0
  FastErrorResult rv;
158
0
  int32_t result(self->GetScreenY(rv));
159
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
160
0
    return false;
161
0
  }
162
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
163
0
  args.rval().setInt32(int32_t(result));
164
0
  return true;
165
0
}
166
167
static const JSJitInfo screenY_getterinfo = {
168
  { (JSJitGetterOp)get_screenY },
169
  { prototypes::id::BoxObject },
170
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
171
  JSJitInfo::Getter,
172
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
173
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
174
  false,  /* isInfallible. False in setters. */
175
  false,  /* isMovable.  Not relevant for setters. */
176
  false, /* isEliminatable.  Not relevant for setters. */
177
  false, /* isAlwaysInSlot.  Only relevant for getters. */
178
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
179
  false,  /* isTypedMethod.  Only relevant for methods. */
180
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
181
};
182
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
183
static_assert(0 < 1, "There is no slot for us");
184
185
MOZ_CAN_RUN_SCRIPT static bool
186
get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
187
0
{
188
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.width", DOM, cx);
189
0
190
0
  int32_t result(self->Width());
191
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
192
0
  args.rval().setInt32(int32_t(result));
193
0
  return true;
194
0
}
195
196
static const JSJitInfo width_getterinfo = {
197
  { (JSJitGetterOp)get_width },
198
  { prototypes::id::BoxObject },
199
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
200
  JSJitInfo::Getter,
201
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
202
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
203
  true,  /* isInfallible. False in setters. */
204
  false,  /* isMovable.  Not relevant for setters. */
205
  false, /* isEliminatable.  Not relevant for setters. */
206
  false, /* isAlwaysInSlot.  Only relevant for getters. */
207
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
208
  false,  /* isTypedMethod.  Only relevant for methods. */
209
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
210
};
211
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
212
static_assert(0 < 1, "There is no slot for us");
213
214
MOZ_CAN_RUN_SCRIPT static bool
215
get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
216
0
{
217
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.height", DOM, cx);
218
0
219
0
  int32_t result(self->Height());
220
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
221
0
  args.rval().setInt32(int32_t(result));
222
0
  return true;
223
0
}
224
225
static const JSJitInfo height_getterinfo = {
226
  { (JSJitGetterOp)get_height },
227
  { prototypes::id::BoxObject },
228
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
229
  JSJitInfo::Getter,
230
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
231
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
232
  true,  /* isInfallible. False in setters. */
233
  false,  /* isMovable.  Not relevant for setters. */
234
  false, /* isEliminatable.  Not relevant for setters. */
235
  false, /* isAlwaysInSlot.  Only relevant for getters. */
236
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
237
  false,  /* isTypedMethod.  Only relevant for methods. */
238
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
239
};
240
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
241
static_assert(0 < 1, "There is no slot for us");
242
243
MOZ_CAN_RUN_SCRIPT static bool
244
getPropertyAsSupports(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, const JSJitMethodCallArgs& args)
245
0
{
246
0
  AUTO_PROFILER_LABEL_FAST("BoxObject.getPropertyAsSupports", DOM, cx);
247
0
248
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
249
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BoxObject.getPropertyAsSupports");
250
0
  }
251
0
  binding_detail::FakeString arg0;
252
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
253
0
    return false;
254
0
  }
255
0
  auto result(StrongOrRawPtr<nsISupports>(self->GetPropertyAsSupports(NonNullHelper(Constify(arg0)))));
256
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
257
0
  if (!result) {
258
0
    args.rval().setNull();
259
0
    return true;
260
0
  }
261
0
  if (!WrapObject(cx, result, args.rval())) {
262
0
    return false;
263
0
  }
264
0
  return true;
265
0
}
266
267
static const JSJitInfo getPropertyAsSupports_methodinfo = {
268
  { (JSJitGetterOp)getPropertyAsSupports },
269
  { prototypes::id::BoxObject },
270
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
271
  JSJitInfo::Method,
272
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
273
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
274
  false,  /* isInfallible. False in setters. */
275
  false,  /* isMovable.  Not relevant for setters. */
276
  false, /* isEliminatable.  Not relevant for setters. */
277
  false, /* isAlwaysInSlot.  Only relevant for getters. */
278
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
279
  false,  /* isTypedMethod.  Only relevant for methods. */
280
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
281
};
282
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
283
static_assert(0 < 1, "There is no slot for us");
284
285
MOZ_CAN_RUN_SCRIPT static bool
286
setPropertyAsSupports(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, const JSJitMethodCallArgs& args)
287
0
{
288
0
  AUTO_PROFILER_LABEL_FAST("BoxObject.setPropertyAsSupports", DOM, cx);
289
0
290
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
291
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BoxObject.setPropertyAsSupports");
292
0
  }
293
0
  binding_detail::FakeString arg0;
294
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
295
0
    return false;
296
0
  }
297
0
  nsISupports* arg1;
298
0
  RefPtr<nsISupports> arg1_holder;
299
0
  if (args[1].isObject()) {
300
0
    JS::Rooted<JSObject*> source(cx, &args[1].toObject());
301
0
    if (NS_FAILED(UnwrapArg<nsISupports>(cx, source, getter_AddRefs(arg1_holder)))) {
302
0
      ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of BoxObject.setPropertyAsSupports", "nsISupports");
303
0
      return false;
304
0
    }
305
0
    MOZ_ASSERT(arg1_holder);
306
0
    arg1 = arg1_holder;
307
0
  } else {
308
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of BoxObject.setPropertyAsSupports");
309
0
    return false;
310
0
  }
311
0
  self->SetPropertyAsSupports(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)));
312
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
313
0
  args.rval().setUndefined();
314
0
  return true;
315
0
}
316
317
static const JSJitInfo setPropertyAsSupports_methodinfo = {
318
  { (JSJitGetterOp)setPropertyAsSupports },
319
  { prototypes::id::BoxObject },
320
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
321
  JSJitInfo::Method,
322
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
323
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
324
  false,  /* isInfallible. False in setters. */
325
  false,  /* isMovable.  Not relevant for setters. */
326
  false, /* isEliminatable.  Not relevant for setters. */
327
  false, /* isAlwaysInSlot.  Only relevant for getters. */
328
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
329
  false,  /* isTypedMethod.  Only relevant for methods. */
330
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
331
};
332
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
333
static_assert(0 < 1, "There is no slot for us");
334
335
MOZ_CAN_RUN_SCRIPT static bool
336
getProperty(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, const JSJitMethodCallArgs& args)
337
0
{
338
0
  AUTO_PROFILER_LABEL_FAST("BoxObject.getProperty", DOM, cx);
339
0
340
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
341
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BoxObject.getProperty");
342
0
  }
343
0
  binding_detail::FakeString arg0;
344
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
345
0
    return false;
346
0
  }
347
0
  FastErrorResult rv;
348
0
  DOMString result;
349
0
  self->GetProperty(NonNullHelper(Constify(arg0)), result, rv);
350
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
351
0
    return false;
352
0
  }
353
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
354
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
355
0
    return false;
356
0
  }
357
0
  return true;
358
0
}
359
360
static const JSJitInfo getProperty_methodinfo = {
361
  { (JSJitGetterOp)getProperty },
362
  { prototypes::id::BoxObject },
363
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
364
  JSJitInfo::Method,
365
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
366
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
367
  false,  /* isInfallible. False in setters. */
368
  false,  /* isMovable.  Not relevant for setters. */
369
  false, /* isEliminatable.  Not relevant for setters. */
370
  false, /* isAlwaysInSlot.  Only relevant for getters. */
371
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
372
  false,  /* isTypedMethod.  Only relevant for methods. */
373
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
374
};
375
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
376
static_assert(0 < 1, "There is no slot for us");
377
378
MOZ_CAN_RUN_SCRIPT static bool
379
setProperty(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, const JSJitMethodCallArgs& args)
380
0
{
381
0
  AUTO_PROFILER_LABEL_FAST("BoxObject.setProperty", DOM, cx);
382
0
383
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
384
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BoxObject.setProperty");
385
0
  }
386
0
  binding_detail::FakeString arg0;
387
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
388
0
    return false;
389
0
  }
390
0
  binding_detail::FakeString arg1;
391
0
  if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
392
0
    return false;
393
0
  }
394
0
  self->SetProperty(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)));
395
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
396
0
  args.rval().setUndefined();
397
0
  return true;
398
0
}
399
400
static const JSJitInfo setProperty_methodinfo = {
401
  { (JSJitGetterOp)setProperty },
402
  { prototypes::id::BoxObject },
403
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
404
  JSJitInfo::Method,
405
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
406
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
407
  false,  /* isInfallible. False in setters. */
408
  false,  /* isMovable.  Not relevant for setters. */
409
  false, /* isEliminatable.  Not relevant for setters. */
410
  false, /* isAlwaysInSlot.  Only relevant for getters. */
411
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
412
  false,  /* isTypedMethod.  Only relevant for methods. */
413
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
414
};
415
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
416
static_assert(0 < 1, "There is no slot for us");
417
418
MOZ_CAN_RUN_SCRIPT static bool
419
removeProperty(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, const JSJitMethodCallArgs& args)
420
0
{
421
0
  AUTO_PROFILER_LABEL_FAST("BoxObject.removeProperty", DOM, cx);
422
0
423
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
424
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "BoxObject.removeProperty");
425
0
  }
426
0
  binding_detail::FakeString arg0;
427
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
428
0
    return false;
429
0
  }
430
0
  self->RemoveProperty(NonNullHelper(Constify(arg0)));
431
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
432
0
  args.rval().setUndefined();
433
0
  return true;
434
0
}
435
436
static const JSJitInfo removeProperty_methodinfo = {
437
  { (JSJitGetterOp)removeProperty },
438
  { prototypes::id::BoxObject },
439
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
440
  JSJitInfo::Method,
441
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
442
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
443
  false,  /* isInfallible. False in setters. */
444
  false,  /* isMovable.  Not relevant for setters. */
445
  false, /* isEliminatable.  Not relevant for setters. */
446
  false, /* isAlwaysInSlot.  Only relevant for getters. */
447
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
448
  false,  /* isTypedMethod.  Only relevant for methods. */
449
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
450
};
451
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
452
static_assert(0 < 1, "There is no slot for us");
453
454
MOZ_CAN_RUN_SCRIPT static bool
455
get_parentBox(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
456
0
{
457
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.parentBox", DOM, cx);
458
0
459
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetParentBox()));
460
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
461
0
  if (!result) {
462
0
    args.rval().setNull();
463
0
    return true;
464
0
  }
465
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
466
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
467
0
    return false;
468
0
  }
469
0
  return true;
470
0
}
471
472
static const JSJitInfo parentBox_getterinfo = {
473
  { (JSJitGetterOp)get_parentBox },
474
  { prototypes::id::BoxObject },
475
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
476
  JSJitInfo::Getter,
477
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
478
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
479
  false,  /* isInfallible. False in setters. */
480
  false,  /* isMovable.  Not relevant for setters. */
481
  false, /* isEliminatable.  Not relevant for setters. */
482
  false, /* isAlwaysInSlot.  Only relevant for getters. */
483
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
484
  false,  /* isTypedMethod.  Only relevant for methods. */
485
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
486
};
487
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
488
static_assert(0 < 1, "There is no slot for us");
489
490
MOZ_CAN_RUN_SCRIPT static bool
491
get_firstChild(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
492
0
{
493
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.firstChild", DOM, cx);
494
0
495
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetFirstChild()));
496
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
497
0
  if (!result) {
498
0
    args.rval().setNull();
499
0
    return true;
500
0
  }
501
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
502
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
503
0
    return false;
504
0
  }
505
0
  return true;
506
0
}
507
508
static const JSJitInfo firstChild_getterinfo = {
509
  { (JSJitGetterOp)get_firstChild },
510
  { prototypes::id::BoxObject },
511
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
512
  JSJitInfo::Getter,
513
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
514
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
515
  false,  /* isInfallible. False in setters. */
516
  false,  /* isMovable.  Not relevant for setters. */
517
  false, /* isEliminatable.  Not relevant for setters. */
518
  false, /* isAlwaysInSlot.  Only relevant for getters. */
519
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
520
  false,  /* isTypedMethod.  Only relevant for methods. */
521
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
522
};
523
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
524
static_assert(0 < 1, "There is no slot for us");
525
526
MOZ_CAN_RUN_SCRIPT static bool
527
get_lastChild(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
528
0
{
529
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.lastChild", DOM, cx);
530
0
531
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetLastChild()));
532
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
533
0
  if (!result) {
534
0
    args.rval().setNull();
535
0
    return true;
536
0
  }
537
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
538
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
539
0
    return false;
540
0
  }
541
0
  return true;
542
0
}
543
544
static const JSJitInfo lastChild_getterinfo = {
545
  { (JSJitGetterOp)get_lastChild },
546
  { prototypes::id::BoxObject },
547
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
548
  JSJitInfo::Getter,
549
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
550
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
551
  false,  /* isInfallible. False in setters. */
552
  false,  /* isMovable.  Not relevant for setters. */
553
  false, /* isEliminatable.  Not relevant for setters. */
554
  false, /* isAlwaysInSlot.  Only relevant for getters. */
555
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
556
  false,  /* isTypedMethod.  Only relevant for methods. */
557
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
558
};
559
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
560
static_assert(0 < 1, "There is no slot for us");
561
562
MOZ_CAN_RUN_SCRIPT static bool
563
get_nextSibling(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
564
0
{
565
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.nextSibling", DOM, cx);
566
0
567
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetNextSibling()));
568
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
569
0
  if (!result) {
570
0
    args.rval().setNull();
571
0
    return true;
572
0
  }
573
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
574
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
575
0
    return false;
576
0
  }
577
0
  return true;
578
0
}
579
580
static const JSJitInfo nextSibling_getterinfo = {
581
  { (JSJitGetterOp)get_nextSibling },
582
  { prototypes::id::BoxObject },
583
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
584
  JSJitInfo::Getter,
585
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
586
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
587
  false,  /* isInfallible. False in setters. */
588
  false,  /* isMovable.  Not relevant for setters. */
589
  false, /* isEliminatable.  Not relevant for setters. */
590
  false, /* isAlwaysInSlot.  Only relevant for getters. */
591
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
592
  false,  /* isTypedMethod.  Only relevant for methods. */
593
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
594
};
595
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
596
static_assert(0 < 1, "There is no slot for us");
597
598
MOZ_CAN_RUN_SCRIPT static bool
599
get_previousSibling(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::BoxObject* self, JSJitGetterCallArgs args)
600
0
{
601
0
  AUTO_PROFILER_LABEL_FAST("get BoxObject.previousSibling", DOM, cx);
602
0
603
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetPreviousSibling()));
604
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
605
0
  if (!result) {
606
0
    args.rval().setNull();
607
0
    return true;
608
0
  }
609
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
610
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
611
0
    return false;
612
0
  }
613
0
  return true;
614
0
}
615
616
static const JSJitInfo previousSibling_getterinfo = {
617
  { (JSJitGetterOp)get_previousSibling },
618
  { prototypes::id::BoxObject },
619
  { PrototypeTraits<prototypes::id::BoxObject>::Depth },
620
  JSJitInfo::Getter,
621
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
622
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
623
  false,  /* isInfallible. False in setters. */
624
  false,  /* isMovable.  Not relevant for setters. */
625
  false, /* isEliminatable.  Not relevant for setters. */
626
  false, /* isAlwaysInSlot.  Only relevant for getters. */
627
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
628
  false,  /* isTypedMethod.  Only relevant for methods. */
629
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
630
};
631
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
632
static_assert(0 < 1, "There is no slot for us");
633
634
static bool
635
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
636
0
{
637
0
  mozilla::dom::BoxObject* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BoxObject>(obj);
638
0
  // We don't want to preserve if we don't have a wrapper, and we
639
0
  // obviously can't preserve if we're not initialized.
640
0
  if (self && self->GetWrapperPreserveColor()) {
641
0
    PreserveWrapper(self);
642
0
  }
643
0
  return true;
644
0
}
645
646
static void
647
_finalize(js::FreeOp* fop, JSObject* obj)
648
0
{
649
0
  mozilla::dom::BoxObject* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BoxObject>(obj);
650
0
  if (self) {
651
0
    ClearWrapper(self, self, obj);
652
0
    AddForDeferredFinalization<mozilla::dom::BoxObject>(self);
653
0
  }
654
0
}
655
656
static size_t
657
_objectMoved(JSObject* obj, JSObject* old)
658
0
{
659
0
  mozilla::dom::BoxObject* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::BoxObject>(obj);
660
0
  if (self) {
661
0
    UpdateWrapper(self, self, obj, old);
662
0
  }
663
0
664
0
  return 0;
665
0
}
666
667
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
668
#if defined(__clang__)
669
#pragma clang diagnostic push
670
#pragma clang diagnostic ignored "-Wmissing-braces"
671
#endif
672
static const JSFunctionSpec sMethods_specs[] = {
673
  JS_FNSPEC("getPropertyAsSupports", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getPropertyAsSupports_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
674
  JS_FNSPEC("setPropertyAsSupports", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setPropertyAsSupports_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
675
  JS_FNSPEC("getProperty", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getProperty_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
676
  JS_FNSPEC("setProperty", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setProperty_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
677
  JS_FNSPEC("removeProperty", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeProperty_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
678
  JS_FS_END
679
};
680
#if defined(__clang__)
681
#pragma clang diagnostic pop
682
#endif
683
684
685
static const Prefable<const JSFunctionSpec> sMethods[] = {
686
  { nullptr, &sMethods_specs[0] },
687
  { nullptr, nullptr }
688
};
689
690
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
691
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
692
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
693
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
694
695
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
696
#if defined(__clang__)
697
#pragma clang diagnostic push
698
#pragma clang diagnostic ignored "-Wmissing-braces"
699
#endif
700
static const JSPropertySpec sAttributes_specs[] = {
701
  { "element", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &element_getterinfo, nullptr, nullptr },
702
  { "x", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &x_getterinfo, nullptr, nullptr },
703
  { "y", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &y_getterinfo, nullptr, nullptr },
704
  { "screenX", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &screenX_getterinfo, nullptr, nullptr },
705
  { "screenY", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &screenY_getterinfo, nullptr, nullptr },
706
  { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, nullptr, nullptr },
707
  { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, nullptr, nullptr },
708
  { "parentBox", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &parentBox_getterinfo, nullptr, nullptr },
709
  { "firstChild", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &firstChild_getterinfo, nullptr, nullptr },
710
  { "lastChild", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &lastChild_getterinfo, nullptr, nullptr },
711
  { "nextSibling", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &nextSibling_getterinfo, nullptr, nullptr },
712
  { "previousSibling", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &previousSibling_getterinfo, nullptr, nullptr },
713
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
714
};
715
#if defined(__clang__)
716
#pragma clang diagnostic pop
717
#endif
718
719
720
static const Prefable<const JSPropertySpec> sAttributes[] = {
721
  { nullptr, &sAttributes_specs[0] },
722
  { nullptr, nullptr }
723
};
724
725
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
726
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
727
static_assert(12 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
728
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
729
730
731
static uint16_t sNativeProperties_sortedPropertyIndices[17];
732
static PropertyInfo sNativeProperties_propertyInfos[17];
733
734
static const NativePropertiesN<2> sNativeProperties = {
735
  false, 0,
736
  false, 0,
737
  true,  0 /* sMethods */,
738
  true,  1 /* sAttributes */,
739
  false, 0,
740
  false, 0,
741
  false, 0,
742
  -1,
743
  17,
744
  sNativeProperties_sortedPropertyIndices,
745
  {
746
    { sMethods, &sNativeProperties_propertyInfos[0] },
747
    { sAttributes, &sNativeProperties_propertyInfos[5] }
748
  }
749
};
750
static_assert(17 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
751
    "We have a property info count that is oversized");
752
753
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
754
  {
755
    "Function",
756
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
757
    &sBoringInterfaceObjectClassClassOps,
758
    JS_NULL_CLASS_SPEC,
759
    JS_NULL_CLASS_EXT,
760
    &sInterfaceObjectClassObjectOps
761
  },
762
  eInterface,
763
  true,
764
  prototypes::id::BoxObject,
765
  PrototypeTraits<prototypes::id::BoxObject>::Depth,
766
  sNativePropertyHooks,
767
  "function BoxObject() {\n    [native code]\n}",
768
  JS::GetRealmFunctionPrototype
769
};
770
771
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
772
  {
773
    "BoxObjectPrototype",
774
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
775
    JS_NULL_CLASS_OPS,
776
    JS_NULL_CLASS_SPEC,
777
    JS_NULL_CLASS_EXT,
778
    JS_NULL_OBJECT_OPS
779
  },
780
  eInterfacePrototype,
781
  false,
782
  prototypes::id::BoxObject,
783
  PrototypeTraits<prototypes::id::BoxObject>::Depth,
784
  sNativePropertyHooks,
785
  "[object BoxObjectPrototype]",
786
  JS::GetRealmObjectPrototype
787
};
788
789
bool
790
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
791
0
{
792
0
  return IsChromeOrXBL(aCx, aObj);
793
0
}
794
795
static const js::ClassOps sClassOps = {
796
  _addProperty, /* addProperty */
797
  nullptr,               /* delProperty */
798
  nullptr,               /* enumerate */
799
  nullptr, /* newEnumerate */
800
  nullptr, /* resolve */
801
  nullptr, /* mayResolve */
802
  _finalize, /* finalize */
803
  nullptr, /* call */
804
  nullptr,               /* hasInstance */
805
  nullptr,               /* construct */
806
  nullptr, /* trace */
807
};
808
809
static const js::ClassExtension sClassExtension = {
810
  nullptr, /* weakmapKeyDelegateOp */
811
  _objectMoved /* objectMovedOp */
812
};
813
814
static const DOMJSClass sClass = {
815
  { "BoxObject",
816
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
817
    &sClassOps,
818
    JS_NULL_CLASS_SPEC,
819
    &sClassExtension,
820
    JS_NULL_OBJECT_OPS
821
  },
822
  { prototypes::id::BoxObject, 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 },
823
  IsBaseOf<nsISupports, mozilla::dom::BoxObject >::value,
824
  sNativePropertyHooks,
825
  FindAssociatedGlobalForNative<mozilla::dom::BoxObject>::Get,
826
  GetProtoObjectHandle,
827
  GetCCParticipant<mozilla::dom::BoxObject>::Get()
828
};
829
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
830
              "Must have the right minimal number of reserved slots.");
831
static_assert(1 >= 1,
832
              "Must have enough reserved slots.");
833
834
const JSClass*
835
GetJSClass()
836
0
{
837
0
  return sClass.ToJSClass();
838
0
}
839
840
bool
841
Wrap(JSContext* aCx, mozilla::dom::BoxObject* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
842
0
{
843
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::BoxObject>::value,
844
0
                "Shouldn't have wrappercached things that are not refcounted.");
845
0
  MOZ_ASSERT(static_cast<mozilla::dom::BoxObject*>(aObject) ==
846
0
             reinterpret_cast<mozilla::dom::BoxObject*>(aObject),
847
0
             "Multiple inheritance for mozilla::dom::BoxObject is broken.");
848
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
849
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
850
0
  MOZ_ASSERT(!aCache->GetWrapper(),
851
0
             "You should probably not be using Wrap() directly; use "
852
0
             "GetOrCreateDOMReflector instead");
853
0
854
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
855
0
             "nsISupports must be on our primary inheritance chain");
856
0
857
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
858
0
  if (!global) {
859
0
    return false;
860
0
  }
861
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
862
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
863
0
864
0
  // That might have ended up wrapping us already, due to the wonders
865
0
  // of XBL.  Check for that, and bail out as needed.
866
0
  aReflector.set(aCache->GetWrapper());
867
0
  if (aReflector) {
868
#ifdef DEBUG
869
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
870
#endif // DEBUG
871
    return true;
872
0
  }
873
0
874
0
  JSAutoRealm ar(aCx, global);
875
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
876
0
  if (!canonicalProto) {
877
0
    return false;
878
0
  }
879
0
  JS::Rooted<JSObject*> proto(aCx);
880
0
  if (aGivenProto) {
881
0
    proto = aGivenProto;
882
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
883
0
    // coming in, we changed compartments to that of "parent" so may need
884
0
    // to wrap the proto here.
885
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
886
0
      if (!JS_WrapObject(aCx, &proto)) {
887
0
        return false;
888
0
      }
889
0
    }
890
0
  } else {
891
0
    proto = canonicalProto;
892
0
  }
893
0
894
0
  BindingJSObjectCreator<mozilla::dom::BoxObject> creator(aCx);
895
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
896
0
  if (!aReflector) {
897
0
    return false;
898
0
  }
899
0
900
0
  aCache->SetWrapper(aReflector);
901
0
  creator.InitializationSucceeded();
902
0
903
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
904
0
             aCache->GetWrapperPreserveColor() == aReflector);
905
0
  // If proto != canonicalProto, we have to preserve our wrapper;
906
0
  // otherwise we won't be able to properly recreate it later, since
907
0
  // we won't know what proto to use.  Note that we don't check
908
0
  // aGivenProto here, since it's entirely possible (and even
909
0
  // somewhat common) to have a non-null aGivenProto which is the
910
0
  // same as canonicalProto.
911
0
  if (proto != canonicalProto) {
912
0
    PreserveWrapper(aObject);
913
0
  }
914
0
915
0
  return true;
916
0
}
917
918
const NativePropertyHooks sNativePropertyHooks[] = { {
919
  nullptr,
920
  nullptr,
921
  nullptr,
922
  { sNativeProperties.Upcast(), nullptr },
923
  prototypes::id::BoxObject,
924
  constructors::id::BoxObject,
925
  nullptr,
926
  &DefaultXrayExpandoObjectClass
927
} };
928
929
void
930
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
931
0
{
932
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
933
0
  if (!parentProto) {
934
0
    return;
935
0
  }
936
0
937
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
938
0
  if (!constructorProto) {
939
0
    return;
940
0
  }
941
0
942
0
  static bool sIdsInited = false;
943
0
  if (!sIdsInited && NS_IsMainThread()) {
944
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
945
0
      return;
946
0
    }
947
0
    sIdsInited = true;
948
0
  }
949
0
950
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::BoxObject);
951
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::BoxObject);
952
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
953
0
                              &sPrototypeClass.mBase, protoCache,
954
0
                              nullptr,
955
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
956
0
                              interfaceCache,
957
0
                              sNativeProperties.Upcast(),
958
0
                              nullptr,
959
0
                              "BoxObject", aDefineOnGlobal,
960
0
                              nullptr,
961
0
                              false);
962
0
}
963
964
JSObject*
965
GetProtoObject(JSContext* aCx)
966
0
{
967
0
  return GetProtoObjectHandle(aCx);
968
0
}
969
970
JSObject*
971
GetConstructorObject(JSContext* aCx)
972
0
{
973
0
  return GetConstructorObjectHandle(aCx);
974
0
}
975
976
} // namespace BoxObject_Binding
977
978
979
980
} // namespace dom
981
} // namespace mozilla