Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/OffscreenCanvasBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM OffscreenCanvas.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventTargetBinding.h"
4
#include "OffscreenCanvasBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/DOMPrefs.h"
10
#include "mozilla/dom/ImageBitmap.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/Nullable.h"
13
#include "mozilla/dom/OffscreenCanvas.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/Promise.h"
16
#include "mozilla/dom/ToJSValue.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
#include "nsISupports.h"
19
20
namespace mozilla {
21
namespace dom {
22
23
namespace binding_detail {}; // Just to make sure it's known as a namespace
24
using namespace mozilla::dom::binding_detail;
25
26
27
namespace OffscreenCanvas_Binding {
28
29
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
30
              "Can't inherit from an interface with a different ownership model.");
31
32
MOZ_CAN_RUN_SCRIPT static bool
33
get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, JSJitGetterCallArgs args)
34
0
{
35
0
  AUTO_PROFILER_LABEL_FAST("get OffscreenCanvas.width", DOM, cx);
36
0
37
0
  uint32_t result(self->Width());
38
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
39
0
  args.rval().setNumber(result);
40
0
  return true;
41
0
}
42
43
MOZ_CAN_RUN_SCRIPT static bool
44
set_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, JSJitSetterCallArgs args)
45
0
{
46
0
  AUTO_PROFILER_LABEL_FAST("set OffscreenCanvas.width", DOM, cx);
47
0
48
0
  uint32_t arg0;
49
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
50
0
    return false;
51
0
  }
52
0
  FastErrorResult rv;
53
0
  self->SetWidth(arg0, rv);
54
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
55
0
    return false;
56
0
  }
57
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
58
0
59
0
  return true;
60
0
}
61
62
static const JSJitInfo width_getterinfo = {
63
  { (JSJitGetterOp)get_width },
64
  { prototypes::id::OffscreenCanvas },
65
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
66
  JSJitInfo::Getter,
67
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
68
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
69
  true,  /* isInfallible. False in setters. */
70
  true,  /* isMovable.  Not relevant for setters. */
71
  true, /* isEliminatable.  Not relevant for setters. */
72
  false, /* isAlwaysInSlot.  Only relevant for getters. */
73
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
74
  false,  /* isTypedMethod.  Only relevant for methods. */
75
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
76
};
77
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
78
static_assert(0 < 1, "There is no slot for us");
79
static const JSJitInfo width_setterinfo = {
80
  { (JSJitGetterOp)set_width },
81
  { prototypes::id::OffscreenCanvas },
82
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
83
  JSJitInfo::Setter,
84
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
85
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
86
  false,  /* isInfallible. False in setters. */
87
  false,  /* isMovable.  Not relevant for setters. */
88
  false, /* isEliminatable.  Not relevant for setters. */
89
  false, /* isAlwaysInSlot.  Only relevant for getters. */
90
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
91
  false,  /* isTypedMethod.  Only relevant for methods. */
92
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
93
};
94
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
95
static_assert(0 < 1, "There is no slot for us");
96
97
MOZ_CAN_RUN_SCRIPT static bool
98
get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, JSJitGetterCallArgs args)
99
0
{
100
0
  AUTO_PROFILER_LABEL_FAST("get OffscreenCanvas.height", DOM, cx);
101
0
102
0
  uint32_t result(self->Height());
103
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
104
0
  args.rval().setNumber(result);
105
0
  return true;
106
0
}
107
108
MOZ_CAN_RUN_SCRIPT static bool
109
set_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, JSJitSetterCallArgs args)
110
0
{
111
0
  AUTO_PROFILER_LABEL_FAST("set OffscreenCanvas.height", DOM, cx);
112
0
113
0
  uint32_t arg0;
114
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
115
0
    return false;
116
0
  }
117
0
  FastErrorResult rv;
118
0
  self->SetHeight(arg0, rv);
119
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
120
0
    return false;
121
0
  }
122
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
123
0
124
0
  return true;
