Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ImageDataBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM ImageData.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "ImageDataBinding.h"
4
#include "WrapperFactory.h"
5
#include "XrayWrapper.h"
6
#include "jsfriendapi.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/ImageData.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/TypedArray.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
namespace ImageData_Binding {
24
25
MOZ_CAN_RUN_SCRIPT static bool
26
get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageData* self, JSJitGetterCallArgs args)
27
0
{
28
0
  AUTO_PROFILER_LABEL_FAST("get ImageData.width", DOM, cx);
29
0
30
0
  uint32_t result(self->Width());
31
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
32
0
  args.rval().setNumber(result);
33
0
  return true;
34
0
}
35
36
static const JSJitInfo width_getterinfo = {
37
  { (JSJitGetterOp)get_width },
38
  { prototypes::id::ImageData },
39
  { PrototypeTraits<prototypes::id::ImageData>::Depth },
40
  JSJitInfo::Getter,
41
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
42
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
43
  true,  /* isInfallible. False in setters. */
44
  true,  /* isMovable.  Not relevant for setters. */
45
  true, /* isEliminatable.  Not relevant for setters. */
46
  false, /* isAlwaysInSlot.  Only relevant for getters. */
47
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
48
  false,  /* isTypedMethod.  Only relevant for methods. */
49
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
50
};
51
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
52
static_assert(0 < 2, "There is no slot for us");
53
54
MOZ_CAN_RUN_SCRIPT static bool
55
get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageData* self, JSJitGetterCallArgs args)
56
0
{
57
0
  AUTO_PROFILER_LABEL_FAST("get ImageData.height", DOM, cx);
58
0
59
0
  uint32_t result(self->Height());
60
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
61
0
  args.rval().setNumber(result);
62
0
  return true;
63
0
}
64
65
static const JSJitInfo height_getterinfo = {
66
  { (JSJitGetterOp)get_height },
67
  { prototypes::id::ImageData },
68
  { PrototypeTraits<prototypes::id::ImageData>::Depth },
69
  JSJitInfo::Getter,
70
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
71
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
72
  true,  /* isInfallible. False in setters. */
73
  true,  /* isMovable.  Not relevant for setters. */
74
  true, /* isEliminatable.  Not relevant for setters. */
75
  false, /* isAlwaysInSlot.  Only relevant for getters. */
76
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
77
  false,  /* isTypedMethod.  Only relevant for methods. */
78
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
79
};
80
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
81
static_assert(0 < 2, "There is no slot for us");
82
83
static bool
84
get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageData* self, JSJitGetterCallArgs args)
85
0
{
86
0
  AUTO_PROFILER_LABEL_FAST("get ImageData.data", DOM, cx);
87
0
88
0
  // Have to either root across the getter call or reget after.
89
0
  bool isXray;
90
0
  JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray));
91
0
  if (!slotStorage) {
92
0
    return false;
93
0
  }
94
0
  const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0);
95
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
96
0
  {
97
0
    // Scope for cachedVal
98
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
99
0
    if (!cachedVal.isUndefined()) {
100
0
      args.rval().set(cachedVal);
101
0
      // The cached value is in the compartment of slotStorage,
102
0
      // so wrap into the caller compartment as needed.
103
0
      if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
104
0
        return true;
105
0
      }
106
0
      return false;
107
0
    }
108
0
  }
109
0
110
0
  JS::Rooted<JSObject*> result(cx);
111
0
  self->GetData(cx, &result);
112
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
113
0
  {
114
0
    JS::Rooted<JSObject*> conversionScope(cx, isXray ? JS::CurrentGlobalOrNull(cx) : slotStorage);
115
0
    JSAutoRealm ar(cx, conversionScope);
116
0
    do { // block we break out of when done wrapping
117
0
      JS::ExposeObjectToActiveJS(result);
118
0
      args.rval().setObject(*result);
119
0
      if (!MaybeWrapNonDOMObjectValue(cx, args.rval())) {
120
0
        return false;
121
0
      }
122
0
      break;
123
0
    } while (false);
124
0
  }
