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