125
0
}
126
127
static const JSJitInfo height_getterinfo = {
128
  { (JSJitGetterOp)get_height },
129
  { prototypes::id::OffscreenCanvas },
130
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
131
  JSJitInfo::Getter,
132
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
133
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
134
  true,  /* isInfallible. False in setters. */
135
  true,  /* isMovable.  Not relevant for setters. */
136
  true, /* isEliminatable.  Not relevant for setters. */
137
  false, /* isAlwaysInSlot.  Only relevant for getters. */
138
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
139
  false,  /* isTypedMethod.  Only relevant for methods. */
140
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
141
};
142
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
143
static_assert(0 < 1, "There is no slot for us");
144
static const JSJitInfo height_setterinfo = {
145
  { (JSJitGetterOp)set_height },
146
  { prototypes::id::OffscreenCanvas },
147
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
148
  JSJitInfo::Setter,
149
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
150
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
151
  false,  /* isInfallible. False in setters. */
152
  false,  /* isMovable.  Not relevant for setters. */
153
  false, /* isEliminatable.  Not relevant for setters. */
154
  false, /* isAlwaysInSlot.  Only relevant for getters. */
155
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
156
  false,  /* isTypedMethod.  Only relevant for methods. */
157
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
158
};
159
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
160
static_assert(0 < 1, "There is no slot for us");
161
162
MOZ_CAN_RUN_SCRIPT static bool
163
getContext(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, const JSJitMethodCallArgs& args)
164
0
{
165
0
  AUTO_PROFILER_LABEL_FAST("OffscreenCanvas.getContext", DOM, cx);
166
0
167
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
168
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "OffscreenCanvas.getContext");
169
0
  }
170
0
  binding_detail::FakeString arg0;
171
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
172
0
    return false;
173
0
  }
174
0
  JS::Rooted<JS::Value> arg1(cx);
175
0
  if (args.hasDefined(1)) {
176
0
    arg1 = args[1];
177
0
  } else {
178
0
    arg1 = JS::NullValue();
179
0
  }
180
0
  FastErrorResult rv;
181
0
  auto result(StrongOrRawPtr<nsISupports>(self->GetContext(cx, NonNullHelper(Constify(arg0)), arg1, rv)));
182
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
183
0
    return false;
184
0
  }
185
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
186
0
  if (!result) {
187
0
    args.rval().setNull();
188
0
    return true;
189
0
  }
190
0
  if (!WrapObject(cx, result, args.rval())) {
191
0
    return false;
192
0
  }
193
0
  return true;
194
0
}
195
196
static const JSJitInfo getContext_methodinfo = {
197
  { (JSJitGetterOp)getContext },
198
  { prototypes::id::OffscreenCanvas },
199
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
200
  JSJitInfo::Method,
201
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
202
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
203
  false,  /* 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
transferToImageBitmap(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, const JSJitMethodCallArgs& args)
216
0
{
217
0
  AUTO_PROFILER_LABEL_FAST("OffscreenCanvas.transferToImageBitmap", DOM, cx);
218
0
219
0
  FastErrorResult rv;
220
0
  auto result(StrongOrRawPtr<mozilla::dom::ImageBitmap>(self->TransferToImageBitmap(rv)));
221
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
222
0
    return false;
223
0
  }
224
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
225
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
226
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
227
0
    return false;
228
0
  }
229
0
  return true;
230
0
}
231
232
static const JSJitInfo transferToImageBitmap_methodinfo = {
233
  { (JSJitGetterOp)transferToImageBitmap },
234
  { prototypes::id::OffscreenCanvas },
235
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
236
  JSJitInfo::Method,
237
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
238
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
239
  false,  /* isInfallible. False in setters. */
240
  false,  /* isMovable.  Not relevant for setters. */
241
  false, /* isEliminatable.  Not relevant for setters. */
242
  false, /* isAlwaysInSlot.  Only relevant for getters. */
243
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
244
  false,  /* isTypedMethod.  Only relevant for methods. */
245
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
246
};
247
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
248
static_assert(0 < 1, "There is no slot for us");
249
250
MOZ_CAN_RUN_SCRIPT static bool
251
toBlob(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, const JSJitMethodCallArgs& args)
252
0
{
253
0
  AUTO_PROFILER_LABEL_FAST("OffscreenCanvas.toBlob", DOM, cx);
254
0
255
0
  binding_detail::FakeString arg0;
256
0
  if (args.hasDefined(0)) {
257
0
    if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
258
0
      return false;
259
0
    }
260
0
  } else {
261
0
    static const char16_t data[] = { 0 };
262
0
    arg0.Rebind(data, ArrayLength(data) - 1);
263
0
  }