125
0
  { // And now store things in the realm of our slotStorage.
126
0
    JSAutoRealm ar(cx, slotStorage);
127
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
128
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
129
0
    if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
130
0
      return false;
131
0
    }
132
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
133
0
  }
134
0
  // And now make sure args.rval() is in the caller realm.
135
0
  if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
136
0
    return true;
137
0
  }
138
0
  return false;
139
0
}
140
141
static const JSJitInfo data_getterinfo = {
142
  { (JSJitGetterOp)get_data },
143
  { prototypes::id::ImageData },
144
  { PrototypeTraits<prototypes::id::ImageData>::Depth },
145
  JSJitInfo::Getter,
146
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
147
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
148
  false,  /* isInfallible. False in setters. */
149
  true,  /* isMovable.  Not relevant for setters. */
150
  true, /* isEliminatable.  Not relevant for setters. */
151
  true, /* isAlwaysInSlot.  Only relevant for getters. */
152
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
153
  false,  /* isTypedMethod.  Only relevant for methods. */
154
  (DOM_INSTANCE_RESERVED_SLOTS + 0)   /* Reserved slot index, if we're stored in a slot, else 0. */
155
};
156
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
157
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
158
159
static void
160
_finalize(js::FreeOp* fop, JSObject* obj)
161
0
{
162
0
  mozilla::dom::ImageData* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageData>(obj);
163
0
  if (self) {
164
0
    AddForDeferredFinalization<mozilla::dom::ImageData>(self);
165
0
  }
166
0
}
167
168
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
169
#if defined(__clang__)
170
#pragma clang diagnostic push
171
#pragma clang diagnostic ignored "-Wmissing-braces"
172
#endif
173
static const JSPropertySpec sAttributes_specs[] = {
174
  { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, nullptr, nullptr },
175
  { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, nullptr, nullptr },
176
  { "data", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &data_getterinfo, nullptr, nullptr },
177
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
178
};
179
#if defined(__clang__)
180
#pragma clang diagnostic pop
181
#endif
182
183
184
static const Prefable<const JSPropertySpec> sAttributes[] = {
185
  { nullptr, &sAttributes_specs[0] },
186
  { nullptr, nullptr }
187
};
188
189
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
190
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
191
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
192
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
193
194
195
static uint16_t sNativeProperties_sortedPropertyIndices[3];
196
static PropertyInfo sNativeProperties_propertyInfos[3];
197
198
static const NativePropertiesN<1> sNativeProperties = {
199
  false, 0,
200
  false, 0,
201
  false, 0,
202
  true,  0 /* sAttributes */,
203
  false, 0,
204
  false, 0,
205
  false, 0,
206
  -1,
207
  3,
208
  sNativeProperties_sortedPropertyIndices,
209
  {
210
    { sAttributes, &sNativeProperties_propertyInfos[0] }
211
  }
212
};
213
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
214
    "We have a property info count that is oversized");
215
216
static bool
217
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
218
0
{
219
0
  AUTO_PROFILER_LABEL_FAST("ImageData constructor", DOM, cx);
220
0
221
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
222
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
223
0
  if (!args.isConstructing()) {
224
0
    // XXXbz wish I could get the name from the callee instead of
225
0
    // Adding more relocations
226
0
    return ThrowConstructorWithoutNew(cx, "ImageData");
227
0
  }
228
0
229
0
  JS::Rooted<JSObject*> desiredProto(cx);
230
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
231
0
    return false;
232
0
  }
233
0
234
0
  unsigned argcount = std::min(args.length(), 3u);
