/work/obj-fuzz/dom/bindings/CSSPseudoElementBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM CSSPseudoElement.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AnimatableBinding.h" |
4 | | #include "CSSPseudoElementBinding.h" |
5 | | #include "KeyframeAnimationOptionsBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/Animation.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/CSSPseudoElement.h" |
11 | | #include "mozilla/dom/DOMJSClass.h" |
12 | | #include "mozilla/dom/Element.h" |
13 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
14 | | #include "mozilla/dom/Nullable.h" |
15 | | #include "mozilla/dom/UnionConversions.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.h" |
17 | | #include "nsDocument.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
23 | | using namespace mozilla::dom::binding_detail; |
24 | | |
25 | | |
26 | | namespace CSSPseudoElement_Binding { |
27 | | |
28 | | MOZ_CAN_RUN_SCRIPT static bool |
29 | | get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSPseudoElement* self, JSJitGetterCallArgs args) |
30 | 0 | { |
31 | 0 | AUTO_PROFILER_LABEL_FAST("get CSSPseudoElement.type", DOM, cx); |
32 | 0 |
|
33 | 0 | DOMString result; |
34 | 0 | self->GetType(result); |
35 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
36 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
37 | 0 | return false; |
38 | 0 | } |
39 | 0 | return true; |
40 | 0 | } |
41 | | |
42 | | static const JSJitInfo type_getterinfo = { |
43 | | { (JSJitGetterOp)get_type }, |
44 | | { prototypes::id::CSSPseudoElement }, |
45 | | { PrototypeTraits<prototypes::id::CSSPseudoElement>::Depth }, |
46 | | JSJitInfo::Getter, |
47 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
48 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
49 | | false, /* isInfallible. False in setters. */ |
50 | | false, /* isMovable. Not relevant for setters. */ |
51 | | false, /* isEliminatable. Not relevant for setters. */ |
52 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
53 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
54 | | false, /* isTypedMethod. Only relevant for methods. */ |
55 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
56 | | }; |
57 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
58 | | static_assert(0 < 1, "There is no slot for us"); |
59 | | |
60 | | MOZ_CAN_RUN_SCRIPT static bool |
61 | | get_parentElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSPseudoElement* self, JSJitGetterCallArgs args) |
62 | 0 | { |
63 | 0 | AUTO_PROFILER_LABEL_FAST("get CSSPseudoElement.parentElement", DOM, cx); |
64 | 0 |
|
65 | 0 | auto result(StrongOrRawPtr<mozilla::dom::Element>(self->ParentElement())); |
66 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
67 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
68 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
69 | 0 | return false; |
70 | 0 | } |
71 | 0 | return true; |
72 | 0 | } |
73 | | |
74 | | static const JSJitInfo parentElement_getterinfo = { |
75 | | { (JSJitGetterOp)get_parentElement }, |
76 | | { prototypes::id::CSSPseudoElement }, |
77 | | { PrototypeTraits<prototypes::id::CSSPseudoElement>::Depth }, |
78 | | JSJitInfo::Getter, |
79 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
80 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
81 | | false, /* isInfallible. False in setters. */ |
82 | | false, /* isMovable. Not relevant for setters. */ |
83 | | false, /* isEliminatable. Not relevant for setters. */ |
84 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
85 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
86 | | false, /* isTypedMethod. Only relevant for methods. */ |
87 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
88 | | }; |
89 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
90 | | static_assert(0 < 1, "There is no slot for us"); |
91 | | |
92 | | MOZ_CAN_RUN_SCRIPT static bool |
93 | | animate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSPseudoElement* self, const JSJitMethodCallArgs& args) |
94 | 0 | { |
95 | 0 | AUTO_PROFILER_LABEL_FAST("CSSPseudoElement.animate", DOM, cx); |
96 | 0 |
|
97 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
98 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSPseudoElement.animate"); |
99 | 0 | } |
100 | 0 | JS::Rooted<JSObject*> arg0(cx); |
101 | 0 | if (args[0].isObject()) { |
102 | 0 | arg0 = &args[0].toObject(); |
103 | 0 | } else if (args[0].isNullOrUndefined()) { |
104 | 0 | arg0 = nullptr; |
105 | 0 | } else { |
106 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of CSSPseudoElement.animate"); |
107 | 0 | return false; |
108 | 0 | } |
109 | 0 | UnrestrictedDoubleOrKeyframeAnimationOptions arg1; |
110 | 0 | UnrestrictedDoubleOrKeyframeAnimationOptionsArgument arg1_holder(arg1); |
111 | 0 | if (!(args.hasDefined(1))) { |
112 | 0 | if (!arg1.RawSetAsKeyframeAnimationOptions().Init(cx, JS::NullHandleValue, "Member of UnrestrictedDoubleOrKeyframeAnimationOptions")) { |
113 | 0 | return false; |
114 | 0 | } |
115 | 0 | } else { |
116 | 0 | { |
117 | 0 | bool done = false, failed = false, tryNext; |
118 | 0 | if (!done) { |
119 | 0 | done = (failed = !arg1_holder.TrySetToKeyframeAnimationOptions(cx, args[1], tryNext, false)) || !tryNext; |
120 | 0 | } |
121 | 0 | if (!done) { |
122 | 0 | do { |
123 | 0 | done = (failed = !arg1_holder.TrySetToUnrestrictedDouble(cx, args[1], tryNext)) || !tryNext; |
124 | 0 | break; |
125 | 0 | } while (false); |
126 | 0 | } |
127 | 0 | if (failed) { |
128 | 0 | return false; |
129 | 0 | } |
130 | 0 | if (!done) { |
131 | 0 | ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 2 of CSSPseudoElement.animate", "KeyframeAnimationOptions"); |
132 | 0 | return false; |
133 | 0 | } |
134 | 0 | } |
135 | 0 | } |
136 | 0 | FastErrorResult rv; |
137 | 0 | auto result(StrongOrRawPtr<mozilla::dom::Animation>(self->Animate(cx, arg0, Constify(arg1), rv))); |
138 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
142 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
143 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | return true; |
147 | 0 | } |
148 | | |
149 | | static const JSJitInfo animate_methodinfo = { |
150 | | { (JSJitGetterOp)animate }, |
151 | | { prototypes::id::CSSPseudoElement }, |
152 | | { PrototypeTraits<prototypes::id::CSSPseudoElement>::Depth }, |
153 | | JSJitInfo::Method, |
154 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
155 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
156 | | false, /* isInfallible. False in setters. */ |
157 | | false, /* isMovable. Not relevant for setters. */ |
158 | | false, /* isEliminatable. Not relevant for setters. */ |
159 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
160 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
161 | | false, /* isTypedMethod. Only relevant for methods. */ |
162 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
163 | | }; |
164 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
165 | | static_assert(0 < 1, "There is no slot for us"); |
166 | | |
167 | | MOZ_CAN_RUN_SCRIPT static bool |
168 | | getAnimations(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSPseudoElement* self, const JSJitMethodCallArgs& args) |
169 | 0 | { |
170 | 0 | AUTO_PROFILER_LABEL_FAST("CSSPseudoElement.getAnimations", DOM, cx); |
171 | 0 |
|
172 | 0 | binding_detail::FastAnimationFilter arg0; |
173 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of CSSPseudoElement.getAnimations", false)) { |
174 | 0 | return false; |
175 | 0 | } |
176 | 0 | nsTArray<StrongPtrForMember<mozilla::dom::Animation>::Type> result; |
177 | 0 | self->GetAnimations(Constify(arg0), result); |
178 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
179 | 0 |
|
180 | 0 | uint32_t length = result.Length(); |
181 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
182 | 0 | if (!returnArray) { |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | // Scope for 'tmp' |
186 | 0 | { |
187 | 0 | JS::Rooted<JS::Value> tmp(cx); |
188 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
189 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
190 | 0 | // are different ways to succeed at wrapping the object. |
191 | 0 | do { |
192 | 0 | if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) { |
193 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
194 | 0 | return false; |
195 | 0 | } |
196 | 0 | break; |
197 | 0 | } while (false); |
198 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
199 | 0 | JSPROP_ENUMERATE)) { |
200 | 0 | return false; |
201 | 0 | } |
202 | 0 | } |
203 | 0 | } |
204 | 0 | args.rval().setObject(*returnArray); |
205 | 0 | return true; |
206 | 0 | } |
207 | | |
208 | | static const JSJitInfo getAnimations_methodinfo = { |
209 | | { (JSJitGetterOp)getAnimations }, |
210 | | { prototypes::id::CSSPseudoElement }, |
211 | | { PrototypeTraits<prototypes::id::CSSPseudoElement>::Depth }, |
212 | | JSJitInfo::Method, |
213 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
214 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
215 | | false, /* isInfallible. False in setters. */ |
216 | | false, /* isMovable. Not relevant for setters. */ |
217 | | false, /* isEliminatable. Not relevant for setters. */ |
218 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
219 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
220 | | false, /* isTypedMethod. Only relevant for methods. */ |
221 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
222 | | }; |
223 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
224 | | static_assert(0 < 1, "There is no slot for us"); |
225 | | |
226 | | static bool |
227 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
228 | 0 | { |
229 | 0 | mozilla::dom::CSSPseudoElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSPseudoElement>(obj); |
230 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
231 | 0 | // obviously can't preserve if we're not initialized. |
232 | 0 | if (self && self->GetWrapperPreserveColor()) { |
233 | 0 | PreserveWrapper(self); |
234 | 0 | } |
235 | 0 | return true; |
236 | 0 | } |
237 | | |
238 | | static void |
239 | | _finalize(js::FreeOp* fop, JSObject* obj) |
240 | 0 | { |
241 | 0 | mozilla::dom::CSSPseudoElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSPseudoElement>(obj); |
242 | 0 | if (self) { |
243 | 0 | ClearWrapper(self, self, obj); |
244 | 0 | AddForDeferredFinalization<mozilla::dom::CSSPseudoElement>(self); |
245 | 0 | } |
246 | 0 | } |
247 | | |
248 | | static size_t |
249 | | _objectMoved(JSObject* obj, JSObject* old) |
250 | 0 | { |
251 | 0 | mozilla::dom::CSSPseudoElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSPseudoElement>(obj); |
252 | 0 | if (self) { |
253 | 0 | UpdateWrapper(self, self, obj, old); |
254 | 0 | } |
255 | 0 |
|
256 | 0 | return 0; |
257 | 0 | } |
258 | | |
259 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
260 | | #if defined(__clang__) |
261 | | #pragma clang diagnostic push |
262 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
263 | | #endif |
264 | | static const JSFunctionSpec sMethods_specs[] = { |
265 | | JS_FNSPEC("animate", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&animate_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
266 | | JS_FS_END, |
267 | | JS_FNSPEC("getAnimations", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getAnimations_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
268 | | JS_FS_END |
269 | | }; |
270 | | #if defined(__clang__) |
271 | | #pragma clang diagnostic pop |
272 | | #endif |
273 | | |
274 | | // Can't be const because the pref-enabled boolean needs to be writable |
275 | | static PrefableDisablers sMethods_disablers2 = { |
276 | | true, false, 0, &nsDocument::IsWebAnimationsGetAnimationsEnabled |
277 | | }; |
278 | | |
279 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
280 | | { nullptr, &sMethods_specs[0] }, |
281 | | { &sMethods_disablers2, &sMethods_specs[2] }, |
282 | | { nullptr, nullptr } |
283 | | }; |
284 | | |
285 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
286 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
287 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
288 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
289 | | |
290 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
291 | | #if defined(__clang__) |
292 | | #pragma clang diagnostic push |
293 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
294 | | #endif |
295 | | static const JSPropertySpec sAttributes_specs[] = { |
296 | | { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr }, |
297 | | { "parentElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &parentElement_getterinfo, nullptr, nullptr }, |
298 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
299 | | }; |
300 | | #if defined(__clang__) |
301 | | #pragma clang diagnostic pop |
302 | | #endif |
303 | | |
304 | | |
305 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
306 | | { nullptr, &sAttributes_specs[0] }, |
307 | | { nullptr, nullptr } |
308 | | }; |
309 | | |
310 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
311 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
312 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
313 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
314 | | |
315 | | |
316 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
317 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
318 | | |
319 | | static const NativePropertiesN<2> sNativeProperties = { |
320 | | false, 0, |
321 | | false, 0, |
322 | | true, 0 /* sMethods */, |
323 | | true, 1 /* sAttributes */, |
324 | | false, 0, |
325 | | false, 0, |
326 | | false, 0, |
327 | | -1, |
328 | | 4, |
329 | | sNativeProperties_sortedPropertyIndices, |
330 | | { |
331 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
332 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
333 | | } |
334 | | }; |
335 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
336 | | "We have a property info count that is oversized"); |
337 | | |
338 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
339 | | { |
340 | | "Function", |
341 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
342 | | &sBoringInterfaceObjectClassClassOps, |
343 | | JS_NULL_CLASS_SPEC, |
344 | | JS_NULL_CLASS_EXT, |
345 | | &sInterfaceObjectClassObjectOps |
346 | | }, |
347 | | eInterface, |
348 | | true, |
349 | | prototypes::id::CSSPseudoElement, |
350 | | PrototypeTraits<prototypes::id::CSSPseudoElement>::Depth, |
351 | | sNativePropertyHooks, |
352 | | "function CSSPseudoElement() {\n [native code]\n}", |
353 | | JS::GetRealmFunctionPrototype |
354 | | }; |
355 | | |
356 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
357 | | { |
358 | | "CSSPseudoElementPrototype", |
359 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
360 | | JS_NULL_CLASS_OPS, |
361 | | JS_NULL_CLASS_SPEC, |
362 | | JS_NULL_CLASS_EXT, |
363 | | JS_NULL_OBJECT_OPS |
364 | | }, |
365 | | eInterfacePrototype, |
366 | | false, |
367 | | prototypes::id::CSSPseudoElement, |
368 | | PrototypeTraits<prototypes::id::CSSPseudoElement>::Depth, |
369 | | sNativePropertyHooks, |
370 | | "[object CSSPseudoElementPrototype]", |
371 | | JS::GetRealmObjectPrototype |
372 | | }; |
373 | | |
374 | | bool |
375 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
376 | 0 | { |
377 | 0 | return nsDocument::IsWebAnimationsGetAnimationsEnabled(aCx, aObj); |
378 | 0 | } |
379 | | |
380 | | static const js::ClassOps sClassOps = { |
381 | | _addProperty, /* addProperty */ |
382 | | nullptr, /* delProperty */ |
383 | | nullptr, /* enumerate */ |
384 | | nullptr, /* newEnumerate */ |
385 | | nullptr, /* resolve */ |
386 | | nullptr, /* mayResolve */ |
387 | | _finalize, /* finalize */ |
388 | | nullptr, /* call */ |
389 | | nullptr, /* hasInstance */ |
390 | | nullptr, /* construct */ |
391 | | nullptr, /* trace */ |
392 | | }; |
393 | | |
394 | | static const js::ClassExtension sClassExtension = { |
395 | | nullptr, /* weakmapKeyDelegateOp */ |
396 | | _objectMoved /* objectMovedOp */ |
397 | | }; |
398 | | |
399 | | static const DOMJSClass sClass = { |
400 | | { "CSSPseudoElement", |
401 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
402 | | &sClassOps, |
403 | | JS_NULL_CLASS_SPEC, |
404 | | &sClassExtension, |
405 | | JS_NULL_OBJECT_OPS |
406 | | }, |
407 | | { prototypes::id::CSSPseudoElement, 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 }, |
408 | | IsBaseOf<nsISupports, mozilla::dom::CSSPseudoElement >::value, |
409 | | sNativePropertyHooks, |
410 | | FindAssociatedGlobalForNative<mozilla::dom::CSSPseudoElement>::Get, |
411 | | GetProtoObjectHandle, |
412 | | GetCCParticipant<mozilla::dom::CSSPseudoElement>::Get() |
413 | | }; |
414 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
415 | | "Must have the right minimal number of reserved slots."); |
416 | | static_assert(1 >= 1, |
417 | | "Must have enough reserved slots."); |
418 | | |
419 | | const JSClass* |
420 | | GetJSClass() |
421 | 0 | { |
422 | 0 | return sClass.ToJSClass(); |
423 | 0 | } |
424 | | |
425 | | bool |
426 | | Wrap(JSContext* aCx, mozilla::dom::CSSPseudoElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
427 | 0 | { |
428 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::CSSPseudoElement>::value, |
429 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
430 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::CSSPseudoElement*>(aObject) == |
431 | 0 | reinterpret_cast<mozilla::dom::CSSPseudoElement*>(aObject), |
432 | 0 | "Multiple inheritance for mozilla::dom::CSSPseudoElement is broken."); |
433 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
434 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
435 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
436 | 0 | "You should probably not be using Wrap() directly; use " |
437 | 0 | "GetOrCreateDOMReflector instead"); |
438 | 0 |
|
439 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
440 | 0 | "nsISupports must be on our primary inheritance chain"); |
441 | 0 |
|
442 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
443 | 0 | if (!global) { |
444 | 0 | return false; |
445 | 0 | } |
446 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
447 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
448 | 0 |
|
449 | 0 | // That might have ended up wrapping us already, due to the wonders |
450 | 0 | // of XBL. Check for that, and bail out as needed. |
451 | 0 | aReflector.set(aCache->GetWrapper()); |
452 | 0 | if (aReflector) { |
453 | | #ifdef DEBUG |
454 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
455 | | #endif // DEBUG |
456 | | return true; |
457 | 0 | } |
458 | 0 |
|
459 | 0 | JSAutoRealm ar(aCx, global); |
460 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
461 | 0 | if (!canonicalProto) { |
462 | 0 | return false; |
463 | 0 | } |
464 | 0 | JS::Rooted<JSObject*> proto(aCx); |
465 | 0 | if (aGivenProto) { |
466 | 0 | proto = aGivenProto; |
467 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
468 | 0 | // coming in, we changed compartments to that of "parent" so may need |
469 | 0 | // to wrap the proto here. |
470 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
471 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
472 | 0 | return false; |
473 | 0 | } |
474 | 0 | } |
475 | 0 | } else { |
476 | 0 | proto = canonicalProto; |
477 | 0 | } |
478 | 0 |
|
479 | 0 | BindingJSObjectCreator<mozilla::dom::CSSPseudoElement> creator(aCx); |
480 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
481 | 0 | if (!aReflector) { |
482 | 0 | return false; |
483 | 0 | } |
484 | 0 | |
485 | 0 | aCache->SetWrapper(aReflector); |
486 | 0 | creator.InitializationSucceeded(); |
487 | 0 |
|
488 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
489 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
490 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
491 | 0 | // otherwise we won't be able to properly recreate it later, since |
492 | 0 | // we won't know what proto to use. Note that we don't check |
493 | 0 | // aGivenProto here, since it's entirely possible (and even |
494 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
495 | 0 | // same as canonicalProto. |
496 | 0 | if (proto != canonicalProto) { |
497 | 0 | PreserveWrapper(aObject); |
498 | 0 | } |
499 | 0 |
|
500 | 0 | return true; |
501 | 0 | } |
502 | | |
503 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
504 | | nullptr, |
505 | | nullptr, |
506 | | nullptr, |
507 | | { sNativeProperties.Upcast(), nullptr }, |
508 | | prototypes::id::CSSPseudoElement, |
509 | | constructors::id::CSSPseudoElement, |
510 | | nullptr, |
511 | | &DefaultXrayExpandoObjectClass |
512 | | } }; |
513 | | |
514 | | void |
515 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
516 | 0 | { |
517 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
518 | 0 | if (!parentProto) { |
519 | 0 | return; |
520 | 0 | } |
521 | 0 | |
522 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
523 | 0 | if (!constructorProto) { |
524 | 0 | return; |
525 | 0 | } |
526 | 0 | |
527 | 0 | static bool sIdsInited = false; |
528 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
529 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
530 | 0 | return; |
531 | 0 | } |
532 | 0 | sIdsInited = true; |
533 | 0 | } |
534 | 0 |
|
535 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSPseudoElement); |
536 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSPseudoElement); |
537 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
538 | 0 | &sPrototypeClass.mBase, protoCache, |
539 | 0 | nullptr, |
540 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
541 | 0 | interfaceCache, |
542 | 0 | sNativeProperties.Upcast(), |
543 | 0 | nullptr, |
544 | 0 | "CSSPseudoElement", aDefineOnGlobal, |
545 | 0 | nullptr, |
546 | 0 | false); |
547 | 0 | } |
548 | | |
549 | | JSObject* |
550 | | GetConstructorObject(JSContext* aCx) |
551 | 0 | { |
552 | 0 | return GetConstructorObjectHandle(aCx); |
553 | 0 | } |
554 | | |
555 | | } // namespace CSSPseudoElement_Binding |
556 | | |
557 | | |
558 | | |
559 | | } // namespace dom |
560 | | } // namespace mozilla |