Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ShadowRootBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM ShadowRoot.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "DocumentFragmentBinding.h"
4
#include "ShadowRootBinding.h"
5
#include "WrapperFactory.h"
6
#include "jsapi.h"
7
#include "mozilla/FloatingPoint.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/CustomElementRegistry.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/DocGroup.h"
13
#include "mozilla/dom/Element.h"
14
#include "mozilla/dom/NonRefcountedDOMObject.h"
15
#include "mozilla/dom/Nullable.h"
16
#include "mozilla/dom/PrimitiveConversions.h"
17
#include "mozilla/dom/ShadowRoot.h"
18
#include "mozilla/dom/StyleSheetList.h"
19
#include "mozilla/dom/XrayExpandoClass.h"
20
#include "nsContentList.h"
21
#include "nsContentUtils.h"
22
#include "nsDocument.h"
23
#include "nsIDocument.h"
24
#include "nsINode.h"
25
26
namespace mozilla {
27
namespace dom {
28
29
namespace binding_detail {}; // Just to make sure it's known as a namespace
30
using namespace mozilla::dom::binding_detail;
31
32
33
namespace ShadowRootModeValues {
34
extern const EnumEntry strings[3] = {
35
  {"open", 4},
36
  {"closed", 6},
37
  { nullptr, 0 }
38
};
39
} // namespace ShadowRootModeValues
40
41
bool
42
ToJSValue(JSContext* aCx, ShadowRootMode aArgument, JS::MutableHandle<JS::Value> aValue)
43
0
{
44
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ShadowRootModeValues::strings));
45
0
  JSString* resultStr =
46
0
    JS_NewStringCopyN(aCx, ShadowRootModeValues::strings[uint32_t(aArgument)].value,
47
0
                      ShadowRootModeValues::strings[uint32_t(aArgument)].length);
48
0
  if (!resultStr) {
49
0
    return false;
50
0
  }
51
0
  aValue.setString(resultStr);
52
0
  return true;
53
0
}
54
55
56
namespace ShadowRoot_Binding {
57
58
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<DocumentFragment_Binding::NativeType>::value,
59
              "Can't inherit from an interface with a different ownership model.");
60
61
MOZ_CAN_RUN_SCRIPT static bool
62
get_mode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
63
0
{
64
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.mode", DOM, cx);
65
0
66
0
  ShadowRootMode result(self->Mode());
67
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
68
0
  if (!ToJSValue(cx, result, args.rval())) {
69
0
    return false;
70
0
  }
71
0
  return true;
72
0
}
73
74
static const JSJitInfo mode_getterinfo = {
75
  { (JSJitGetterOp)get_mode },
76
  { prototypes::id::ShadowRoot },
77
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
78
  JSJitInfo::Getter,
79
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
80
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
81
  false,  /* isInfallible. False in setters. */
82
  false,  /* isMovable.  Not relevant for setters. */
83
  false, /* isEliminatable.  Not relevant for setters. */
84
  false, /* isAlwaysInSlot.  Only relevant for getters. */
85
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
86
  false,  /* isTypedMethod.  Only relevant for methods. */
87
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
88
};
89
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
90
static_assert(0 < 1, "There is no slot for us");
91
92
MOZ_CAN_RUN_SCRIPT static bool
93
get_host(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
94
0
{
95
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.host", DOM, cx);
96
0
97
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->Host()));
98
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
99
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
100
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
101
0
    return false;
102
0
  }
103
0
  return true;
104
0
}
105
106
static const JSJitInfo host_getterinfo = {
107
  { (JSJitGetterOp)get_host },
108
  { prototypes::id::ShadowRoot },
109
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
110
  JSJitInfo::Getter,
111
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
112
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
113
  false,  /* isInfallible. False in setters. */
114
  false,  /* isMovable.  Not relevant for setters. */
115
  false, /* isEliminatable.  Not relevant for setters. */
116
  false, /* isAlwaysInSlot.  Only relevant for getters. */
117
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
118
  false,  /* isTypedMethod.  Only relevant for methods. */
119
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
120
};
121
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
122
static_assert(0 < 1, "There is no slot for us");
123
124
MOZ_CAN_RUN_SCRIPT static bool
125
getElementById(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
126
0
{
127
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.getElementById", DOM, cx);
128
0
129
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
130
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementById");
131
0
  }
132
0
  binding_detail::FakeString arg0;
133
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
134
0
    return false;
135
0
  }
136
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetElementById(NonNullHelper(Constify(arg0)))));
137
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
138
0
  if (!result) {
139
0
    args.rval().setNull();
140
0
    return true;
141
0
  }
142
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
143
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
144
0
    return false;
145
0
  }
146
0
  return true;
147
0
}
148
149
static const JSJitInfo getElementById_methodinfo = {
150
  { (JSJitGetterOp)getElementById },
151
  { prototypes::id::ShadowRoot },
152
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
153
  JSJitInfo::Method,
154
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
155
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
156
  false,  /* isInfallible. False in setters. */
157
  false,  /* isMovable.  Not relevant for setters. */
158
  false, /* isEliminatable.  Not relevant for setters. */
159
  false, /* isAlwaysInSlot.  Only relevant for getters. */
160
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
161
  false,  /* isTypedMethod.  Only relevant for methods. */
162
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
163
};
164
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
165
static_assert(0 < 1, "There is no slot for us");
166
167
MOZ_CAN_RUN_SCRIPT static bool
168
getElementsByTagName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
169
0
{
170
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.getElementsByTagName", DOM, cx);
171
0
172
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
173
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementsByTagName");
174
0
  }
