Coverage Report

Created: 2018-09-25 14:53

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