Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM HTMLLegendElement.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "HTMLElementBinding.h"
4 : #include "HTMLLegendElementBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/CustomElementRegistry.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/HTMLFormElement.h"
11 : #include "mozilla/dom/HTMLLegendElement.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : namespace HTMLLegendElementBinding {
20 :
21 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElementBinding::NativeType>::value,
22 : "Can't inherit from an interface with a different ownership model.");
23 :
24 : static bool
25 0 : get_form(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLLegendElement* self, JSJitGetterCallArgs args)
26 : {
27 0 : auto result(StrongOrRawPtr<mozilla::dom::HTMLFormElement>(self->GetForm()));
28 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
29 0 : if (!result) {
30 0 : args.rval().setNull();
31 0 : return true;
32 : }
33 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
34 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
35 0 : return false;
36 : }
37 0 : return true;
38 : }
39 :
40 : static const JSJitInfo form_getterinfo = {
41 : { (JSJitGetterOp)get_form },
42 : { prototypes::id::HTMLLegendElement },
43 : { PrototypeTraits<prototypes::id::HTMLLegendElement>::Depth },
44 : JSJitInfo::Getter,
45 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
46 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
47 : false, /* isInfallible. False in setters. */
48 : false, /* isMovable. Not relevant for setters. */
49 : false, /* isEliminatable. Not relevant for setters. */
50 : false, /* isAlwaysInSlot. Only relevant for getters. */
51 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
52 : false, /* isTypedMethod. Only relevant for methods. */
53 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
54 : };
55 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
56 : static_assert(0 < 1, "There is no slot for us");
57 :
58 : static bool
59 0 : get_align(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLLegendElement* self, JSJitGetterCallArgs args)
60 : {
61 0 : DOMString result;
62 0 : self->GetAlign(result);
63 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
64 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
65 0 : return false;
66 : }
67 0 : return true;
68 : }
69 :
70 : static bool
71 0 : set_align(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLLegendElement* self, JSJitSetterCallArgs args)
72 : {
73 0 : binding_detail::FakeString arg0;
74 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
75 0 : return false;
76 : }
77 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
78 0 : Maybe<AutoCEReaction> ceReaction;
79 0 : if (reactionsStack) {
80 0 : ceReaction.emplace(reactionsStack);
81 : }
82 0 : binding_detail::FastErrorResult rv;
83 0 : self->SetAlign(NonNullHelper(Constify(arg0)), rv);
84 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
85 0 : return false;
86 : }
87 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
88 :
89 0 : return true;
90 : }
91 :
92 : static const JSJitInfo align_getterinfo = {
93 : { (JSJitGetterOp)get_align },
94 : { prototypes::id::HTMLLegendElement },
95 : { PrototypeTraits<prototypes::id::HTMLLegendElement>::Depth },
96 : JSJitInfo::Getter,
97 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
98 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
99 : false, /* isInfallible. False in setters. */
100 : false, /* isMovable. Not relevant for setters. */
101 : false, /* isEliminatable. Not relevant for setters. */
102 : false, /* isAlwaysInSlot. Only relevant for getters. */
103 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
104 : false, /* isTypedMethod. Only relevant for methods. */
105 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
106 : };
107 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
108 : static_assert(0 < 1, "There is no slot for us");
109 : static const JSJitInfo align_setterinfo = {
110 : { (JSJitGetterOp)set_align },
111 : { prototypes::id::HTMLLegendElement },
112 : { PrototypeTraits<prototypes::id::HTMLLegendElement>::Depth },
113 : JSJitInfo::Setter,
114 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
115 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
116 : false, /* isInfallible. False in setters. */
117 : false, /* isMovable. Not relevant for setters. */
118 : false, /* isEliminatable. Not relevant for setters. */
119 : false, /* isAlwaysInSlot. Only relevant for getters. */
120 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
121 : false, /* isTypedMethod. Only relevant for methods. */
122 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
123 : };
124 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
125 : static_assert(0 < 1, "There is no slot for us");
126 :
127 : static bool
128 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
129 : {
130 0 : mozilla::dom::HTMLLegendElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLLegendElement>(obj);
131 : // We don't want to preserve if we don't have a wrapper, and we
132 : // obviously can't preserve if we're not initialized.
133 0 : if (self && self->GetWrapperPreserveColor()) {
134 0 : PreserveWrapper(self);
135 : }
136 0 : return true;
137 : }
138 :
139 : static void
140 0 : _finalize(js::FreeOp* fop, JSObject* obj)
141 : {
142 0 : mozilla::dom::HTMLLegendElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLLegendElement>(obj);
143 0 : if (self) {
144 0 : ClearWrapper(self, self, obj);
145 0 : AddForDeferredFinalization<mozilla::dom::HTMLLegendElement>(self);
146 : }
147 0 : }
148 :
149 : static void
150 0 : _objectMoved(JSObject* obj, const JSObject* old)
151 : {
152 0 : mozilla::dom::HTMLLegendElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLLegendElement>(obj);
153 0 : if (self) {
154 0 : UpdateWrapper(self, self, obj, old);
155 : }
156 0 : }
157 :
158 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
159 : #if defined(__clang__)
160 : #pragma clang diagnostic push
161 : #pragma clang diagnostic ignored "-Wmissing-braces"
162 : #endif
163 : static const JSPropertySpec sAttributes_specs[] = {
164 : { "form", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &form_getterinfo, nullptr, nullptr },
165 : { "align", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &align_getterinfo, GenericBindingSetter, &align_setterinfo },
166 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
167 : };
168 : #if defined(__clang__)
169 : #pragma clang diagnostic pop
170 : #endif
171 :
172 :
173 : // Can't be const because the pref-enabled boolean needs to be writable
174 : static Prefable<const JSPropertySpec> sAttributes[] = {
175 : { nullptr, &sAttributes_specs[0] },
176 : { nullptr, nullptr }
177 : };
178 :
179 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
180 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
181 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
182 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
183 :
184 :
185 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
186 : static PropertyInfo sNativeProperties_propertyInfos[2];
187 :
188 : static const NativePropertiesN<1> sNativeProperties = {
189 : false, 0,
190 : false, 0,
191 : false, 0,
192 : true, 0 /* sAttributes */,
193 : false, 0,
194 : false, 0,
195 : false, 0,
196 : -1,
197 : 2,
198 : sNativeProperties_sortedPropertyIndices,
199 : {
200 : { sAttributes, &sNativeProperties_propertyInfos[0] }
201 : }
202 : };
203 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
204 : "We have a property info count that is oversized");
205 :
206 : static bool
207 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
208 : {
209 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
210 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
211 0 : if (!args.isConstructing()) {
212 : // XXXbz wish I could get the name from the callee instead of
213 : // Adding more relocations
214 0 : return ThrowConstructorWithoutNew(cx, "HTMLLegendElement");
215 : }
216 :
217 0 : GlobalObject global(cx, obj);
218 0 : if (global.Failed()) {
219 0 : return false;
220 : }
221 :
222 : // The newTarget might be a cross-compartment wrapper. Get the underlying object
223 : // so we can do the spec's object-identity checks.
224 0 : JS::Rooted<JSObject*> newTarget(cx, js::CheckedUnwrap(&args.newTarget().toObject()));
225 0 : if (!newTarget) {
226 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
227 : }
228 :
229 : // Step 2 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
230 : // Enter the compartment of our underlying newTarget object, so we end
231 : // up comparing to the constructor object for our interface from that global.
232 : {
233 0 : JSAutoCompartment ac(cx, newTarget);
234 0 : JS::Handle<JSObject*> constructor(GetConstructorObjectHandle(cx));
235 0 : if (!constructor) {
236 0 : return false;
237 : }
238 0 : if (newTarget == constructor) {
239 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
240 : }
241 : }
242 :
243 0 : JS::Rooted<JSObject*> desiredProto(cx);
244 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
245 0 : return false;
246 : }
247 0 : if (!desiredProto) {
248 : // Step 7 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
249 : // This fallback behavior is designed to match analogous behavior for the
250 : // JavaScript built-ins. So we enter the compartment of our underlying
251 : // newTarget object and fall back to the prototype object from that global.
252 : // XXX The spec says to use GetFunctionRealm(), which is not actually
253 : // the same thing as what we have here (e.g. in the case of scripted callable proxies
254 : // whose target is not same-compartment with the proxy, or bound functions, etc).
255 : // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658
256 : {
257 0 : JSAutoCompartment ac(cx, newTarget);
258 0 : desiredProto = GetProtoObjectHandle(cx);
259 0 : if (!desiredProto) {
260 0 : return false;
261 : }
262 : }
263 :
264 : // desiredProto is in the compartment of the underlying newTarget object.
265 : // Wrap it into the context compartment.
266 0 : if (!JS_WrapObject(cx, &desiredProto)) {
267 0 : return false;
268 : }
269 : }
270 :
271 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
272 0 : Maybe<JSAutoCompartment> ac;
273 0 : if (objIsXray) {
274 0 : obj = js::CheckedUnwrap(obj);
275 0 : if (!obj) {
276 0 : return false;
277 : }
278 0 : ac.emplace(cx, obj);
279 0 : if (!JS_WrapObject(cx, &desiredProto)) {
280 0 : return false;
281 : }
282 : }
283 0 : binding_detail::FastErrorResult rv;
284 0 : auto result(StrongOrRawPtr<mozilla::dom::HTMLLegendElement>(CreateHTMLElement(global, args, rv)));
285 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
286 0 : return false;
287 : }
288 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
289 : static_assert(!IsPointer<decltype(result)>::value,
290 : "NewObject implies that we need to keep the object alive with a strong reference.");
291 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
292 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
293 0 : return false;
294 : }
295 0 : return true;
296 : }
297 :
298 : static const js::ClassOps sInterfaceObjectClassOps = {
299 : nullptr, /* addProperty */
300 : nullptr, /* delProperty */
301 : nullptr, /* getProperty */
302 : nullptr, /* setProperty */
303 : nullptr, /* enumerate */
304 : nullptr, /* newEnumerate */
305 : nullptr, /* resolve */
306 : nullptr, /* mayResolve */
307 : nullptr, /* finalize */
308 : _constructor, /* call */
309 : nullptr, /* hasInstance */
310 : _constructor, /* construct */
311 : nullptr, /* trace */
312 : };
313 :
314 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
315 : {
316 : "Function",
317 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
318 : &sInterfaceObjectClassOps,
319 : JS_NULL_CLASS_SPEC,
320 : JS_NULL_CLASS_EXT,
321 : &sInterfaceObjectClassObjectOps
322 : },
323 : eInterface,
324 : true,
325 : prototypes::id::HTMLLegendElement,
326 : PrototypeTraits<prototypes::id::HTMLLegendElement>::Depth,
327 : sNativePropertyHooks,
328 : "function HTMLLegendElement() {\n [native code]\n}",
329 : HTMLElementBinding::GetConstructorObject
330 : };
331 :
332 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
333 : {
334 : "HTMLLegendElementPrototype",
335 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
336 : JS_NULL_CLASS_OPS,
337 : JS_NULL_CLASS_SPEC,
338 : JS_NULL_CLASS_EXT,
339 : JS_NULL_OBJECT_OPS
340 : },
341 : eInterfacePrototype,
342 : false,
343 : prototypes::id::HTMLLegendElement,
344 : PrototypeTraits<prototypes::id::HTMLLegendElement>::Depth,
345 : sNativePropertyHooks,
346 : "[object HTMLLegendElementPrototype]",
347 : HTMLElementBinding::GetProtoObject
348 : };
349 :
350 : JSObject*
351 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
352 : {
353 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
354 : }
355 :
356 : static const js::ClassOps sClassOps = {
357 : _addProperty, /* addProperty */
358 : nullptr, /* delProperty */
359 : nullptr, /* getProperty */
360 : nullptr, /* setProperty */
361 : nullptr, /* enumerate */
362 : nullptr, /* newEnumerate */
363 : nullptr, /* resolve */
364 : nullptr, /* mayResolve */
365 : _finalize, /* finalize */
366 : nullptr, /* call */
367 : nullptr, /* hasInstance */
368 : nullptr, /* construct */
369 : nullptr, /* trace */
370 : };
371 :
372 : static const js::ClassExtension sClassExtension = {
373 : nullptr, /* weakmapKeyDelegateOp */
374 : _objectMoved /* objectMovedOp */
375 : };
376 :
377 : static const DOMJSClass sClass = {
378 : { "HTMLLegendElement",
379 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
380 : &sClassOps,
381 : JS_NULL_CLASS_SPEC,
382 : &sClassExtension,
383 : JS_NULL_OBJECT_OPS
384 : },
385 : { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLLegendElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
386 : IsBaseOf<nsISupports, mozilla::dom::HTMLLegendElement >::value,
387 : sNativePropertyHooks,
388 : FindAssociatedGlobalForNative<mozilla::dom::HTMLLegendElement>::Get,
389 : GetProtoObjectHandle,
390 : GetCCParticipant<mozilla::dom::HTMLLegendElement>::Get()
391 : };
392 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
393 : "Must have the right minimal number of reserved slots.");
394 : static_assert(1 >= 1,
395 : "Must have enough reserved slots.");
396 :
397 : const JSClass*
398 0 : GetJSClass()
399 : {
400 0 : return sClass.ToJSClass();
401 : }
402 :
403 : bool
404 0 : Wrap(JSContext* aCx, mozilla::dom::HTMLLegendElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
405 : {
406 : MOZ_ASSERT(static_cast<mozilla::dom::HTMLLegendElement*>(aObject) ==
407 : reinterpret_cast<mozilla::dom::HTMLLegendElement*>(aObject),
408 : "Multiple inheritance for mozilla::dom::HTMLLegendElement is broken.");
409 : MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
410 : reinterpret_cast<nsGenericHTMLElement*>(aObject),
411 : "Multiple inheritance for nsGenericHTMLElement is broken.");
412 : MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
413 : reinterpret_cast<mozilla::dom::Element*>(aObject),
414 : "Multiple inheritance for mozilla::dom::Element is broken.");
415 : MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
416 : reinterpret_cast<nsINode*>(aObject),
417 : "Multiple inheritance for nsINode is broken.");
418 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
419 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
420 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
421 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
422 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
423 0 : MOZ_ASSERT(!aCache->GetWrapper(),
424 : "You should probably not be using Wrap() directly; use "
425 : "GetOrCreateDOMReflector instead");
426 :
427 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
428 : "nsISupports must be on our primary inheritance chain");
429 :
430 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
431 0 : if (!global) {
432 0 : return false;
433 : }
434 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
435 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
436 :
437 : // That might have ended up wrapping us already, due to the wonders
438 : // of XBL. Check for that, and bail out as needed.
439 0 : aReflector.set(aCache->GetWrapper());
440 0 : if (aReflector) {
441 : #ifdef DEBUG
442 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
443 : #endif // DEBUG
444 0 : return true;
445 : }
446 :
447 0 : JSAutoCompartment ac(aCx, global);
448 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
449 0 : if (!canonicalProto) {
450 0 : return false;
451 : }
452 0 : JS::Rooted<JSObject*> proto(aCx);
453 0 : if (aGivenProto) {
454 0 : proto = aGivenProto;
455 : // Unfortunately, while aGivenProto was in the compartment of aCx
456 : // coming in, we changed compartments to that of "parent" so may need
457 : // to wrap the proto here.
458 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
459 0 : if (!JS_WrapObject(aCx, &proto)) {
460 0 : return false;
461 : }
462 : }
463 : } else {
464 0 : proto = canonicalProto;
465 : }
466 :
467 0 : BindingJSObjectCreator<mozilla::dom::HTMLLegendElement> creator(aCx);
468 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
469 0 : if (!aReflector) {
470 0 : return false;
471 : }
472 :
473 0 : aCache->SetWrapper(aReflector);
474 0 : creator.InitializationSucceeded();
475 :
476 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
477 : aCache->GetWrapperPreserveColor() == aReflector);
478 : // If proto != canonicalProto, we have to preserve our wrapper;
479 : // otherwise we won't be able to properly recreate it later, since
480 : // we won't know what proto to use. Note that we don't check
481 : // aGivenProto here, since it's entirely possible (and even
482 : // somewhat common) to have a non-null aGivenProto which is the
483 : // same as canonicalProto.
484 0 : if (proto != canonicalProto) {
485 0 : PreserveWrapper(aObject);
486 : }
487 :
488 0 : return true;
489 : }
490 :
491 : const NativePropertyHooks sNativePropertyHooks[] = { {
492 : nullptr,
493 : nullptr,
494 : nullptr,
495 : { sNativeProperties.Upcast(), nullptr },
496 : prototypes::id::HTMLLegendElement,
497 : constructors::id::HTMLLegendElement,
498 : HTMLElementBinding::sNativePropertyHooks,
499 : &DefaultXrayExpandoObjectClass
500 : } };
501 :
502 : void
503 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
504 : {
505 0 : JS::Handle<JSObject*> parentProto(HTMLElementBinding::GetProtoObjectHandle(aCx));
506 0 : if (!parentProto) {
507 0 : return;
508 : }
509 :
510 0 : JS::Handle<JSObject*> constructorProto(HTMLElementBinding::GetConstructorObjectHandle(aCx));
511 0 : if (!constructorProto) {
512 0 : return;
513 : }
514 :
515 : static bool sIdsInited = false;
516 0 : if (!sIdsInited && NS_IsMainThread()) {
517 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
518 0 : return;
519 : }
520 0 : sIdsInited = true;
521 : }
522 :
523 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLLegendElement);
524 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLLegendElement);
525 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
526 : &sPrototypeClass.mBase, protoCache,
527 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
528 : interfaceCache,
529 : sNativeProperties.Upcast(),
530 : nullptr,
531 : "HTMLLegendElement", aDefineOnGlobal,
532 : nullptr,
533 0 : false);
534 : }
535 :
536 : JS::Handle<JSObject*>
537 0 : GetProtoObjectHandle(JSContext* aCx)
538 : {
539 : /* Get the interface prototype object for this class. This will create the
540 : object as needed. */
541 0 : bool aDefineOnGlobal = true;
542 :
543 : /* Make sure our global is sane. Hopefully we can remove this sometime */
544 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
545 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
546 0 : return nullptr;
547 : }
548 :
549 : /* Check to see whether the interface objects are already installed */
550 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
551 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::HTMLLegendElement)) {
552 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
553 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
554 : }
555 :
556 : /*
557 : * The object might _still_ be null, but that's OK.
558 : *
559 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
560 : * traced by TraceProtoAndIfaceCache() and its contents are never
561 : * changed after they have been set.
562 : *
563 : * Calling address() avoids the read read barrier that does gray
564 : * unmarking, but it's not possible for the object to be gray here.
565 : */
566 :
567 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::HTMLLegendElement);
568 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
569 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
570 : }
571 :
572 : JS::Handle<JSObject*>
573 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
574 : {
575 : /* Get the interface object for this class. This will create the object as
576 : needed. */
577 :
578 : /* Make sure our global is sane. Hopefully we can remove this sometime */
579 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
580 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
581 0 : return nullptr;
582 : }
583 :
584 : /* Check to see whether the interface objects are already installed */
585 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
586 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::HTMLLegendElement)) {
587 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
588 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
589 : }
590 :
591 : /*
592 : * The object might _still_ be null, but that's OK.
593 : *
594 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
595 : * traced by TraceProtoAndIfaceCache() and its contents are never
596 : * changed after they have been set.
597 : *
598 : * Calling address() avoids the read read barrier that does gray
599 : * unmarking, but it's not possible for the object to be gray here.
600 : */
601 :
602 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::HTMLLegendElement);
603 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
604 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
605 : }
606 :
607 : JSObject*
608 0 : GetConstructorObject(JSContext* aCx)
609 : {
610 0 : return GetConstructorObjectHandle(aCx);
611 : }
612 :
613 : } // namespace HTMLLegendElementBinding
614 :
615 :
616 :
617 : } // namespace dom
618 : } // namespace mozilla
|