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