264
0
  JS::Rooted<JS::Value> arg1(cx);
265
0
  if (args.hasDefined(1)) {
266
0
    arg1 = args[1];
267
0
  } else {
268
0
    arg1 = JS::UndefinedValue();
269
0
  }
270
0
  FastErrorResult rv;
271
0
  auto result(StrongOrRawPtr<Promise>(self->ToBlob(cx, NonNullHelper(Constify(arg0)), arg1, rv)));
272
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
273
0
    return false;
274
0
  }
275
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
276
0
  if (!ToJSValue(cx, result, args.rval())) {
277
0
    return false;
278
0
  }
279
0
  return true;
280
0
}
281
282
MOZ_CAN_RUN_SCRIPT static bool
283
toBlob_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OffscreenCanvas* self, const JSJitMethodCallArgs& args)
284
0
{
285
0
  bool ok = toBlob(cx, obj, self, args);
286
0
  if (ok) {
287
0
    return true;
288
0
  }
289
0
  return ConvertExceptionToPromise(cx, args.rval());
290
0
}
291
292
static const JSJitInfo toBlob_methodinfo = {
293
  { (JSJitGetterOp)toBlob_promiseWrapper },
294
  { prototypes::id::OffscreenCanvas },
295
  { PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth },
296
  JSJitInfo::Method,
297
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
298
  JSVAL_TYPE_OBJECT,  /* 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
static bool
311
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
312
0
{
313
0
  mozilla::dom::OffscreenCanvas* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OffscreenCanvas>(obj);
314
0
  // We don't want to preserve if we don't have a wrapper, and we
315
0
  // obviously can't preserve if we're not initialized.
316
0
  if (self && self->GetWrapperPreserveColor()) {
317
0
    PreserveWrapper(self);
318
0
  }
319
0
  return true;
320
0
}
321
322
static void
323
_finalize(js::FreeOp* fop, JSObject* obj)
324
0
{
325
0
  mozilla::dom::OffscreenCanvas* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OffscreenCanvas>(obj);
326
0
  if (self) {
327
0
    ClearWrapper(self, self, obj);
328
0
    AddForDeferredFinalization<mozilla::dom::OffscreenCanvas>(self);
329
0
  }
330
0
}
331
332
static size_t
333
_objectMoved(JSObject* obj, JSObject* old)
334
0
{
335
0
  mozilla::dom::OffscreenCanvas* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OffscreenCanvas>(obj);
336
0
  if (self) {
337
0
    UpdateWrapper(self, self, obj, old);
338
0
  }
339
0
340
0
  return 0;
341
0
}
342
343
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
344
#if defined(__clang__)
345
#pragma clang diagnostic push
346
#pragma clang diagnostic ignored "-Wmissing-braces"
347
#endif
348
static const JSFunctionSpec sMethods_specs[] = {
349
  JS_FNSPEC("getContext", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getContext_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
350
  JS_FNSPEC("transferToImageBitmap", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&transferToImageBitmap_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
351
  JS_FNSPEC("toBlob", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&toBlob_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
352
  JS_FS_END
353
};
354
#if defined(__clang__)
355
#pragma clang diagnostic pop
356
#endif
357
358
359
static const Prefable<const JSFunctionSpec> sMethods[] = {
360
  { nullptr, &sMethods_specs[0] },
361
  { nullptr, nullptr }
362
};
363
364
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
365
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
366
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
367
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
368
369
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
370
#if defined(__clang__)
371
#pragma clang diagnostic push
372
#pragma clang diagnostic ignored "-Wmissing-braces"
373
#endif
374
static const JSPropertySpec sAttributes_specs[] = {
375
  { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, GenericSetter<NormalThisPolicy>, &width_setterinfo },
376
  { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, GenericSetter<NormalThisPolicy>, &height_setterinfo },
377
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
378
};
379
#if defined(__clang__)
380
#pragma clang diagnostic pop
381
#endif
382
383
384
static const Prefable<const JSPropertySpec> sAttributes[] = {
385
  { nullptr, &sAttributes_specs[0] },
386
  { nullptr, nullptr }
387
};
388
389
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
390
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
391
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
392
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
393
394
395
static uint16_t sNativeProperties_sortedPropertyIndices[5];
396
static PropertyInfo sNativeProperties_propertyInfos[5];
397
398
static const NativePropertiesN<2> sNativeProperties = {
399
  false, 0,
400
  false, 0,
401
  true,  0 /* sMethods */,
402
  true,  1 /* sAttributes */,
403
  false, 0,
404
  false, 0,
405
  false, 0,
406
  -1,
407
  5,
408
  sNativeProperties_sortedPropertyIndices,
409
  {
410
    { sMethods, &sNativeProperties_propertyInfos[0] },
411
    { sAttributes, &sNativeProperties_propertyInfos[3] }
412
  }
413
};
414
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
415
    "We have a property info count that is oversized");
