Line data Source code
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 "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/DOMJSClass.h"
9 : #include "mozilla/dom/Element.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/Nullable.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ShadowRoot.h"
14 : #include "mozilla/dom/StyleSheetList.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 : #include "nsContentList.h"
17 : #include "nsDocument.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : namespace ShadowRootBinding {
23 :
24 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<DocumentFragmentBinding::NativeType>::value,
25 : "Can't inherit from an interface with a different ownership model.");
26 :
27 : static bool
28 0 : getElementById(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
29 : {
30 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
31 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementById");
32 : }
33 0 : binding_detail::FakeString arg0;
34 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
35 0 : return false;
36 : }
37 0 : auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetElementById(NonNullHelper(Constify(arg0)))));
38 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
39 0 : if (!result) {
40 0 : args.rval().setNull();
41 0 : return true;
42 : }
43 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
44 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
45 0 : return false;
46 : }
47 0 : return true;
48 : }
49 :
50 : static const JSJitInfo getElementById_methodinfo = {
51 : { (JSJitGetterOp)getElementById },
52 : { prototypes::id::ShadowRoot },
53 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
54 : JSJitInfo::Method,
55 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
56 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
57 : false, /* isInfallible. False in setters. */
58 : false, /* isMovable. Not relevant for setters. */
59 : false, /* isEliminatable. Not relevant for setters. */
60 : false, /* isAlwaysInSlot. Only relevant for getters. */
61 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
62 : false, /* isTypedMethod. Only relevant for methods. */
63 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
64 : };
65 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
66 : static_assert(0 < 1, "There is no slot for us");
67 :
68 : static bool
69 0 : getElementsByTagName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
70 : {
71 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
72 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementsByTagName");
73 : }
74 0 : binding_detail::FakeString arg0;
75 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
76 0 : return false;
77 : }
78 0 : auto result(StrongOrRawPtr<nsIHTMLCollection>(self->GetElementsByTagName(NonNullHelper(Constify(arg0)))));
79 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
80 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
81 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
82 0 : return false;
83 : }
84 0 : return true;
85 : }
86 :
87 : static const JSJitInfo getElementsByTagName_methodinfo = {
88 : { (JSJitGetterOp)getElementsByTagName },
89 : { prototypes::id::ShadowRoot },
90 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
91 : JSJitInfo::Method,
92 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
93 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
94 : false, /* isInfallible. False in setters. */
95 : false, /* isMovable. Not relevant for setters. */
96 : false, /* isEliminatable. Not relevant for setters. */
97 : false, /* isAlwaysInSlot. Only relevant for getters. */
98 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
99 : false, /* isTypedMethod. Only relevant for methods. */
100 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
101 : };
102 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
103 : static_assert(0 < 1, "There is no slot for us");
104 :
105 : static bool
106 0 : getElementsByTagNameNS(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
107 : {
108 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
109 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementsByTagNameNS");
110 : }
111 0 : binding_detail::FakeString arg0;
112 0 : if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) {
113 0 : return false;
114 : }
115 0 : binding_detail::FakeString arg1;
116 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
117 0 : return false;
118 : }
119 0 : auto result(StrongOrRawPtr<nsIHTMLCollection>(self->GetElementsByTagNameNS(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)))));
120 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
121 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
122 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
123 0 : return false;
124 : }
125 0 : return true;
126 : }
127 :
128 : static const JSJitInfo getElementsByTagNameNS_methodinfo = {
129 : { (JSJitGetterOp)getElementsByTagNameNS },
130 : { prototypes::id::ShadowRoot },
131 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
132 : JSJitInfo::Method,
133 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
134 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
135 : false, /* isInfallible. False in setters. */
136 : false, /* isMovable. Not relevant for setters. */
137 : false, /* isEliminatable. Not relevant for setters. */
138 : false, /* isAlwaysInSlot. Only relevant for getters. */
139 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
140 : false, /* isTypedMethod. Only relevant for methods. */
141 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
142 : };
143 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
144 : static_assert(0 < 1, "There is no slot for us");
145 :
146 : static bool
147 0 : getElementsByClassName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, const JSJitMethodCallArgs& args)
148 : {
149 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
150 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ShadowRoot.getElementsByClassName");
151 : }
152 0 : binding_detail::FakeString arg0;
153 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
154 0 : return false;
155 : }
156 0 : auto result(StrongOrRawPtr<nsIHTMLCollection>(self->GetElementsByClassName(NonNullHelper(Constify(arg0)))));
157 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
158 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
159 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
160 0 : return false;
161 : }
162 0 : return true;
163 : }
164 :
165 : static const JSJitInfo getElementsByClassName_methodinfo = {
166 : { (JSJitGetterOp)getElementsByClassName },
167 : { prototypes::id::ShadowRoot },
168 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
169 : JSJitInfo::Method,
170 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
171 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
172 : false, /* isInfallible. False in setters. */
173 : false, /* isMovable. Not relevant for setters. */
174 : false, /* isEliminatable. Not relevant for setters. */
175 : false, /* isAlwaysInSlot. Only relevant for getters. */
176 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
177 : false, /* isTypedMethod. Only relevant for methods. */
178 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
179 : };
180 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
181 : static_assert(0 < 1, "There is no slot for us");
182 :
183 : static bool
184 0 : get_innerHTML(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
185 : {
186 0 : DOMString result;
187 0 : self->GetInnerHTML(result);
188 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
189 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
190 0 : return false;
191 : }
192 0 : return true;
193 : }
194 :
195 : static bool
196 0 : set_innerHTML(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitSetterCallArgs args)
197 : {
198 0 : binding_detail::FakeString arg0;
199 0 : if (!ConvertJSValueToString(cx, args[0], eEmpty, eStringify, arg0)) {
200 0 : return false;
201 : }
202 0 : binding_detail::FastErrorResult rv;
203 0 : self->SetInnerHTML(NonNullHelper(Constify(arg0)), rv);
204 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
205 0 : return false;
206 : }
207 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
208 :
209 0 : return true;
210 : }
211 :
212 : static const JSJitInfo innerHTML_getterinfo = {
213 : { (JSJitGetterOp)get_innerHTML },
214 : { prototypes::id::ShadowRoot },
215 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
216 : JSJitInfo::Getter,
217 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
218 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
219 : false, /* isInfallible. False in setters. */
220 : false, /* isMovable. Not relevant for setters. */
221 : false, /* isEliminatable. Not relevant for setters. */
222 : false, /* isAlwaysInSlot. Only relevant for getters. */
223 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
224 : false, /* isTypedMethod. Only relevant for methods. */
225 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
226 : };
227 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
228 : static_assert(0 < 1, "There is no slot for us");
229 : static const JSJitInfo innerHTML_setterinfo = {
230 : { (JSJitGetterOp)set_innerHTML },
231 : { prototypes::id::ShadowRoot },
232 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
233 : JSJitInfo::Setter,
234 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
235 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
236 : false, /* isInfallible. False in setters. */
237 : false, /* isMovable. Not relevant for setters. */
238 : false, /* isEliminatable. Not relevant for setters. */
239 : false, /* isAlwaysInSlot. Only relevant for getters. */
240 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
241 : false, /* isTypedMethod. Only relevant for methods. */
242 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
243 : };
244 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
245 : static_assert(0 < 1, "There is no slot for us");
246 :
247 : static bool
248 0 : get_host(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
249 : {
250 0 : auto result(StrongOrRawPtr<mozilla::dom::Element>(self->Host()));
251 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
252 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
253 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
254 0 : return false;
255 : }
256 0 : return true;
257 : }
258 :
259 : static const JSJitInfo host_getterinfo = {
260 : { (JSJitGetterOp)get_host },
261 : { prototypes::id::ShadowRoot },
262 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
263 : JSJitInfo::Getter,
264 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
265 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
266 : false, /* isInfallible. False in setters. */
267 : false, /* isMovable. Not relevant for setters. */
268 : false, /* isEliminatable. Not relevant for setters. */
269 : false, /* isAlwaysInSlot. Only relevant for getters. */
270 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
271 : false, /* isTypedMethod. Only relevant for methods. */
272 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
273 : };
274 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
275 : static_assert(0 < 1, "There is no slot for us");
276 :
277 : static bool
278 0 : get_olderShadowRoot(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
279 : {
280 0 : auto result(StrongOrRawPtr<mozilla::dom::ShadowRoot>(self->GetOlderShadowRoot()));
281 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
282 0 : if (!result) {
283 0 : args.rval().setNull();
284 0 : return true;
285 : }
286 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
287 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
288 0 : return false;
289 : }
290 0 : return true;
291 : }
292 :
293 : static const JSJitInfo olderShadowRoot_getterinfo = {
294 : { (JSJitGetterOp)get_olderShadowRoot },
295 : { prototypes::id::ShadowRoot },
296 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
297 : JSJitInfo::Getter,
298 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
299 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
300 : false, /* isInfallible. False in setters. */
301 : false, /* isMovable. Not relevant for setters. */
302 : false, /* isEliminatable. Not relevant for setters. */
303 : false, /* isAlwaysInSlot. Only relevant for getters. */
304 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
305 : false, /* isTypedMethod. Only relevant for methods. */
306 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
307 : };
308 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
309 : static_assert(0 < 1, "There is no slot for us");
310 :
311 : static bool
312 0 : get_applyAuthorStyles(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
313 : {
314 0 : bool result(self->ApplyAuthorStyles());
315 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
316 0 : args.rval().setBoolean(result);
317 0 : return true;
318 : }
319 :
320 : static bool
321 0 : set_applyAuthorStyles(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitSetterCallArgs args)
322 : {
323 : bool arg0;
324 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
325 0 : return false;
326 : }
327 0 : self->SetApplyAuthorStyles(arg0);
328 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
329 :
330 0 : return true;
331 : }
332 :
333 : static const JSJitInfo applyAuthorStyles_getterinfo = {
334 : { (JSJitGetterOp)get_applyAuthorStyles },
335 : { prototypes::id::ShadowRoot },
336 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
337 : JSJitInfo::Getter,
338 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
339 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
340 : true, /* isInfallible. False in setters. */
341 : false, /* isMovable. Not relevant for setters. */
342 : false, /* isEliminatable. Not relevant for setters. */
343 : false, /* isAlwaysInSlot. Only relevant for getters. */
344 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
345 : false, /* isTypedMethod. Only relevant for methods. */
346 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
347 : };
348 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
349 : static_assert(0 < 1, "There is no slot for us");
350 : static const JSJitInfo applyAuthorStyles_setterinfo = {
351 : { (JSJitGetterOp)set_applyAuthorStyles },
352 : { prototypes::id::ShadowRoot },
353 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
354 : JSJitInfo::Setter,
355 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
356 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
357 : false, /* isInfallible. False in setters. */
358 : false, /* isMovable. Not relevant for setters. */
359 : false, /* isEliminatable. Not relevant for setters. */
360 : false, /* isAlwaysInSlot. Only relevant for getters. */
361 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
362 : false, /* isTypedMethod. Only relevant for methods. */
363 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
364 : };
365 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
366 : static_assert(0 < 1, "There is no slot for us");
367 :
368 : static bool
369 0 : get_styleSheets(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ShadowRoot* self, JSJitGetterCallArgs args)
370 : {
371 0 : auto result(StrongOrRawPtr<mozilla::dom::StyleSheetList>(self->StyleSheets()));
372 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
373 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
374 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
375 0 : return false;
376 : }
377 0 : return true;
378 : }
379 :
380 : static const JSJitInfo styleSheets_getterinfo = {
381 : { (JSJitGetterOp)get_styleSheets },
382 : { prototypes::id::ShadowRoot },
383 : { PrototypeTraits<prototypes::id::ShadowRoot>::Depth },
384 : JSJitInfo::Getter,
385 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
386 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
387 : false, /* isInfallible. False in setters. */
388 : false, /* isMovable. Not relevant for setters. */
389 : false, /* isEliminatable. Not relevant for setters. */
390 : false, /* isAlwaysInSlot. Only relevant for getters. */
391 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
392 : false, /* isTypedMethod. Only relevant for methods. */
393 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
394 : };
395 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
396 : static_assert(0 < 1, "There is no slot for us");
397 :
398 : static bool
399 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
400 : {
401 0 : mozilla::dom::ShadowRoot* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ShadowRoot>(obj);
402 : // We don't want to preserve if we don't have a wrapper, and we
403 : // obviously can't preserve if we're not initialized.
404 0 : if (self && self->GetWrapperPreserveColor()) {
405 0 : PreserveWrapper(self);
406 : }
407 0 : return true;
408 : }
409 :
410 : static void
411 0 : _finalize(js::FreeOp* fop, JSObject* obj)
412 : {
413 0 : mozilla::dom::ShadowRoot* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ShadowRoot>(obj);
414 0 : if (self) {
415 0 : ClearWrapper(self, self, obj);
416 0 : AddForDeferredFinalization<mozilla::dom::ShadowRoot>(self);
417 : }
418 0 : }
419 :
420 : static void
421 0 : _objectMoved(JSObject* obj, const JSObject* old)
422 : {
423 0 : mozilla::dom::ShadowRoot* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ShadowRoot>(obj);
424 0 : if (self) {
425 0 : UpdateWrapper(self, self, obj, old);
426 : }
427 0 : }
428 :
429 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
430 : #if defined(__clang__)
431 : #pragma clang diagnostic push
432 : #pragma clang diagnostic ignored "-Wmissing-braces"
433 : #endif
434 : static const JSFunctionSpec sMethods_specs[] = {
435 : JS_FNSPEC("getElementById", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getElementById_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
436 : JS_FNSPEC("getElementsByTagName", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getElementsByTagName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
437 : JS_FNSPEC("getElementsByTagNameNS", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getElementsByTagNameNS_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
438 : JS_FNSPEC("getElementsByClassName", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getElementsByClassName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
439 : JS_FS_END
440 : };
441 : #if defined(__clang__)
442 : #pragma clang diagnostic pop
443 : #endif
444 :
445 :
446 : // Can't be const because the pref-enabled boolean needs to be writable
447 : static Prefable<const JSFunctionSpec> sMethods[] = {
448 : { nullptr, &sMethods_specs[0] },
449 : { nullptr, nullptr }
450 : };
451 :
452 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
453 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
454 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
455 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
456 :
457 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
458 : #if defined(__clang__)
459 : #pragma clang diagnostic push
460 : #pragma clang diagnostic ignored "-Wmissing-braces"
461 : #endif
462 : static const JSPropertySpec sAttributes_specs[] = {
463 : { "innerHTML", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &innerHTML_getterinfo, GenericBindingSetter, &innerHTML_setterinfo },
464 : { "host", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &host_getterinfo, nullptr, nullptr },
465 : { "olderShadowRoot", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &olderShadowRoot_getterinfo, nullptr, nullptr },
466 : { "applyAuthorStyles", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &applyAuthorStyles_getterinfo, GenericBindingSetter, &applyAuthorStyles_setterinfo },
467 : { "styleSheets", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &styleSheets_getterinfo, nullptr, nullptr },
468 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
469 : };
470 : #if defined(__clang__)
471 : #pragma clang diagnostic pop
472 : #endif
473 :
474 :
475 : // Can't be const because the pref-enabled boolean needs to be writable
476 : static Prefable<const JSPropertySpec> sAttributes[] = {
477 : { nullptr, &sAttributes_specs[0] },
478 : { nullptr, nullptr }
479 : };
480 :
481 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
482 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
483 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
484 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
485 :
486 :
487 : static uint16_t sNativeProperties_sortedPropertyIndices[9];
488 : static PropertyInfo sNativeProperties_propertyInfos[9];
489 :
490 : static const NativePropertiesN<2> sNativeProperties = {
491 : false, 0,
492 : false, 0,
493 : true, 0 /* sMethods */,
494 : true, 1 /* sAttributes */,
495 : false, 0,
496 : false, 0,
497 : false, 0,
498 : -1,
499 : 9,
500 : sNativeProperties_sortedPropertyIndices,
501 : {
502 : { sMethods, &sNativeProperties_propertyInfos[0] },
503 : { sAttributes, &sNativeProperties_propertyInfos[4] }
504 : }
505 : };
506 : static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
507 : "We have a property info count that is oversized");
508 :
509 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
510 : {
511 : "Function",
512 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
513 : &sBoringInterfaceObjectClassClassOps,
514 : JS_NULL_CLASS_SPEC,
515 : JS_NULL_CLASS_EXT,
516 : &sInterfaceObjectClassObjectOps
517 : },
518 : eInterface,
519 : true,
520 : prototypes::id::ShadowRoot,
521 : PrototypeTraits<prototypes::id::ShadowRoot>::Depth,
522 : sNativePropertyHooks,
523 : "function ShadowRoot() {\n [native code]\n}",
524 : DocumentFragmentBinding::GetConstructorObject
525 : };
526 :
527 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
528 : {
529 : "ShadowRootPrototype",
530 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
531 : JS_NULL_CLASS_OPS,
532 : JS_NULL_CLASS_SPEC,
533 : JS_NULL_CLASS_EXT,
534 : JS_NULL_OBJECT_OPS
535 : },
536 : eInterfacePrototype,
537 : false,
538 : prototypes::id::ShadowRoot,
539 : PrototypeTraits<prototypes::id::ShadowRoot>::Depth,
540 : sNativePropertyHooks,
541 : "[object ShadowRootPrototype]",
542 : DocumentFragmentBinding::GetProtoObject
543 : };
544 :
545 : bool
546 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
547 : {
548 0 : return nsDocument::IsWebComponentsEnabled(aCx, aObj);
549 : }
550 :
551 : JSObject*
552 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
553 : {
554 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
555 : }
556 :
557 : static const js::ClassOps sClassOps = {
558 : _addProperty, /* addProperty */
559 : nullptr, /* delProperty */
560 : nullptr, /* getProperty */
561 : nullptr, /* setProperty */
562 : nullptr, /* enumerate */
563 : nullptr, /* newEnumerate */
564 : nullptr, /* resolve */
565 : nullptr, /* mayResolve */
566 : _finalize, /* finalize */
567 : nullptr, /* call */
568 : nullptr, /* hasInstance */
569 : nullptr, /* construct */
570 : nullptr, /* trace */
571 : };
572 :
573 : static const js::ClassExtension sClassExtension = {
574 : nullptr, /* weakmapKeyDelegateOp */
575 : _objectMoved /* objectMovedOp */
576 : };
577 :
578 : static const DOMJSClass sClass = {
579 : { "ShadowRoot",
580 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
581 : &sClassOps,
582 : JS_NULL_CLASS_SPEC,
583 : &sClassExtension,
584 : JS_NULL_OBJECT_OPS
585 : },
586 : { 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 },
587 : IsBaseOf<nsISupports, mozilla::dom::ShadowRoot >::value,
588 : sNativePropertyHooks,
589 : FindAssociatedGlobalForNative<mozilla::dom::ShadowRoot>::Get,
590 : GetProtoObjectHandle,
591 : GetCCParticipant<mozilla::dom::ShadowRoot>::Get()
592 : };
593 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
594 : "Must have the right minimal number of reserved slots.");
595 : static_assert(1 >= 1,
596 : "Must have enough reserved slots.");
597 :
598 : const JSClass*
599 0 : GetJSClass()
600 : {
601 0 : return sClass.ToJSClass();
602 : }
603 :
604 : bool
605 0 : Wrap(JSContext* aCx, mozilla::dom::ShadowRoot* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
606 : {
607 : MOZ_ASSERT(static_cast<mozilla::dom::ShadowRoot*>(aObject) ==
608 : reinterpret_cast<mozilla::dom::ShadowRoot*>(aObject),
609 : "Multiple inheritance for mozilla::dom::ShadowRoot is broken.");
610 : MOZ_ASSERT(static_cast<mozilla::dom::DocumentFragment*>(aObject) ==
611 : reinterpret_cast<mozilla::dom::DocumentFragment*>(aObject),
612 : "Multiple inheritance for mozilla::dom::DocumentFragment is broken.");
613 : MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
614 : reinterpret_cast<nsINode*>(aObject),
615 : "Multiple inheritance for nsINode is broken.");
616 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
617 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
618 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
619 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
620 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
621 0 : MOZ_ASSERT(!aCache->GetWrapper(),
622 : "You should probably not be using Wrap() directly; use "
623 : "GetOrCreateDOMReflector instead");
624 :
625 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
626 : "nsISupports must be on our primary inheritance chain");
627 :
628 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
629 0 : if (!global) {
630 0 : return false;
631 : }
632 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
633 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
634 :
635 : // That might have ended up wrapping us already, due to the wonders
636 : // of XBL. Check for that, and bail out as needed.
637 0 : aReflector.set(aCache->GetWrapper());
638 0 : if (aReflector) {
639 : #ifdef DEBUG
640 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
641 : #endif // DEBUG
642 0 : return true;
643 : }
644 :
645 0 : JSAutoCompartment ac(aCx, global);
646 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
647 0 : if (!canonicalProto) {
648 0 : return false;
649 : }
650 0 : JS::Rooted<JSObject*> proto(aCx);
651 0 : if (aGivenProto) {
652 0 : proto = aGivenProto;
653 : // Unfortunately, while aGivenProto was in the compartment of aCx
654 : // coming in, we changed compartments to that of "parent" so may need
655 : // to wrap the proto here.
656 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
657 0 : if (!JS_WrapObject(aCx, &proto)) {
658 0 : return false;
659 : }
660 : }
661 : } else {
662 0 : proto = canonicalProto;
663 : }
664 :
665 0 : BindingJSObjectCreator<mozilla::dom::ShadowRoot> creator(aCx);
666 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
667 0 : if (!aReflector) {
668 0 : return false;
669 : }
670 :
671 0 : aCache->SetWrapper(aReflector);
672 0 : creator.InitializationSucceeded();
673 :
674 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
675 : aCache->GetWrapperPreserveColor() == aReflector);
676 : // If proto != canonicalProto, we have to preserve our wrapper;
677 : // otherwise we won't be able to properly recreate it later, since
678 : // we won't know what proto to use. Note that we don't check
679 : // aGivenProto here, since it's entirely possible (and even
680 : // somewhat common) to have a non-null aGivenProto which is the
681 : // same as canonicalProto.
682 0 : if (proto != canonicalProto) {
683 0 : PreserveWrapper(aObject);
684 : }
685 :
686 0 : return true;
687 : }
688 :
689 : const NativePropertyHooks sNativePropertyHooks[] = { {
690 : nullptr,
691 : nullptr,
692 : nullptr,
693 : { sNativeProperties.Upcast(), nullptr },
694 : prototypes::id::ShadowRoot,
695 : constructors::id::ShadowRoot,
696 : DocumentFragmentBinding::sNativePropertyHooks,
697 : &DefaultXrayExpandoObjectClass
698 : } };
699 :
700 : void
701 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
702 : {
703 0 : JS::Handle<JSObject*> parentProto(DocumentFragmentBinding::GetProtoObjectHandle(aCx));
704 0 : if (!parentProto) {
705 0 : return;
706 : }
707 :
708 0 : JS::Handle<JSObject*> constructorProto(DocumentFragmentBinding::GetConstructorObjectHandle(aCx));
709 0 : if (!constructorProto) {
710 0 : return;
711 : }
712 :
713 : static bool sIdsInited = false;
714 0 : if (!sIdsInited && NS_IsMainThread()) {
715 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
716 0 : return;
717 : }
718 0 : sIdsInited = true;
719 : }
720 :
721 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ShadowRoot);
722 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ShadowRoot);
723 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
724 : &sPrototypeClass.mBase, protoCache,
725 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
726 : interfaceCache,
727 : sNativeProperties.Upcast(),
728 : nullptr,
729 : "ShadowRoot", aDefineOnGlobal,
730 : nullptr,
731 0 : false);
732 : }
733 :
734 : JS::Handle<JSObject*>
735 0 : GetProtoObjectHandle(JSContext* aCx)
736 : {
737 : /* Get the interface prototype object for this class. This will create the
738 : object as needed. */
739 0 : bool aDefineOnGlobal = true;
740 :
741 : /* Make sure our global is sane. Hopefully we can remove this sometime */
742 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
743 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
744 0 : return nullptr;
745 : }
746 :
747 : /* Check to see whether the interface objects are already installed */
748 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
749 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ShadowRoot)) {
750 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
751 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
752 : }
753 :
754 : /*
755 : * The object might _still_ be null, but that's OK.
756 : *
757 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
758 : * traced by TraceProtoAndIfaceCache() and its contents are never
759 : * changed after they have been set.
760 : *
761 : * Calling address() avoids the read read barrier that does gray
762 : * unmarking, but it's not possible for the object to be gray here.
763 : */
764 :
765 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ShadowRoot);
766 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
767 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
768 : }
769 :
770 : JS::Handle<JSObject*>
771 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
772 : {
773 : /* Get the interface object for this class. This will create the object as
774 : needed. */
775 :
776 : /* Make sure our global is sane. Hopefully we can remove this sometime */
777 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
778 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
779 0 : return nullptr;
780 : }
781 :
782 : /* Check to see whether the interface objects are already installed */
783 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
784 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ShadowRoot)) {
785 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
786 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
787 : }
788 :
789 : /*
790 : * The object might _still_ be null, but that's OK.
791 : *
792 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
793 : * traced by TraceProtoAndIfaceCache() and its contents are never
794 : * changed after they have been set.
795 : *
796 : * Calling address() avoids the read read barrier that does gray
797 : * unmarking, but it's not possible for the object to be gray here.
798 : */
799 :
800 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ShadowRoot);
801 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
802 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
803 : }
804 :
805 : JSObject*
806 0 : GetConstructorObject(JSContext* aCx)
807 : {
808 0 : return GetConstructorObjectHandle(aCx);
809 : }
810 :
811 : } // namespace ShadowRootBinding
812 :
813 :
814 :
815 : } // namespace dom
816 : } // namespace mozilla
|