235
0
  switch (argcount) {
236
0
    case 2: {
237
0
      if (args[0].isObject()) {
238
0
        do {
239
0
          RootedSpiderMonkeyInterface<Uint8ClampedArray> arg0(cx);
240
0
          if (!arg0.Init(&args[0].toObject())) {
241
0
            break;
242
0
          }
243
0
          GlobalObject global(cx, obj);
244
0
          if (global.Failed()) {
245
0
            return false;
246
0
          }
247
0
248
0
          bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
249
0
          uint32_t arg1;
250
0
          if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
251
0
            return false;
252
0
          }
253
0
          Optional<uint32_t> arg2;
254
0
          if (args.hasDefined(2)) {
255
0
            arg2.Construct();
256
0
            if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) {
257
0
              return false;
258
0
            }
259
0
          }
260
0
          Maybe<JSAutoRealm> ar;
261
0
          if (objIsXray) {
262
0
            obj = js::CheckedUnwrap(obj);
263
0
            if (!obj) {
264
0
              return false;
265
0
            }
266
0
            ar.emplace(cx, obj);
267
0
            if (!JS_WrapObject(cx, &desiredProto)) {
268
0
              return false;
269
0
            }
270
0
            if (!arg0.WrapIntoNewCompartment(cx)) {
271
0
              return false;
272
0
            }
273
0
          }
274
0
          FastErrorResult rv;
275
0
          auto result(StrongOrRawPtr<mozilla::dom::ImageData>(mozilla::dom::ImageData::Constructor(global, Constify(arg0), arg1, Constify(arg2), rv)));
276
0
          if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
277
0
            return false;
278
0
          }
279
0
          MOZ_ASSERT(!JS_IsExceptionPending(cx));
280
0
          static_assert(!IsPointer<decltype(result)>::value,
281
0
                        "NewObject implies that we need to keep the object alive with a strong reference.");
282
0
          if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
283
0
            MOZ_ASSERT(JS_IsExceptionPending(cx));
284
0
            return false;
285
0
          }
286
0
          return true;
287
0
        } while (false);
288
0
      }
289
0
      GlobalObject global(cx, obj);
290
0
      if (global.Failed()) {
291
0
        return false;
292
0
      }
293
0
294
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
295
0
      uint32_t arg0;
296
0
      if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
297
0
        return false;
298
0
      }
299
0
      uint32_t arg1;
300
0
      if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
301
0
        return false;
302
0
      }
303
0
      Maybe<JSAutoRealm> ar;
304
0
      if (objIsXray) {
305
0
        obj = js::CheckedUnwrap(obj);
306
0
        if (!obj) {
307
0
          return false;
308
0
        }
309
0
        ar.emplace(cx, obj);
310
0
        if (!JS_WrapObject(cx, &desiredProto)) {
311
0
          return false;
312
0
        }
313
0
      }
314
0
      FastErrorResult rv;
315
0
      auto result(StrongOrRawPtr<mozilla::dom::ImageData>(mozilla::dom::ImageData::Constructor(global, arg0, arg1, rv)));
316
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
317
0
        return false;
318
0
      }
319
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
320
0
      static_assert(!IsPointer<decltype(result)>::value,
321
0
                    "NewObject implies that we need to keep the object alive with a strong reference.");
322
0
      if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
323
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
324
0
        return false;
325
0
      }
326
0
      return true;
327
0
      break;
328
0
    }
329
0
    case 3: {
330
0
      GlobalObject global(cx, obj);
331
0
      if (global.Failed()) {
332
0
        return false;
333
0
      }
334
0
335
0
      bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
336
0
      RootedSpiderMonkeyInterface<Uint8ClampedArray> arg0(cx);
337
0
      if (args[0].isObject()) {
338
0
        if (!arg0.Init(&args[0].toObject())) {
339
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of ImageData.constructor", "Uint8ClampedArray");
340
0
          return false;
341
0
        }
342
0
      } else {
343
0
        ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of ImageData.constructor");
344
0
        return false;
345
0
      }
346
0
      uint32_t arg1;
347
0
      if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
348
0
        return false;
349
0
      }
350
0
      Optional<uint32_t> arg2;
351
0
      if (args.hasDefined(2)) {
352
0
        arg2.Construct();
353
0
        if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) {
354
0
          return false;
355
0
        }
356
0
      }
357
0
      Maybe<JSAutoRealm> ar;
358
0
      if (objIsXray) {
359
0
        obj = js::CheckedUnwrap(obj);
360
0
        if (!obj) {
361
0
          return false;
362
0
        }
363
0
        ar.emplace(cx, obj);
364
0
        if (!JS_WrapObject(cx, &desiredProto)) {
365
0
          return false;
366
0
        }
367
0
        if (!arg0.WrapIntoNewCompartment(cx)) {
368
0
          return false;
369
0
        }
370
0
      }