416
417
static bool
418
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
419
0
{
420
0
  AUTO_PROFILER_LABEL_FAST("OffscreenCanvas constructor", DOM, cx);
421
0
422
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
423
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
424
0
  if (!args.isConstructing()) {
425
0
    // XXXbz wish I could get the name from the callee instead of
426
0
    // Adding more relocations
427
0
    return ThrowConstructorWithoutNew(cx, "OffscreenCanvas");
428
0
  }
429
0
430
0
  JS::Rooted<JSObject*> desiredProto(cx);
431
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
432
0
    return false;
433
0
  }
434
0
435
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
436
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "OffscreenCanvas");
437
0
  }
438
0
  GlobalObject global(cx, obj);
439
0
  if (global.Failed()) {
440
0
    return false;
441
0
  }
442
0
443
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
444
0
  uint32_t arg0;
445
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
446
0
    return false;
447
0
  }
448
0
  uint32_t arg1;
449
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
450
0
    return false;
451
0
  }
452
0
  Maybe<JSAutoRealm> ar;
453
0
  if (objIsXray) {
454
0
    obj = js::CheckedUnwrap(obj);
455
0
    if (!obj) {
456
0
      return false;
457
0
    }
458
0
    ar.emplace(cx, obj);
459
0
    if (!JS_WrapObject(cx, &desiredProto)) {
460
0
      return false;
461
0
    }
462
0
  }
463
0
  FastErrorResult rv;
464
0
  auto result(StrongOrRawPtr<mozilla::dom::OffscreenCanvas>(mozilla::dom::OffscreenCanvas::Constructor(global, arg0, arg1, rv)));
465
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
466
0
    return false;
467
0
  }
468
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
469
0
  static_assert(!IsPointer<decltype(result)>::value,
470
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
471
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
472
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
473
0
    return false;
474
0
  }
475
0
  return true;