175
0
  binding_detail::FakeString arg0;
176
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
177
0
    return false;
178
0
  }
179
0
  auto result(StrongOrRawPtr<nsIHTMLCollection>(self->GetElementsByTagName(NonNullHelper(Constify(arg0)))));
180
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
181
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
182
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
183
0
    return false;
184
0
  }
185
0
  return true;
186
0
}
187
188
static const JSJitInfo getElementsByTagName_methodinfo = {
189
  { (JSJitGetterOp)getElementsByTagName },
190
  { prototypes::id::ShadowRoot },
191
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
192
  JSJitInfo::Method,
193
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
194
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
195
  false,  /* isInfallible. False in setters. */
196
  false,  /* isMovable.  Not relevant for setters. */
197
  false, /* isEliminatable.  Not relevant for setters. */
198
  false, /* isAlwaysInSlot.  Only relevant for getters. */
199
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
200
  false,  /* isTypedMethod.  Only relevant for methods. */
201
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
202
};
203
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
204
static_assert(0 < 1, "There is no slot for us");
205
206
MOZ_CAN_RUN_SCRIPT static bool
207
getElementsByTagNameNS(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
208
0
{
209
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.getElementsByTagNameNS", DOM, cx);
210
0
211
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
212
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementsByTagNameNS");
213
0
  }
214
0
  binding_detail::FakeString arg0;
215
0
  if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) {
216
0
    return false;
217
0
  }
218
0
  binding_detail::FakeString arg1;
219
0
  if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
220
0
    return false;
221
0
  }
222
0
  auto result(StrongOrRawPtr<nsIHTMLCollection>(self->GetElementsByTagNameNS(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)))));
223
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
224
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
225
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
226
0
    return false;
227
0
  }
228
0
  return true;
229
0
}
230
231
static const JSJitInfo getElementsByTagNameNS_methodinfo = {
232
  { (JSJitGetterOp)getElementsByTagNameNS },
233
  { prototypes::id::ShadowRoot },
234
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
235
  JSJitInfo::Method,
236
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
237
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
238
  false,  /* isInfallible. False in setters. */
239
  false,  /* isMovable.  Not relevant for setters. */
240
  false, /* isEliminatable.  Not relevant for setters. */
241
  false, /* isAlwaysInSlot.  Only relevant for getters. */
242
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
243
  false,  /* isTypedMethod.  Only relevant for methods. */
244
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
245
};
246
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
247
static_assert(0 < 1, "There is no slot for us");
248
249
MOZ_CAN_RUN_SCRIPT static bool
250
getElementsByClassName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
251
0
{
252
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.getElementsByClassName", DOM, cx);
253
0
254
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
255
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementsByClassName");
256
0
  }
257
0
  binding_detail::FakeString arg0;
258
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
259
0
    return false;
260
0
  }
261
0
  auto result(StrongOrRawPtr<nsIHTMLCollection>(self->GetElementsByClassName(NonNullHelper(Constify(arg0)))));
262
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
263
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
264
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
265
0
    return false;
266
0
  }
267
0
  return true;
268
0
}
269
270
static const JSJitInfo getElementsByClassName_methodinfo = {
271
  { (JSJitGetterOp)getElementsByClassName },
272
  { prototypes::id::ShadowRoot },
273
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
274
  JSJitInfo::Method,
275
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
276
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
277
  false,  /* isInfallible. False in setters. */
278
  false,  /* isMovable.  Not relevant for setters. */
279
  false, /* isEliminatable.  Not relevant for setters. */
280
  false, /* isAlwaysInSlot.  Only relevant for getters. */
281
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
282
  false,  /* isTypedMethod.  Only relevant for methods. */
283
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
284
};
285
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
286
static_assert(0 < 1, "There is no slot for us");
287
288
MOZ_CAN_RUN_SCRIPT static bool
289
get_innerHTML(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
290
0
{
291
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.innerHTML", DOM, cx);
292
0
293
0
  DOMString result;
294
0
  self->GetInnerHTML(result);
295
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
296
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
297
0
    return false;
298
0
  }
299
0
  return true;
300
0
}
301
302
MOZ_CAN_RUN_SCRIPT static bool
303
set_innerHTML(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitSetterCallArgs args)
304
0
{
305
0
  AUTO_PROFILER_LABEL_FAST("set ShadowRoot.innerHTML", DOM, cx);
306
0
307
0
  binding_detail::FakeString arg0;
308
0
  if (!ConvertJSValueToString(cx, args[0], eEmpty, eStringify, arg0)) {
309
0
    return false;
310
0
  }
311
0
  Maybe<AutoCEReaction> ceReaction;
312
0
  if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) {
313
0
    DocGroup* docGroup = self->GetDocGroup();
314
0
    if (docGroup) {
315
0
      ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
316
0
    }
317
0
  }
318
0
  FastErrorResult rv;
319
0
  self->SetInnerHTML(NonNullHelper(Constify(arg0)), rv);
320
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
321
0
    return false;
322
0
  }
323
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
324
0
325
0
  return true;
