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