476
0
}
477
478
static const js::ClassOps sInterfaceObjectClassOps = {
479
    nullptr,               /* addProperty */
480
    nullptr,               /* delProperty */
481
    nullptr,               /* enumerate */
482
    nullptr,               /* newEnumerate */
483
    nullptr,               /* resolve */
484
    nullptr,               /* mayResolve */
485
    nullptr,               /* finalize */
486
    _constructor, /* call */
487
    nullptr,               /* hasInstance */
488
    _constructor, /* construct */
489
    nullptr,               /* trace */
490
};
491
492
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
493
  {
494
    "Function",
495
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
496
    &sInterfaceObjectClassOps,
497
    JS_NULL_CLASS_SPEC,
498
    JS_NULL_CLASS_EXT,
499
    &sInterfaceObjectClassObjectOps
500
  },
501
  eInterface,
502
  true,
503
  prototypes::id::OffscreenCanvas,
504
  PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth,
505
  sNativePropertyHooks,
506
  "function OffscreenCanvas() {\n    [native code]\n}",
507
  EventTarget_Binding::GetConstructorObject
508
};
509
510
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
511
  {
512
    "OffscreenCanvasPrototype",
513
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
514
    JS_NULL_CLASS_OPS,
515
    JS_NULL_CLASS_SPEC,
516
    JS_NULL_CLASS_EXT,
517
    JS_NULL_OBJECT_OPS
518
  },
519
  eInterfacePrototype,
520
  false,
521
  prototypes::id::OffscreenCanvas,
522
  PrototypeTraits<prototypes::id::OffscreenCanvas>::Depth,
523
  sNativePropertyHooks,
524
  "[object OffscreenCanvasPrototype]",
525
  EventTarget_Binding::GetProtoObject
526
};
527
528
bool
529
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
530
0
{
531
0
  return mozilla::dom::DOMPrefs::gfx_offscreencanvas_enabled(aCx, aObj);
532
0
}
533
534
static const js::ClassOps sClassOps = {
535
  _addProperty, /* addProperty */
536
  nullptr,               /* delProperty */
537
  nullptr,               /* enumerate */
538
  nullptr, /* newEnumerate */
539
  nullptr, /* resolve */
540
  nullptr, /* mayResolve */
541
  _finalize, /* finalize */
542
  nullptr, /* call */
543
  nullptr,               /* hasInstance */
544
  nullptr,               /* construct */
545
  nullptr, /* trace */
546
};
547
548
static const js::ClassExtension sClassExtension = {
549
  nullptr, /* weakmapKeyDelegateOp */
550
  _objectMoved /* objectMovedOp */
551
};
552
553
static const DOMJSClass sClass = {
554
  { "OffscreenCanvas",
555
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
556
    &sClassOps,
557
    JS_NULL_CLASS_SPEC,
558
    &sClassExtension,
559
    JS_NULL_OBJECT_OPS
560
  },
561
  { prototypes::id::EventTarget, prototypes::id::OffscreenCanvas, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
562
  IsBaseOf<nsISupports, mozilla::dom::OffscreenCanvas >::value,
563
  sNativePropertyHooks,
564
  FindAssociatedGlobalForNative<mozilla::dom::OffscreenCanvas>::Get,
565
  GetProtoObjectHandle,
566
  GetCCParticipant<mozilla::dom::OffscreenCanvas>::Get()
567
};
568
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
569
              "Must have the right minimal number of reserved slots.");
570
static_assert(1 >= 1,
571
              "Must have enough reserved slots.");
572
573
const JSClass*
574
GetJSClass()
575
0
{
576
0
  return sClass.ToJSClass();
577
0
}
578
579
bool
580
Wrap(JSContext* aCx, mozilla::dom::OffscreenCanvas* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
581
0
{
582
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::OffscreenCanvas>::value,
583
0
                "Shouldn't have wrappercached things that are not refcounted.");
584
0
  MOZ_ASSERT(static_cast<mozilla::dom::OffscreenCanvas*>(aObject) ==
585
0
             reinterpret_cast<mozilla::dom::OffscreenCanvas*>(aObject),
586
0
             "Multiple inheritance for mozilla::dom::OffscreenCanvas is broken.");
587
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
588
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
589
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
590
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
591
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
592
0
  MOZ_ASSERT(!aCache->GetWrapper(),
593
0
             "You should probably not be using Wrap() directly; use "
594
0
             "GetOrCreateDOMReflector instead");
595
0
596
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
597
0
             "nsISupports must be on our primary inheritance chain");