326
0
}
327
328
static const JSJitInfo innerHTML_getterinfo = {
329
  { (JSJitGetterOp)get_innerHTML },
330
  { prototypes::id::ShadowRoot },
331
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
332
  JSJitInfo::Getter,
333
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
334
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
335
  false,  /* isInfallible. False in setters. */
336
  false,  /* isMovable.  Not relevant for setters. */
337
  false, /* isEliminatable.  Not relevant for setters. */
338
  false, /* isAlwaysInSlot.  Only relevant for getters. */
339
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
340
  false,  /* isTypedMethod.  Only relevant for methods. */
341
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
342
};
343
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
344
static_assert(0 < 1, "There is no slot for us");
345
static const JSJitInfo innerHTML_setterinfo = {
346
  { (JSJitGetterOp)set_innerHTML },
347
  { prototypes::id::ShadowRoot },
348
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
349
  JSJitInfo::Setter,
350
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
351
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
352
  false,  /* isInfallible. False in setters. */
353
  false,  /* isMovable.  Not relevant for setters. */
354
  false, /* isEliminatable.  Not relevant for setters. */
355
  false, /* isAlwaysInSlot.  Only relevant for getters. */
356
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
357
  false,  /* isTypedMethod.  Only relevant for methods. */
358
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
359
};
360
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
361
static_assert(0 < 1, "There is no slot for us");
362
363
MOZ_CAN_RUN_SCRIPT static bool
364
importNodeAndAppendChildAt(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
365
0
{
366
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.importNodeAndAppendChildAt", DOM, cx);
367
0
368
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
369
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.importNodeAndAppendChildAt");
370
0
  }
371
0
  NonNull<nsINode> arg0;
372
0
  if (args[0].isObject()) {
373
0
    {
374
0
      nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[0], arg0);
375
0
      if (NS_FAILED(rv)) {
376
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of ShadowRoot.importNodeAndAppendChildAt", "Node");
377
0
        return false;
378
0
      }
379
0
    }
380
0
  } else {
381
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of ShadowRoot.importNodeAndAppendChildAt");
382
0
    return false;
383
0
  }
384
0
  NonNull<nsINode> arg1;
385
0
  if (args[1].isObject()) {
386
0
    {
387
0
      nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[1], arg1);
388
0
      if (NS_FAILED(rv)) {
389
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of ShadowRoot.importNodeAndAppendChildAt", "Node");
390
0
        return false;
391
0
      }
392
0
    }
393
0
  } else {
394
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ShadowRoot.importNodeAndAppendChildAt");
395
0
    return false;
396
0
  }
397
0
  bool arg2;
398
0
  if (args.hasDefined(2)) {
399
0
    if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
400
0
      return false;
401
0
    }
402
0
  } else {
403
0
    arg2 = false;
404
0
  }
405
0
  Maybe<AutoCEReaction> ceReaction;
406
0
  if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) {
407
0
    DocGroup* docGroup = self->GetDocGroup();
408
0
    if (docGroup) {
409
0
      ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
410
0
    }
411
0
  }
412
0
  FastErrorResult rv;
413
0
  auto result(StrongOrRawPtr<nsINode>(self->ImportNodeAndAppendChildAt(MOZ_KnownLive(NonNullHelper(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), arg2, rv)));
414
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
415
0
    return false;
416
0
  }
417
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
418
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
419
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
420
0
    return false;
421
0
  }
422
0
  return true;
423
0
}
424
425
static const JSJitInfo importNodeAndAppendChildAt_methodinfo = {
426
  { (JSJitGetterOp)importNodeAndAppendChildAt },
427
  { prototypes::id::ShadowRoot },
428
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
429
  JSJitInfo::Method,
430
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
431
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
432
  false,  /* isInfallible. False in setters. */
433
  false,  /* isMovable.  Not relevant for setters. */
434
  false, /* isEliminatable.  Not relevant for setters. */
435
  false, /* isAlwaysInSlot.  Only relevant for getters. */
436
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
437
  false,  /* isTypedMethod.  Only relevant for methods. */
438
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
439
};
440
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
441
static_assert(0 < 1, "There is no slot for us");
442
443
MOZ_CAN_RUN_SCRIPT static bool
444
createElementAndAppendChildAt(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
445
0
{
446
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.createElementAndAppendChildAt", DOM, cx);
447
0
448
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
449
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.createElementAndAppendChildAt");
450
0
  }
451
0
  NonNull<nsINode> arg0;
452
0
  if (args[0].isObject()) {
453
0
    {
454
0
      nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[0], arg0);
455
0
      if (NS_FAILED(rv)) {
456
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of ShadowRoot.createElementAndAppendChildAt", "Node");
457
0
        return false;
458
0
      }
459
0
    }
460
0
  } else {
461
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of ShadowRoot.createElementAndAppendChildAt");
462
0
    return false;
463
0
  }
464
0
  binding_detail::FakeString arg1;
465
0
  if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
466
0
    return false;
467
0
  }
468
0
  Maybe<AutoCEReaction> ceReaction;
469
0
  if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) {
470
0
    DocGroup* docGroup = self->GetDocGroup();
471
0
    if (docGroup) {
472
0
      ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
473
0
    }
474
0
  }
475
0
  FastErrorResult rv;
476
0
  auto result(StrongOrRawPtr<nsINode>(self->CreateElementAndAppendChildAt(MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), rv)));
477
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
478
0
    return false;
479
0
  }
480
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
481
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
482
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
483
0
    return false;
484
0
  }
485
0
  return true;