371
0
      FastErrorResult rv;
372
0
      auto result(StrongOrRawPtr<mozilla::dom::ImageData>(mozilla::dom::ImageData::Constructor(global, Constify(arg0), arg1, Constify(arg2), rv)));
373
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
374
0
        return false;
375
0
      }
376
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
377
0
      static_assert(!IsPointer<decltype(result)>::value,
378
0
                    "NewObject implies that we need to keep the object alive with a strong reference.");
379
0
      if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
380
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
381
0
        return false;
382
0
      }
383
0
      return true;
384
0
      break;
385
0
    }
386
0
    default: {
387
0
      return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ImageData");
388
0
      break;
389
0
    }
390
0
  }
391
0
  MOZ_CRASH("We have an always-returning default case");
392
0
  return false;
393
0
}
394
395
static const js::ClassOps sInterfaceObjectClassOps = {
396
    nullptr,               /* addProperty */
397
    nullptr,               /* delProperty */
398
    nullptr,               /* enumerate */
399
    nullptr,               /* newEnumerate */
400
    nullptr,               /* resolve */
401
    nullptr,               /* mayResolve */
402
    nullptr,               /* finalize */
403
    _constructor, /* call */
404
    nullptr,               /* hasInstance */
405
    _constructor, /* construct */
406
    nullptr,               /* trace */
407
};
408
409
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
410
  {
411
    "Function",
412
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
413
    &sInterfaceObjectClassOps,
414
    JS_NULL_CLASS_SPEC,
415
    JS_NULL_CLASS_EXT,
416
    &sInterfaceObjectClassObjectOps
417
  },
418
  eInterface,
419
  true,
420
  prototypes::id::ImageData,
421
  PrototypeTraits<prototypes::id::ImageData>::Depth,
422
  sNativePropertyHooks,
423
  "function ImageData() {\n    [native code]\n}",
424
  JS::GetRealmFunctionPrototype
425
};
426
427
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
428
  {
429
    "ImageDataPrototype",
430
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
431
    JS_NULL_CLASS_OPS,
432
    JS_NULL_CLASS_SPEC,
433
    JS_NULL_CLASS_EXT,
434
    JS_NULL_OBJECT_OPS
435
  },
436
  eInterfacePrototype,
437
  false,
438
  prototypes::id::ImageData,
439
  PrototypeTraits<prototypes::id::ImageData>::Depth,
440
  sNativePropertyHooks,
441
  "[object ImageDataPrototype]",
442
  JS::GetRealmObjectPrototype
443
};
444
445
static const js::ClassOps sClassOps = {
446
  nullptr, /* addProperty */
447
  nullptr,               /* delProperty */
448
  nullptr,               /* enumerate */
449
  nullptr, /* newEnumerate */
450
  nullptr, /* resolve */
451
  nullptr, /* mayResolve */
452
  _finalize, /* finalize */
453
  nullptr, /* call */
454
  nullptr,               /* hasInstance */
455
  nullptr,               /* construct */
456
  nullptr, /* trace */
457
};
458
459
static const js::ClassExtension sClassExtension = {
460
  nullptr, /* weakmapKeyDelegateOp */
461
  nullptr /* objectMovedOp */
462
};
463
464
static const DOMJSClass sClass = {
465
  { "ImageData",
466
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2),
467
    &sClassOps,
468
    JS_NULL_CLASS_SPEC,
469
    &sClassExtension,
470
    JS_NULL_OBJECT_OPS
471
  },
472
  { prototypes::id::ImageData, 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 },
473
  IsBaseOf<nsISupports, mozilla::dom::ImageData >::value,
474
  sNativePropertyHooks,
475
  FindAssociatedGlobalForNative<mozilla::dom::ImageData>::Get,
476
  GetProtoObjectHandle,
477
  GetCCParticipant<mozilla::dom::ImageData>::Get()
478
};
479
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
480
              "Must have the right minimal number of reserved slots.");
481
static_assert(2 >= 2,
482
              "Must have enough reserved slots.");