598
0
599
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
600
0
  if (!global) {
601
0
    return false;
602
0
  }
603
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
604
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
605
0
606
0
  // That might have ended up wrapping us already, due to the wonders
607
0
  // of XBL.  Check for that, and bail out as needed.
608
0
  aReflector.set(aCache->GetWrapper());
609
0
  if (aReflector) {
610
#ifdef DEBUG
611
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
612
#endif // DEBUG
613
    return true;
614
0
  }
615
0
616
0
  JSAutoRealm ar(aCx, global);
617
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
618
0
  if (!canonicalProto) {
619
0
    return false;
620
0
  }
621
0
  JS::Rooted<JSObject*> proto(aCx);
622
0
  if (aGivenProto) {
623
0
    proto = aGivenProto;
624
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
625
0
    // coming in, we changed compartments to that of "parent" so may need
626
0
    // to wrap the proto here.
627
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
628
0
      if (!JS_WrapObject(aCx, &proto)) {
629
0
        return false;
630
0
      }
631
0
    }
632
0
  } else {
633
0
    proto = canonicalProto;
634
0
  }
635
0
636
0
  BindingJSObjectCreator<mozilla::dom::OffscreenCanvas> creator(aCx);
637
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
638
0
  if (!aReflector) {
639
0
    return false;
640
0
  }
641
0
642
0
  aCache->SetWrapper(aReflector);
643
0
  creator.InitializationSucceeded();
644
0
645
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
646
0
             aCache->GetWrapperPreserveColor() == aReflector);
647
0
  // If proto != canonicalProto, we have to preserve our wrapper;
648
0
  // otherwise we won't be able to properly recreate it later, since
649
0
  // we won't know what proto to use.  Note that we don't check
650
0
  // aGivenProto here, since it's entirely possible (and even
651
0
  // somewhat common) to have a non-null aGivenProto which is the
652
0
  // same as canonicalProto.
653
0
  if (proto != canonicalProto) {
654
0
    PreserveWrapper(aObject);
655
0
  }
656
0
657
0
  return true;
658
0
}
659
660
const NativePropertyHooks sNativePropertyHooks[] = { {
661
  nullptr,
662
  nullptr,
663
  nullptr,
664
  { sNativeProperties.Upcast(), nullptr },
665
  prototypes::id::OffscreenCanvas,
666
  constructors::id::OffscreenCanvas,
667
  EventTarget_Binding::sNativePropertyHooks,
668
  &DefaultXrayExpandoObjectClass
669
} };
670
671
void
672
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
673
0
{
674
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
675
0
  if (!parentProto) {
676
0
    return;
677
0
  }
678
0
679
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
680
0
  if (!constructorProto) {
681
0
    return;
682
0
  }
683
0
684
0
  static bool sIdsInited = false;
685
0
  if (!sIdsInited && NS_IsMainThread()) {
686
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
687
0
      return;
688
0
    }
689
0
    sIdsInited = true;
690
0
  }
691
0
692
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::OffscreenCanvas);
693
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::OffscreenCanvas);
694
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
695
0
                              &sPrototypeClass.mBase, protoCache,
696
0
                              nullptr,
697
0
                              constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
698
0
                              interfaceCache,
699
0
                              sNativeProperties.Upcast(),
700
0
                              nullptr,
701
0
                              "OffscreenCanvas", aDefineOnGlobal,
702
0
                              nullptr,
703
0
                              false);
704
0
}
705
706
JSObject*
707
GetConstructorObject(JSContext* aCx)
708
0
{
709
0
  return GetConstructorObjectHandle(aCx);
710
0
}
711
712
} // namespace OffscreenCanvas_Binding
713
714
715
716
} // namespace dom
717
} // namespace mozilla