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