486
0
}
487
488
static const JSJitInfo createElementAndAppendChildAt_methodinfo = {
489
  { (JSJitGetterOp)createElementAndAppendChildAt },
490
  { prototypes::id::ShadowRoot },
491
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
492
  JSJitInfo::Method,
493
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
494
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
495
  false,  /* isInfallible. False in setters. */
496
  false,  /* isMovable.  Not relevant for setters. */
497
  false, /* isEliminatable.  Not relevant for setters. */
498
  false, /* isAlwaysInSlot.  Only relevant for getters. */
499
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
500
  false,  /* isTypedMethod.  Only relevant for methods. */
501
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
502
};
503
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
504
static_assert(0 < 1, "There is no slot for us");
505
506
MOZ_CAN_RUN_SCRIPT static bool
507
setIsUAWidget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
508
0
{
509
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.setIsUAWidget", DOM, cx);
510
0
511
0
  self->SetIsUAWidget();
512
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
513
0
  args.rval().setUndefined();
514
0
  return true;
515
0
}
516
517
static const JSJitInfo setIsUAWidget_methodinfo = {
518
  { (JSJitGetterOp)setIsUAWidget },
519
  { prototypes::id::ShadowRoot },
520
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
521
  JSJitInfo::Method,
522
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
523
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
524
  true,  /* isInfallible. False in setters. */
525
  false,  /* isMovable.  Not relevant for setters. */
526
  false, /* isEliminatable.  Not relevant for setters. */
527
  false, /* isAlwaysInSlot.  Only relevant for getters. */
528
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
529
  false,  /* isTypedMethod.  Only relevant for methods. */
530
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
531
};
532
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
533
static_assert(0 < 1, "There is no slot for us");
534
535
MOZ_CAN_RUN_SCRIPT static bool
536
elementFromPoint(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
537
0
{
538
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.elementFromPoint", DOM, cx);
539
0
540
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
541
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.elementFromPoint");
542
0
  }
543
0
  float arg0;
544
0
  if (!ValueToPrimitive<float, eDefault>(cx, args[0], &arg0)) {
545
0
    return false;
546
0
  } else if (!mozilla::IsFinite(arg0)) {
547
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 1 of ShadowRoot.elementFromPoint");
548
0
    return false;
549
0
  }
550
0
  float arg1;
551
0
  if (!ValueToPrimitive<float, eDefault>(cx, args[1], &arg1)) {
552
0
    return false;
553
0
  } else if (!mozilla::IsFinite(arg1)) {
554
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of ShadowRoot.elementFromPoint");
555
0
    return false;
556
0
  }
557
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->ElementFromPoint(arg0, arg1)));
558
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
559
0
  if (!result) {
560
0
    args.rval().setNull();
561
0
    return true;
562
0
  }
563
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
564
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
565
0
    return false;
566
0
  }
567
0
  return true;
568
0
}
569
570
static const JSJitInfo elementFromPoint_methodinfo = {
571
  { (JSJitGetterOp)elementFromPoint },
572
  { prototypes::id::ShadowRoot },
573
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
574
  JSJitInfo::Method,
575
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
576
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
577
  false,  /* isInfallible. False in setters. */
578
  false,  /* isMovable.  Not relevant for setters. */
579
  false, /* isEliminatable.  Not relevant for setters. */
580
  false, /* isAlwaysInSlot.  Only relevant for getters. */
581
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
582
  false,  /* isTypedMethod.  Only relevant for methods. */
583
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
584
};
585
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
586
static_assert(0 < 1, "There is no slot for us");
587
588
MOZ_CAN_RUN_SCRIPT static bool
589
elementsFromPoint(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
590
0
{
591
0
  AUTO_PROFILER_LABEL_FAST("ShadowRoot.elementsFromPoint", DOM, cx);
592
0
593
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
594
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.elementsFromPoint");
595
0
  }
596
0
  float arg0;
597
0
  if (!ValueToPrimitive<float, eDefault>(cx, args[0], &arg0)) {
598
0
    return false;
599
0
  } else if (!mozilla::IsFinite(arg0)) {
600
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 1 of ShadowRoot.elementsFromPoint");
601
0
    return false;
602
0
  }
603
0
  float arg1;
604
0
  if (!ValueToPrimitive<float, eDefault>(cx, args[1], &arg1)) {
605
0
    return false;
606
0
  } else if (!mozilla::IsFinite(arg1)) {
607
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of ShadowRoot.elementsFromPoint");
608
0
    return false;
609
0
  }
610
0
  nsTArray<StrongPtrForMember<mozilla::dom::Element>::Type> result;
611
0
  self->ElementsFromPoint(arg0, arg1, result);
612
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
613
0
614
0
  uint32_t length = result.Length();
615
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
616
0
  if (!returnArray) {
617
0
    return false;
618
0
  }
619
0
  // Scope for 'tmp'
620
0
  {
621
0
    JS::Rooted<JS::Value> tmp(cx);
622
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
623
0
      // Control block to let us common up the JS_DefineElement calls when there
624
0
      // are different ways to succeed at wrapping the object.
625
0
      do {
626
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
627
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
628
0
          return false;
629
0
        }
630
0
        break;
631
0
      } while (false);
632
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
633
0
                            JSPROP_ENUMERATE)) {
634
0
        return false;
635
0
      }
636
0
    }
637
0
  }
638
0
  args.rval().setObject(*returnArray);
639
0
  return true;
640
0
}
641
642
static const JSJitInfo elementsFromPoint_methodinfo = {
643
  { (JSJitGetterOp)elementsFromPoint },
644
  { prototypes::id::ShadowRoot },
645
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
646
  JSJitInfo::Method,
647
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
648
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
649
  false,  /* isInfallible. False in setters. */
650
  false,  /* isMovable.  Not relevant for setters. */
651
  false, /* isEliminatable.  Not relevant for setters. */
652
  false, /* isAlwaysInSlot.  Only relevant for getters. */
653
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
654
  false,  /* isTypedMethod.  Only relevant for methods. */
655
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
656
};
657
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
658
static_assert(0 < 1, "There is no slot for us");
659
660
MOZ_CAN_RUN_SCRIPT static bool
661
get_activeElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
662
0
{
663
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.activeElement", DOM, cx);
664
0
665
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetActiveElement()));
666
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
667
0
  if (!result) {
668
0
    args.rval().setNull();
669
0
    return true;
670
0
  }