483
484
const JSClass*
485
GetJSClass()
486
0
{
487
0
  return sClass.ToJSClass();
488
0
}
489
490
static bool
491
UpdateMemberSlots(JSContext* aCx, JS::Handle<JSObject*> aWrapper, mozilla::dom::ImageData* aObject)
492
0
{
493
0
  JS::Rooted<JS::Value> temp(aCx);
494
0
  JSJitGetterCallArgs args(&temp);
495
0
496
0
  static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < js::shadow::Object::MAX_FIXED_SLOTS,
497
0
                "Not enough fixed slots to fit 'ImageData.data.  Ion's visitGetDOMMemberV/visitGetDOMMemberT assume StoreInSlot things are all in fixed slots.");
498
0
  if (!get_data(aCx, aWrapper, aObject, args)) {
499
0
    return false;
500
0
  }
501
0
  // Getter handled setting our reserved slots
502
0
503
0
  return true;
504
0
}
505
506
bool
507
Wrap(JSContext* aCx, mozilla::dom::ImageData* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
508
0
{
509
0
  MOZ_ASSERT(static_cast<mozilla::dom::ImageData*>(aObject) ==
510
0
             reinterpret_cast<mozilla::dom::ImageData*>(aObject),
511
0
             "Multiple inheritance for mozilla::dom::ImageData is broken.");
512
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
513
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
514
0
515
0
  JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
516
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
517
0
  if (!canonicalProto) {
518
0
    return false;
519
0
  }
520
0
  JS::Rooted<JSObject*> proto(aCx);
521
0
  if (aGivenProto) {
522
0
    proto = aGivenProto;
523
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
524
0
    // coming in, we changed compartments to that of "parent" so may need
525
0
    // to wrap the proto here.
526
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
527
0
      if (!JS_WrapObject(aCx, &proto)) {
528
0
        return false;
529
0
      }
530
0
    }
531
0
  } else {
532
0
    proto = canonicalProto;
533
0
  }
534
0
535
0
  BindingJSObjectCreator<mozilla::dom::ImageData> creator(aCx);
536
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
537
0
  if (!aReflector) {
538
0
    return false;
539
0
  }
540
0
541
0
542
0
  if (!UpdateMemberSlots(aCx, aReflector, aObject)) {
543
0
    return false;
544
0
  }
545
0
546
0
  creator.InitializationSucceeded();
547
0
  return true;
548
0
}
549
550
// This may allocate too many slots, because we only really need
551
// slots for our non-interface-typed members that we cache.  But
552
// allocating slots only for those would make the slot index
553
// computations much more complicated, so let's do this the simple
554
// way for now.
555
DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1);
556
557
const NativePropertyHooks sNativePropertyHooks[] = { {
558
  nullptr,
559
  nullptr,
560
  nullptr,
561
  { sNativeProperties.Upcast(), nullptr },
562
  prototypes::id::ImageData,
563
  constructors::id::ImageData,
564
  nullptr,
565
  &sXrayExpandoObjectClass
566
} };
567
568
void
569
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
570
0
{
571
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
572
0
  if (!parentProto) {
573
0
    return;
574
0
  }
575
0
576
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
577
0
  if (!constructorProto) {
578
0
    return;
579
0
  }
580
0
581
0
  static bool sIdsInited = false;
582
0
  if (!sIdsInited && NS_IsMainThread()) {
583
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
584
0
      return;
585
0
    }
586
0
    sIdsInited = true;
587
0
  }
588
0
589
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ImageData);
590
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ImageData);
591
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
592
0
                              &sPrototypeClass.mBase, protoCache,
593
0
                              nullptr,
594
0
                              constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
595
0
                              interfaceCache,
596
0
                              sNativeProperties.Upcast(),
597
0
                              nullptr,
598
0
                              "ImageData", aDefineOnGlobal,
599
0
                              nullptr,
600
0
                              false);
601
0
}
602
603
JSObject*
604
GetConstructorObject(JSContext* aCx)
605
0
{
606
0
  return GetConstructorObjectHandle(aCx);
607
0
}
608
609
} // namespace ImageData_Binding
610
611
612
613
} // namespace dom
614
} // namespace mozilla