/work/obj-fuzz/dom/bindings/CSSStyleSheetBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM CSSStyleSheet.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "CSSStyleSheetBinding.h" |
4 | | #include "StyleSheetBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "jsapi.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/StyleSheet.h" |
9 | | #include "mozilla/css/Rule.h" |
10 | | #include "mozilla/dom/BindingUtils.h" |
11 | | #include "mozilla/dom/CSSRuleList.h" |
12 | | #include "mozilla/dom/DOMJSClass.h" |
13 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
14 | | #include "mozilla/dom/Nullable.h" |
15 | | #include "mozilla/dom/PrimitiveConversions.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.h" |
17 | | #include "nsContentUtils.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 CSSStyleSheetParsingModeValues { |
27 | | extern const EnumEntry strings[4] = { |
28 | | {"author", 6}, |
29 | | {"user", 4}, |
30 | | {"agent", 5}, |
31 | | { nullptr, 0 } |
32 | | }; |
33 | | } // namespace CSSStyleSheetParsingModeValues |
34 | | |
35 | | bool |
36 | | ToJSValue(JSContext* aCx, CSSStyleSheetParsingMode aArgument, JS::MutableHandle<JS::Value> aValue) |
37 | 0 | { |
38 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(CSSStyleSheetParsingModeValues::strings)); |
39 | 0 | JSString* resultStr = |
40 | 0 | JS_NewStringCopyN(aCx, CSSStyleSheetParsingModeValues::strings[uint32_t(aArgument)].value, |
41 | 0 | CSSStyleSheetParsingModeValues::strings[uint32_t(aArgument)].length); |
42 | 0 | if (!resultStr) { |
43 | 0 | return false; |
44 | 0 | } |
45 | 0 | aValue.setString(resultStr); |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | |
50 | | namespace CSSStyleSheet_Binding { |
51 | | |
52 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<StyleSheet_Binding::NativeType>::value, |
53 | | "Can't inherit from an interface with a different ownership model."); |
54 | | |
55 | | MOZ_CAN_RUN_SCRIPT static bool |
56 | | get_ownerRule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args) |
57 | 0 | { |
58 | 0 | AUTO_PROFILER_LABEL_FAST("get CSSStyleSheet.ownerRule", DOM, cx); |
59 | 0 |
|
60 | 0 | auto result(StrongOrRawPtr<mozilla::css::Rule>(self->GetDOMOwnerRule())); |
61 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
62 | 0 | if (!result) { |
63 | 0 | args.rval().setNull(); |
64 | 0 | return true; |
65 | 0 | } |
66 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
67 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
68 | 0 | return false; |
69 | 0 | } |
70 | 0 | return true; |
71 | 0 | } |
72 | | |
73 | | static const JSJitInfo ownerRule_getterinfo = { |
74 | | { (JSJitGetterOp)get_ownerRule }, |
75 | | { prototypes::id::CSSStyleSheet }, |
76 | | { PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth }, |
77 | | JSJitInfo::Getter, |
78 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
79 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
80 | | false, /* isInfallible. False in setters. */ |
81 | | true, /* isMovable. Not relevant for setters. */ |
82 | | true, /* isEliminatable. Not relevant for setters. */ |
83 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
84 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
85 | | false, /* isTypedMethod. Only relevant for methods. */ |
86 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
87 | | }; |
88 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
89 | | static_assert(0 < 1, "There is no slot for us"); |
90 | | |
91 | | MOZ_CAN_RUN_SCRIPT static bool |
92 | | get_cssRules(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args) |
93 | 0 | { |
94 | 0 | AUTO_PROFILER_LABEL_FAST("get CSSStyleSheet.cssRules", DOM, cx); |
95 | 0 |
|
96 | 0 | FastErrorResult rv; |
97 | 0 | NonNull<nsIPrincipal> subjectPrincipal; |
98 | 0 | { |
99 | 0 | JS::Realm* realm = js::GetContextRealm(cx); |
100 | 0 | MOZ_ASSERT(realm); |
101 | 0 | JSPrincipals* principals = JS::GetRealmPrincipals(realm); |
102 | 0 | nsIPrincipal* principal = nsJSPrincipals::get(principals); |
103 | 0 |
|
104 | 0 | subjectPrincipal = principal; |
105 | 0 | } |
106 | 0 | auto result(StrongOrRawPtr<mozilla::dom::CSSRuleList>(self->GetCssRules(subjectPrincipal, rv))); |
107 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
111 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
112 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
113 | 0 | return false; |
114 | 0 | } |
115 | 0 | return true; |
116 | 0 | } |
117 | | |
118 | | static const JSJitInfo cssRules_getterinfo = { |
119 | | { (JSJitGetterOp)get_cssRules }, |
120 | | { prototypes::id::CSSStyleSheet }, |
121 | | { PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth }, |
122 | | JSJitInfo::Getter, |
123 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
124 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
125 | | false, /* isInfallible. False in setters. */ |
126 | | false, /* isMovable. Not relevant for setters. */ |
127 | | false, /* isEliminatable. Not relevant for setters. */ |
128 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
129 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
130 | | false, /* isTypedMethod. Only relevant for methods. */ |
131 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
132 | | }; |
133 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
134 | | static_assert(0 < 1, "There is no slot for us"); |
135 | | |
136 | | MOZ_CAN_RUN_SCRIPT static bool |
137 | | get_parsingMode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args) |
138 | 0 | { |
139 | 0 | AUTO_PROFILER_LABEL_FAST("get CSSStyleSheet.parsingMode", DOM, cx); |
140 | 0 |
|
141 | 0 | CSSStyleSheetParsingMode result(self->ParsingModeDOM()); |
142 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
143 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | return true; |
147 | 0 | } |
148 | | |
149 | | static const JSJitInfo parsingMode_getterinfo = { |
150 | | { (JSJitGetterOp)get_parsingMode }, |
151 | | { prototypes::id::CSSStyleSheet }, |
152 | | { PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth }, |
153 | | JSJitInfo::Getter, |
154 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
155 | | JSVAL_TYPE_STRING, /* 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 | | insertRule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, const JSJitMethodCallArgs& args) |
169 | 0 | { |
170 | 0 | AUTO_PROFILER_LABEL_FAST("CSSStyleSheet.insertRule", DOM, cx); |
171 | 0 |
|
172 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
173 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleSheet.insertRule"); |
174 | 0 | } |
175 | 0 | binding_detail::FakeString arg0; |
176 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | uint32_t arg1; |
180 | 0 | if (args.hasDefined(1)) { |
181 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
182 | 0 | return false; |
183 | 0 | } |
184 | 0 | } else { |
185 | 0 | arg1 = 0U; |
186 | 0 | } |
187 | 0 | FastErrorResult rv; |
188 | 0 | NonNull<nsIPrincipal> subjectPrincipal; |
189 | 0 | { |
190 | 0 | JS::Realm* realm = js::GetContextRealm(cx); |
191 | 0 | MOZ_ASSERT(realm); |
192 | 0 | JSPrincipals* principals = JS::GetRealmPrincipals(realm); |
193 | 0 | nsIPrincipal* principal = nsJSPrincipals::get(principals); |
194 | 0 |
|
195 | 0 | subjectPrincipal = principal; |
196 | 0 | } |
197 | 0 | uint32_t result(self->InsertRule(NonNullHelper(Constify(arg0)), arg1, subjectPrincipal, rv)); |
198 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
199 | 0 | return false; |
200 | 0 | } |
201 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
202 | 0 | args.rval().setNumber(result); |
203 | 0 | return true; |
204 | 0 | } |
205 | | |
206 | | static const JSJitInfo insertRule_methodinfo = { |
207 | | { (JSJitGetterOp)insertRule }, |
208 | | { prototypes::id::CSSStyleSheet }, |
209 | | { PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth }, |
210 | | JSJitInfo::Method, |
211 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
212 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
213 | | false, /* isInfallible. False in setters. */ |
214 | | false, /* isMovable. Not relevant for setters. */ |
215 | | false, /* isEliminatable. Not relevant for setters. */ |
216 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
217 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
218 | | false, /* isTypedMethod. Only relevant for methods. */ |
219 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
220 | | }; |
221 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
222 | | static_assert(0 < 1, "There is no slot for us"); |
223 | | |
224 | | MOZ_CAN_RUN_SCRIPT static bool |
225 | | deleteRule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, const JSJitMethodCallArgs& args) |
226 | 0 | { |
227 | 0 | AUTO_PROFILER_LABEL_FAST("CSSStyleSheet.deleteRule", DOM, cx); |
228 | 0 |
|
229 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
230 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleSheet.deleteRule"); |
231 | 0 | } |
232 | 0 | uint32_t arg0; |
233 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
234 | 0 | return false; |
235 | 0 | } |
236 | 0 | FastErrorResult rv; |
237 | 0 | NonNull<nsIPrincipal> subjectPrincipal; |
238 | 0 | { |
239 | 0 | JS::Realm* realm = js::GetContextRealm(cx); |
240 | 0 | MOZ_ASSERT(realm); |
241 | 0 | JSPrincipals* principals = JS::GetRealmPrincipals(realm); |
242 | 0 | nsIPrincipal* principal = nsJSPrincipals::get(principals); |
243 | 0 |
|
244 | 0 | subjectPrincipal = principal; |
245 | 0 | } |
246 | 0 | self->DeleteRule(arg0, subjectPrincipal, rv); |
247 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
248 | 0 | return false; |
249 | 0 | } |
250 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
251 | 0 | args.rval().setUndefined(); |
252 | 0 | return true; |
253 | 0 | } |
254 | | |
255 | | static const JSJitInfo deleteRule_methodinfo = { |
256 | | { (JSJitGetterOp)deleteRule }, |
257 | | { prototypes::id::CSSStyleSheet }, |
258 | | { PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth }, |
259 | | JSJitInfo::Method, |
260 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
261 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
262 | | false, /* isInfallible. False in setters. */ |
263 | | false, /* isMovable. Not relevant for setters. */ |
264 | | false, /* isEliminatable. Not relevant for setters. */ |
265 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
266 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
267 | | false, /* isTypedMethod. Only relevant for methods. */ |
268 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
269 | | }; |
270 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
271 | | static_assert(0 < 1, "There is no slot for us"); |
272 | | |
273 | | static bool |
274 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
275 | 0 | { |
276 | 0 | mozilla::StyleSheet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::StyleSheet>(obj); |
277 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
278 | 0 | // obviously can't preserve if we're not initialized. |
279 | 0 | if (self && self->GetWrapperPreserveColor()) { |
280 | 0 | PreserveWrapper(self); |
281 | 0 | } |
282 | 0 | return true; |
283 | 0 | } |
284 | | |
285 | | static void |
286 | | _finalize(js::FreeOp* fop, JSObject* obj) |
287 | 0 | { |
288 | 0 | mozilla::StyleSheet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::StyleSheet>(obj); |
289 | 0 | if (self) { |
290 | 0 | ClearWrapper(self, self, obj); |
291 | 0 | AddForDeferredFinalization<mozilla::StyleSheet>(self); |
292 | 0 | } |
293 | 0 | } |
294 | | |
295 | | static size_t |
296 | | _objectMoved(JSObject* obj, JSObject* old) |
297 | 0 | { |
298 | 0 | mozilla::StyleSheet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::StyleSheet>(obj); |
299 | 0 | if (self) { |
300 | 0 | UpdateWrapper(self, self, obj, old); |
301 | 0 | } |
302 | 0 |
|
303 | 0 | return 0; |
304 | 0 | } |
305 | | |
306 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
307 | | #if defined(__clang__) |
308 | | #pragma clang diagnostic push |
309 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
310 | | #endif |
311 | | static const JSFunctionSpec sMethods_specs[] = { |
312 | | JS_FNSPEC("insertRule", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&insertRule_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
313 | | JS_FNSPEC("deleteRule", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&deleteRule_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
314 | | JS_FS_END |
315 | | }; |
316 | | #if defined(__clang__) |
317 | | #pragma clang diagnostic pop |
318 | | #endif |
319 | | |
320 | | |
321 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
322 | | { nullptr, &sMethods_specs[0] }, |
323 | | { nullptr, nullptr } |
324 | | }; |
325 | | |
326 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
327 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
328 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
329 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
330 | | |
331 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
332 | | #if defined(__clang__) |
333 | | #pragma clang diagnostic push |
334 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
335 | | #endif |
336 | | static const JSPropertySpec sAttributes_specs[] = { |
337 | | { "ownerRule", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ownerRule_getterinfo, nullptr, nullptr }, |
338 | | { "cssRules", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &cssRules_getterinfo, nullptr, nullptr }, |
339 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
340 | | }; |
341 | | #if defined(__clang__) |
342 | | #pragma clang diagnostic pop |
343 | | #endif |
344 | | |
345 | | |
346 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
347 | | { nullptr, &sAttributes_specs[0] }, |
348 | | { nullptr, nullptr } |
349 | | }; |
350 | | |
351 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
352 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
353 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
354 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
355 | | |
356 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
357 | | #if defined(__clang__) |
358 | | #pragma clang diagnostic push |
359 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
360 | | #endif |
361 | | static const JSPropertySpec sChromeAttributes_specs[] = { |
362 | | { "parsingMode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &parsingMode_getterinfo, nullptr, nullptr }, |
363 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
364 | | }; |
365 | | #if defined(__clang__) |
366 | | #pragma clang diagnostic pop |
367 | | #endif |
368 | | |
369 | | |
370 | | static const Prefable<const JSPropertySpec> sChromeAttributes[] = { |
371 | | { nullptr, &sChromeAttributes_specs[0] }, |
372 | | { nullptr, nullptr } |
373 | | }; |
374 | | |
375 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
376 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
377 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
378 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
379 | | |
380 | | |
381 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
382 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
383 | | |
384 | | static const NativePropertiesN<2> sNativeProperties = { |
385 | | false, 0, |
386 | | false, 0, |
387 | | true, 0 /* sMethods */, |
388 | | true, 1 /* sAttributes */, |
389 | | false, 0, |
390 | | false, 0, |
391 | | false, 0, |
392 | | -1, |
393 | | 4, |
394 | | sNativeProperties_sortedPropertyIndices, |
395 | | { |
396 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
397 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
398 | | } |
399 | | }; |
400 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
401 | | "We have a property info count that is oversized"); |
402 | | |
403 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
404 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
405 | | |
406 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
407 | | false, 0, |
408 | | false, 0, |
409 | | false, 0, |
410 | | true, 0 /* sChromeAttributes */, |
411 | | false, 0, |
412 | | false, 0, |
413 | | false, 0, |
414 | | -1, |
415 | | 1, |
416 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
417 | | { |
418 | | { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] } |
419 | | } |
420 | | }; |
421 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
422 | | "We have a property info count that is oversized"); |
423 | | |
424 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
425 | | { |
426 | | "Function", |
427 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
428 | | &sBoringInterfaceObjectClassClassOps, |
429 | | JS_NULL_CLASS_SPEC, |
430 | | JS_NULL_CLASS_EXT, |
431 | | &sInterfaceObjectClassObjectOps |
432 | | }, |
433 | | eInterface, |
434 | | true, |
435 | | prototypes::id::CSSStyleSheet, |
436 | | PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth, |
437 | | sNativePropertyHooks, |
438 | | "function CSSStyleSheet() {\n [native code]\n}", |
439 | | StyleSheet_Binding::GetConstructorObject |
440 | | }; |
441 | | |
442 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
443 | | { |
444 | | "CSSStyleSheetPrototype", |
445 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
446 | | JS_NULL_CLASS_OPS, |
447 | | JS_NULL_CLASS_SPEC, |
448 | | JS_NULL_CLASS_EXT, |
449 | | JS_NULL_OBJECT_OPS |
450 | | }, |
451 | | eInterfacePrototype, |
452 | | false, |
453 | | prototypes::id::CSSStyleSheet, |
454 | | PrototypeTraits<prototypes::id::CSSStyleSheet>::Depth, |
455 | | sNativePropertyHooks, |
456 | | "[object CSSStyleSheetPrototype]", |
457 | | StyleSheet_Binding::GetProtoObject |
458 | | }; |
459 | | |
460 | | static const js::ClassOps sClassOps = { |
461 | | _addProperty, /* addProperty */ |
462 | | nullptr, /* delProperty */ |
463 | | nullptr, /* enumerate */ |
464 | | nullptr, /* newEnumerate */ |
465 | | nullptr, /* resolve */ |
466 | | nullptr, /* mayResolve */ |
467 | | _finalize, /* finalize */ |
468 | | nullptr, /* call */ |
469 | | nullptr, /* hasInstance */ |
470 | | nullptr, /* construct */ |
471 | | nullptr, /* trace */ |
472 | | }; |
473 | | |
474 | | static const js::ClassExtension sClassExtension = { |
475 | | nullptr, /* weakmapKeyDelegateOp */ |
476 | | _objectMoved /* objectMovedOp */ |
477 | | }; |
478 | | |
479 | | static const DOMJSClass sClass = { |
480 | | { "CSSStyleSheet", |
481 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
482 | | &sClassOps, |
483 | | JS_NULL_CLASS_SPEC, |
484 | | &sClassExtension, |
485 | | JS_NULL_OBJECT_OPS |
486 | | }, |
487 | | { prototypes::id::StyleSheet, prototypes::id::CSSStyleSheet, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
488 | | IsBaseOf<nsISupports, mozilla::StyleSheet >::value, |
489 | | sNativePropertyHooks, |
490 | | FindAssociatedGlobalForNative<mozilla::StyleSheet>::Get, |
491 | | GetProtoObjectHandle, |
492 | | GetCCParticipant<mozilla::StyleSheet>::Get() |
493 | | }; |
494 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
495 | | "Must have the right minimal number of reserved slots."); |
496 | | static_assert(1 >= 1, |
497 | | "Must have enough reserved slots."); |
498 | | |
499 | | const JSClass* |
500 | | GetJSClass() |
501 | 0 | { |
502 | 0 | return sClass.ToJSClass(); |
503 | 0 | } |
504 | | |
505 | | bool |
506 | | Wrap(JSContext* aCx, mozilla::StyleSheet* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
507 | 0 | { |
508 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::StyleSheet>::value, |
509 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
510 | 0 | MOZ_ASSERT(static_cast<mozilla::StyleSheet*>(aObject) == |
511 | 0 | reinterpret_cast<mozilla::StyleSheet*>(aObject), |
512 | 0 | "Multiple inheritance for mozilla::StyleSheet is broken."); |
513 | 0 | MOZ_ASSERT(static_cast<mozilla::StyleSheet*>(aObject) == |
514 | 0 | reinterpret_cast<mozilla::StyleSheet*>(aObject), |
515 | 0 | "Multiple inheritance for mozilla::StyleSheet 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 | 0 | "You should probably not be using Wrap() directly; use " |
520 | 0 | "GetOrCreateDOMReflector instead"); |
521 | 0 |
|
522 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
523 | 0 | "nsISupports must be on our primary inheritance chain"); |
524 | 0 |
|
525 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
526 | 0 | if (!global) { |
527 | 0 | return false; |
528 | 0 | } |
529 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
530 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
531 | 0 |
|
532 | 0 | // That might have ended up wrapping us already, due to the wonders |
533 | 0 | // of XBL. Check for that, and bail out as needed. |
534 | 0 | aReflector.set(aCache->GetWrapper()); |
535 | 0 | if (aReflector) { |
536 | | #ifdef DEBUG |
537 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
538 | | #endif // DEBUG |
539 | | return true; |
540 | 0 | } |
541 | 0 |
|
542 | 0 | JSAutoRealm ar(aCx, global); |
543 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
544 | 0 | if (!canonicalProto) { |
545 | 0 | return false; |
546 | 0 | } |
547 | 0 | JS::Rooted<JSObject*> proto(aCx); |
548 | 0 | if (aGivenProto) { |
549 | 0 | proto = aGivenProto; |
550 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
551 | 0 | // coming in, we changed compartments to that of "parent" so may need |
552 | 0 | // 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 | 0 | } |
557 | 0 | } |
558 | 0 | } else { |
559 | 0 | proto = canonicalProto; |
560 | 0 | } |
561 | 0 |
|
562 | 0 | BindingJSObjectCreator<mozilla::StyleSheet> creator(aCx); |
563 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
564 | 0 | if (!aReflector) { |
565 | 0 | return false; |
566 | 0 | } |
567 | 0 | |
568 | 0 | aCache->SetWrapper(aReflector); |
569 | 0 | creator.InitializationSucceeded(); |
570 | 0 |
|
571 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
572 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
573 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
574 | 0 | // otherwise we won't be able to properly recreate it later, since |
575 | 0 | // we won't know what proto to use. Note that we don't check |
576 | 0 | // aGivenProto here, since it's entirely possible (and even |
577 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
578 | 0 | // same as canonicalProto. |
579 | 0 | if (proto != canonicalProto) { |
580 | 0 | PreserveWrapper(aObject); |
581 | 0 | } |
582 | 0 |
|
583 | 0 | return true; |
584 | 0 | } |
585 | | |
586 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
587 | | nullptr, |
588 | | nullptr, |
589 | | nullptr, |
590 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
591 | | prototypes::id::CSSStyleSheet, |
592 | | constructors::id::CSSStyleSheet, |
593 | | StyleSheet_Binding::sNativePropertyHooks, |
594 | | &DefaultXrayExpandoObjectClass |
595 | | } }; |
596 | | |
597 | | void |
598 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
599 | 0 | { |
600 | 0 | JS::Handle<JSObject*> parentProto(StyleSheet_Binding::GetProtoObjectHandle(aCx)); |
601 | 0 | if (!parentProto) { |
602 | 0 | return; |
603 | 0 | } |
604 | 0 | |
605 | 0 | JS::Handle<JSObject*> constructorProto(StyleSheet_Binding::GetConstructorObjectHandle(aCx)); |
606 | 0 | if (!constructorProto) { |
607 | 0 | return; |
608 | 0 | } |
609 | 0 | |
610 | 0 | static bool sIdsInited = false; |
611 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
612 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
613 | 0 | return; |
614 | 0 | } |
615 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
616 | 0 | return; |
617 | 0 | } |
618 | 0 | sIdsInited = true; |
619 | 0 | } |
620 | 0 |
|
621 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSStyleSheet); |
622 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSStyleSheet); |
623 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
624 | 0 | &sPrototypeClass.mBase, protoCache, |
625 | 0 | nullptr, |
626 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
627 | 0 | interfaceCache, |
628 | 0 | sNativeProperties.Upcast(), |
629 | 0 | sChromeOnlyNativeProperties.Upcast(), |
630 | 0 | "CSSStyleSheet", aDefineOnGlobal, |
631 | 0 | nullptr, |
632 | 0 | false); |
633 | 0 | } |
634 | | |
635 | | JSObject* |
636 | | GetConstructorObject(JSContext* aCx) |
637 | 0 | { |
638 | 0 | return GetConstructorObjectHandle(aCx); |
639 | 0 | } |
640 | | |
641 | | } // namespace CSSStyleSheet_Binding |
642 | | |
643 | | |
644 | | |
645 | | } // namespace dom |
646 | | } // namespace mozilla |