671
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
672
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
673
0
    return false;
674
0
  }
675
0
  return true;
676
0
}
677
678
static const JSJitInfo activeElement_getterinfo = {
679
  { (JSJitGetterOp)get_activeElement },
680
  { prototypes::id::ShadowRoot },
681
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
682
  JSJitInfo::Getter,
683
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
684
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
685
  false,  /* isInfallible. False in setters. */
686
  false,  /* isMovable.  Not relevant for setters. */
687
  false, /* isEliminatable.  Not relevant for setters. */
688
  false, /* isAlwaysInSlot.  Only relevant for getters. */
689
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
690
  false,  /* isTypedMethod.  Only relevant for methods. */
691
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
692
};
693
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
694
static_assert(0 < 1, "There is no slot for us");
695
696
MOZ_CAN_RUN_SCRIPT static bool
697
get_styleSheets(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
698
0
{
699
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.styleSheets", DOM, cx);
700
0
701
0
  auto result(StrongOrRawPtr<mozilla::dom::StyleSheetList>(self->StyleSheets()));
702
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
703
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
704
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
705
0
    return false;
706
0
  }
707
0
  return true;
708
0
}
709
710
static const JSJitInfo styleSheets_getterinfo = {
711
  { (JSJitGetterOp)get_styleSheets },
712
  { prototypes::id::ShadowRoot },
713
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
714
  JSJitInfo::Getter,
715
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
716
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
717
  false,  /* isInfallible. False in setters. */
718
  false,  /* isMovable.  Not relevant for setters. */
719
  false, /* isEliminatable.  Not relevant for setters. */
720
  false, /* isAlwaysInSlot.  Only relevant for getters. */
721
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
722
  false,  /* isTypedMethod.  Only relevant for methods. */
723
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
724
};
725
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
726
static_assert(0 < 1, "There is no slot for us");
727
728
MOZ_CAN_RUN_SCRIPT static bool
729
get_pointerLockElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
730
0
{
731
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.pointerLockElement", DOM, cx);
732
0
733
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetPointerLockElement()));
734
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
735
0
  if (!result) {
736
0
    args.rval().setNull();
737
0
    return true;
738
0
  }
739
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
740
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
741
0
    return false;
742
0
  }
743
0
  return true;
744
0
}
745
746
static const JSJitInfo pointerLockElement_getterinfo = {
747
  { (JSJitGetterOp)get_pointerLockElement },
748
  { prototypes::id::ShadowRoot },
749
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
750
  JSJitInfo::Getter,
751
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
752
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
753
  false,  /* isInfallible. False in setters. */
754
  false,  /* isMovable.  Not relevant for setters. */
755
  false, /* isEliminatable.  Not relevant for setters. */
756
  false, /* isAlwaysInSlot.  Only relevant for getters. */
757
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
758
  false,  /* isTypedMethod.  Only relevant for methods. */
759
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
760
};
761
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
762
static_assert(0 < 1, "There is no slot for us");
763
764
MOZ_CAN_RUN_SCRIPT static bool
765
get_fullscreenElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
766
0
{
767
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.fullscreenElement", DOM, cx);
768
0
769
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetFullscreenElement()));
770
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
771
0
  if (!result) {
772
0
    args.rval().setNull();
773
0
    return true;
774
0
  }
775
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
776
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
777
0
    return false;
778
0
  }
779
0
  return true;
780
0
}
781
782
MOZ_CAN_RUN_SCRIPT static bool
783
set_fullscreenElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitSetterCallArgs args)
784
0
{
785
0
  AUTO_PROFILER_LABEL_FAST("set ShadowRoot.fullscreenElement", DOM, cx);
786
0
787
0
  DeprecationWarning(cx, obj, nsIDocument::eLenientSetter);
788
0
  return true;
789
0
}
790
791
static const JSJitInfo fullscreenElement_getterinfo = {
792
  { (JSJitGetterOp)get_fullscreenElement },
793
  { prototypes::id::ShadowRoot },
794
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
795
  JSJitInfo::Getter,
796
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
797
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
798
  false,  /* isInfallible. False in setters. */
799
  false,  /* isMovable.  Not relevant for setters. */
800
  false, /* isEliminatable.  Not relevant for setters. */
801
  false, /* isAlwaysInSlot.  Only relevant for getters. */
802
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
803
  false,  /* isTypedMethod.  Only relevant for methods. */
804
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
805
};
806
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
807
static_assert(0 < 1, "There is no slot for us");
808
static const JSJitInfo fullscreenElement_setterinfo = {
809
  { (JSJitGetterOp)set_fullscreenElement },
810
  { prototypes::id::ShadowRoot },
811
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
812
  JSJitInfo::Setter,
813
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
814
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
815
  false,  /* isInfallible. False in setters. */
816
  false,  /* isMovable.  Not relevant for setters. */
817
  false, /* isEliminatable.  Not relevant for setters. */
818
  false, /* isAlwaysInSlot.  Only relevant for getters. */
819
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
820
  false,  /* isTypedMethod.  Only relevant for methods. */
821
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
822
};
823
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
824
static_assert(0 < 1, "There is no slot for us");
825
826
MOZ_CAN_RUN_SCRIPT static bool
827
get_mozFullScreenElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
828
0
{
829
0
  AUTO_PROFILER_LABEL_FAST("get ShadowRoot.mozFullScreenElement", DOM, cx);
830
0
831
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetFullscreenElement()));
832
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
833
0
  if (!result) {
834
0
    args.rval().setNull();
835
0
    return true;
836
0
  }
837
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
838
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
839
0
    return false;
840
0
  }
841
0
  return true;
842
0
}
843
844
static const JSJitInfo mozFullScreenElement_getterinfo = {
845
  { (JSJitGetterOp)get_mozFullScreenElement },
846
  { prototypes::id::ShadowRoot },
847
  { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
848
  JSJitInfo::Getter,
849
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
850
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
851
  false,  /* isInfallible. False in setters. */
852
  false,  /* isMovable.  Not relevant for setters. */
853
  false, /* isEliminatable.  Not relevant for setters. */
854
  false, /* isAlwaysInSlot.  Only relevant for getters. */
855
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
856
  false,  /* isTypedMethod.  Only relevant for methods. */
857
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
858
};
859
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
860
static_assert(0 < 1, "There is no slot for us");
861
862
static bool
863
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
864
0
{
865
0
  mozilla::dom::ShadowRoot* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ShadowRoot>(obj);
866
0
  // We don't want to preserve if we don't have a wrapper, and we
867
0
  // obviously can't preserve if we're not initialized.
868
0
  if (self && self->GetWrapperPreserveColor()) {
869
0
    PreserveWrapper(self);
870
0
  }
871
0
  return true;
872
0
}
873
874
static void
875
_finalize(js::FreeOp* fop, JSObject* obj)
876
0
{
877
0
  mozilla::dom::ShadowRoot* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ShadowRoot>(obj);
878
0
  if (self) {
879
0
    ClearWrapper(self, self, obj);
880
0
    AddForDeferredFinalization<mozilla::dom::ShadowRoot>(self);
881
0
  }
882
0
}
883
884
static size_t
885
_objectMoved(JSObject* obj, JSObject* old)
886
0
{
887
0
  mozilla::dom::ShadowRoot* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ShadowRoot>(obj);
888
0
  if (self) {
889
0
    UpdateWrapper(self, self, obj, old);
890
0
  }
891
0
892
0
  return 0;
893
0
}
894
895
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
896
#if defined(__clang__)
897
#pragma clang diagnostic push
898
#pragma clang diagnostic ignored "-Wmissing-braces"
899
#endif
900
static const JSFunctionSpec sMethods_specs[] = {
901
  JS_FNSPEC("getElementById", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getElementById_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
902
  JS_FNSPEC("getElementsByTagName", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getElementsByTagName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
903
  JS_FNSPEC("getElementsByTagNameNS", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getElementsByTagNameNS_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
904
  JS_FNSPEC("getElementsByClassName", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getElementsByClassName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
905
  JS_FS_END,
906
  JS_FNSPEC("importNodeAndAppendChildAt", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&importNodeAndAppendChildAt_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
907
  JS_FNSPEC("createElementAndAppendChildAt", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createElementAndAppendChildAt_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
908
  JS_FS_END,
909
  JS_FNSPEC("elementFromPoint", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&elementFromPoint_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
910
  JS_FNSPEC("elementsFromPoint", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&elementsFromPoint_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
911
  JS_FS_END
912
};
913
#if defined(__clang__)
914
#pragma clang diagnostic pop
915
#endif
916
917
// Can't be const because the pref-enabled boolean needs to be writable
918
static PrefableDisablers sMethods_disablers5 = {
919
  true, false, 0, &IsChromeOrXBLOrUAWidget
920
};
921
922
static const Prefable<const JSFunctionSpec> sMethods[] = {
923
  { nullptr, &sMethods_specs[0] },
924
  { &sMethods_disablers5, &sMethods_specs[5] },
925
  { nullptr, &sMethods_specs[8] },
926
  { nullptr, nullptr }
927
};
928
929
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
930
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
931
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
932
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
933
934
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
935
#if defined(__clang__)
936
#pragma clang diagnostic push
937
#pragma clang diagnostic ignored "-Wmissing-braces"
938
#endif
939
static const JSFunctionSpec sChromeMethods_specs[] = {
940
  JS_FNSPEC("setIsUAWidget", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setIsUAWidget_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
941
  JS_FS_END
942
};
943
#if defined(__clang__)
944
#pragma clang diagnostic pop
945
#endif
946
947
948
static const Prefable<const JSFunctionSpec> sChromeMethods[] = {
949
  { nullptr, &sChromeMethods_specs[0] },
950
  { nullptr, nullptr }
951
};
952
953
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
954
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
955
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
956
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
957
958
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
959
#if defined(__clang__)
960
#pragma clang diagnostic push
961
#pragma clang diagnostic ignored "-Wmissing-braces"
962
#endif
963
static const JSPropertySpec sAttributes_specs[] = {
964
  { "mode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mode_getterinfo, nullptr, nullptr },
965
  { "host", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &host_getterinfo, nullptr, nullptr },
966
  { "innerHTML", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &innerHTML_getterinfo, GenericSetter<NormalThisPolicy>, &innerHTML_setterinfo },
967
  { "activeElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &activeElement_getterinfo, nullptr, nullptr },
968
  { "styleSheets", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &styleSheets_getterinfo, nullptr, nullptr },
969
  { "pointerLockElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pointerLockElement_getterinfo, nullptr, nullptr },
970
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
971
  { "fullscreenElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &fullscreenElement_getterinfo, GenericSetter<NormalThisPolicy>, &fullscreenElement_setterinfo },
972
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
973
  { "mozFullScreenElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mozFullScreenElement_getterinfo, nullptr, nullptr },
974
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
975
};
976
#if defined(__clang__)
977
#pragma clang diagnostic pop
978
#endif
979
980
// Can't be const because the pref-enabled boolean needs to be writable
981
static PrefableDisablers sAttributes_disablers7 = {
982
  true, false, 0, &nsIDocument::IsUnprefixedFullscreenEnabled
983
};
984
985
static const Prefable<const JSPropertySpec> sAttributes[] = {
986
  { nullptr, &sAttributes_specs[0] },
987
  { &sAttributes_disablers7, &sAttributes_specs[7] },
988
  { nullptr, &sAttributes_specs[9] },
989
  { nullptr, nullptr }
990
};
991
992
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
993
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
994
static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
995
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
996
997
998
static uint16_t sNativeProperties_sortedPropertyIndices[16];
999
static PropertyInfo sNativeProperties_propertyInfos[16];
1000
1001
static const NativePropertiesN<2> sNativeProperties = {
1002
  false, 0,
1003
  false, 0,
1004
  true,  0 /* sMethods */,
1005
  true,  1 /* sAttributes */,
1006
  false, 0,
1007
  false, 0,
1008
  false, 0,
1009
  -1,
1010
  16,
1011
  sNativeProperties_sortedPropertyIndices,
1012
  {
1013
    { sMethods, &sNativeProperties_propertyInfos[0] },
1014
    { sAttributes, &sNativeProperties_propertyInfos[8] }
1015
  }
1016
};
1017
static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1018
    "We have a property info count that is oversized");
1019
1020
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
1021
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
1022
1023
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
1024
  false, 0,
1025
  false, 0,
1026
  true,  0 /* sChromeMethods */,
1027
  false, 0,
1028
  false, 0,
1029
  false, 0,
1030
  false, 0,
1031
  -1,
1032
  1,
1033
  sChromeOnlyNativeProperties_sortedPropertyIndices,
1034
  {
1035
    { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
1036
  }
1037
};
1038
static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
1039
    "We have a property info count that is oversized");
1040
1041
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1042
  {
1043
    "Function",
1044
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1045
    &sBoringInterfaceObjectClassClassOps,
1046
    JS_NULL_CLASS_SPEC,
1047
    JS_NULL_CLASS_EXT,
1048
    &sInterfaceObjectClassObjectOps
1049
  },
1050
  eInterface,
1051
  true,
1052
  prototypes::id::ShadowRoot,
1053
  PrototypeTraits<prototypes::id::ShadowRoot>::Depth,
1054
  sNativePropertyHooks,
1055
  "function ShadowRoot() {\n    [native code]\n}",
1056
  DocumentFragment_Binding::GetConstructorObject
1057
};
1058
1059
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1060
  {
1061
    "ShadowRootPrototype",
1062
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1063
    JS_NULL_CLASS_OPS,
1064
    JS_NULL_CLASS_SPEC,
1065
    JS_NULL_CLASS_EXT,
1066
    JS_NULL_OBJECT_OPS
1067
  },
1068
  eInterfacePrototype,
1069
  false,
1070
  prototypes::id::ShadowRoot,
1071
  PrototypeTraits<prototypes::id::ShadowRoot>::Depth,
1072
  sNativePropertyHooks,
1073
  "[object ShadowRootPrototype]",
1074
  DocumentFragment_Binding::GetProtoObject
1075
};
1076
1077
bool
1078
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1079
0
{
1080
0
  return nsDocument::IsShadowDOMEnabled(aCx, aObj);
1081
0
}
1082
1083
static const js::ClassOps sClassOps = {
1084
  _addProperty, /* addProperty */
1085
  nullptr,               /* delProperty */
1086
  nullptr,               /* enumerate */
1087
  nullptr, /* newEnumerate */
1088
  nullptr, /* resolve */
1089
  nullptr, /* mayResolve */
1090
  _finalize, /* finalize */
1091
  nullptr, /* call */
1092
  nullptr,               /* hasInstance */
1093
  nullptr,               /* construct */
1094
  nullptr, /* trace */
1095
};
1096
1097
static const js::ClassExtension sClassExtension = {
1098
  nullptr, /* weakmapKeyDelegateOp */
1099
  _objectMoved /* objectMovedOp */
1100
};
1101
1102
static const DOMJSClass sClass = {
1103
  { "ShadowRoot",
1104
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1105
    &sClassOps,
1106
    JS_NULL_CLASS_SPEC,
1107
    &sClassExtension,
1108
    JS_NULL_OBJECT_OPS
1109
  },
1110
  { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::DocumentFragment, prototypes::id::ShadowRoot, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1111
  IsBaseOf<nsISupports, mozilla::dom::ShadowRoot >::value,
1112
  sNativePropertyHooks,
1113
  FindAssociatedGlobalForNative<mozilla::dom::ShadowRoot>::Get,
1114
  GetProtoObjectHandle,
1115
  GetCCParticipant<mozilla::dom::ShadowRoot>::Get()
1116
};
1117
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1118
              "Must have the right minimal number of reserved slots.");
1119
static_assert(1 >= 1,
1120
              "Must have enough reserved slots.");
1121
1122
const JSClass*
1123
GetJSClass()
1124
0
{
1125
0
  return sClass.ToJSClass();
1126
0
}
1127
1128
bool
1129
Wrap(JSContext* aCx, mozilla::dom::ShadowRoot* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1130
0
{
1131
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ShadowRoot>::value,
1132
0
                "Shouldn't have wrappercached things that are not refcounted.");
1133
0
  MOZ_ASSERT(static_cast<mozilla::dom::ShadowRoot*>(aObject) ==
1134
0
             reinterpret_cast<mozilla::dom::ShadowRoot*>(aObject),
1135
0
             "Multiple inheritance for mozilla::dom::ShadowRoot is broken.");
1136
0
  MOZ_ASSERT(static_cast<mozilla::dom::DocumentFragment*>(aObject) ==
1137
0
             reinterpret_cast<mozilla::dom::DocumentFragment*>(aObject),
1138
0
             "Multiple inheritance for mozilla::dom::DocumentFragment is broken.");
1139
0
  MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
1140
0
             reinterpret_cast<nsINode*>(aObject),
1141
0
             "Multiple inheritance for nsINode is broken.");
1142
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
1143
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
1144
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
1145
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1146
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1147
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1148
0
             "You should probably not be using Wrap() directly; use "
1149
0
             "GetOrCreateDOMReflector instead");
1150
0
1151
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1152
0
             "nsISupports must be on our primary inheritance chain");
1153
0
1154
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1155
0
  if (!global) {
1156
0
    return false;
1157
0
  }
1158
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1159
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1160
0
1161
0
  // That might have ended up wrapping us already, due to the wonders
1162
0
  // of XBL.  Check for that, and bail out as needed.
1163
0
  aReflector.set(aCache->GetWrapper());
1164
0
  if (aReflector) {
1165
#ifdef DEBUG
1166
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1167
#endif // DEBUG
1168
    return true;
1169
0
  }
1170
0
1171
0
  JSAutoRealm ar(aCx, global);
1172
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1173
0
  if (!canonicalProto) {
1174
0
    return false;
1175
0
  }
1176
0
  JS::Rooted<JSObject*> proto(aCx);
1177
0
  if (aGivenProto) {
1178
0
    proto = aGivenProto;
1179
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1180
0
    // coming in, we changed compartments to that of "parent" so may need
1181
0
    // to wrap the proto here.
1182
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1183
0
      if (!JS_WrapObject(aCx, &proto)) {
1184
0
        return false;
1185
0
      }
1186
0
    }
1187
0
  } else {
1188
0
    proto = canonicalProto;
1189
0
  }
1190
0
1191
0
  BindingJSObjectCreator<mozilla::dom::ShadowRoot> creator(aCx);
1192
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1193
0
  if (!aReflector) {
1194
0
    return false;
1195
0
  }
1196
0
1197
0
  aCache->SetWrapper(aReflector);
1198
0
  creator.InitializationSucceeded();
1199
0
1200
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1201
0
             aCache->GetWrapperPreserveColor() == aReflector);
1202
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1203
0
  // otherwise we won't be able to properly recreate it later, since
1204
0
  // we won't know what proto to use.  Note that we don't check
1205
0
  // aGivenProto here, since it's entirely possible (and even
1206
0
  // somewhat common) to have a non-null aGivenProto which is the
1207
0
  // same as canonicalProto.
1208
0
  if (proto != canonicalProto) {
1209
0
    PreserveWrapper(aObject);
1210
0
  }
1211
0
1212
0
  return true;
1213
0
}
1214
1215
const NativePropertyHooks sNativePropertyHooks[] = { {
1216
  nullptr,
1217
  nullptr,
1218
  nullptr,
1219
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1220
  prototypes::id::ShadowRoot,
1221
  constructors::id::ShadowRoot,
1222
  DocumentFragment_Binding::sNativePropertyHooks,
1223
  &DefaultXrayExpandoObjectClass
1224
} };
1225
1226
void
1227
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1228
0
{
1229
0
  JS::Handle<JSObject*> parentProto(DocumentFragment_Binding::GetProtoObjectHandle(aCx));
1230
0
  if (!parentProto) {
1231
0
    return;
1232
0
  }
1233
0
1234
0
  JS::Handle<JSObject*> constructorProto(DocumentFragment_Binding::GetConstructorObjectHandle(aCx));
1235
0
  if (!constructorProto) {
1236
0
    return;
1237
0
  }
1238
0
1239
0
  static bool sIdsInited = false;
1240
0
  if (!sIdsInited && NS_IsMainThread()) {
1241
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1242
0
      return;
1243
0
    }
1244
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1245
0
      return;
1246
0
    }
1247
0
    sIdsInited = true;
1248
0
  }
1249
0
1250
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ShadowRoot);
1251
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ShadowRoot);
1252
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1253
0
                              &sPrototypeClass.mBase, protoCache,
1254
0
                              nullptr,
1255
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1256
0
                              interfaceCache,
1257
0
                              sNativeProperties.Upcast(),
1258
0
                              sChromeOnlyNativeProperties.Upcast(),
1259
0
                              "ShadowRoot", aDefineOnGlobal,
1260
0
                              nullptr,
1261
0
                              false);
1262
0
}
1263
1264
JSObject*
1265
GetConstructorObject(JSContext* aCx)
1266
0
{
1267
0
  return GetConstructorObjectHandle(aCx);
1268
0
}
1269
1270
} // namespace ShadowRoot_Binding
1271
1272
1273
1274
} // namespace dom
1275
} // namespace mozilla