Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM CSSRule.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "CSSRuleBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/StyleSheet.h"
7 : #include "mozilla/css/Rule.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/Nullable.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/XrayExpandoClass.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : namespace CSSRuleBinding {
19 :
20 : static bool
21 0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::css::Rule* self, JSJitGetterCallArgs args)
22 : {
23 0 : uint16_t result(self->Type());
24 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
25 0 : args.rval().setInt32(int32_t(result));
26 0 : return true;
27 : }
28 :
29 : static const JSJitInfo type_getterinfo = {
30 : { (JSJitGetterOp)get_type },
31 : { prototypes::id::CSSRule },
32 : { PrototypeTraits<prototypes::id::CSSRule>::Depth },
33 : JSJitInfo::Getter,
34 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
35 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
36 : true, /* isInfallible. False in setters. */
37 : false, /* isMovable. Not relevant for setters. */
38 : false, /* isEliminatable. Not relevant for setters. */
39 : false, /* isAlwaysInSlot. Only relevant for getters. */
40 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
41 : false, /* isTypedMethod. Only relevant for methods. */
42 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
43 : };
44 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
45 : static_assert(0 < 1, "There is no slot for us");
46 :
47 : static bool
48 0 : get_cssText(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::css::Rule* self, JSJitGetterCallArgs args)
49 : {
50 0 : DOMString result;
51 0 : self->GetCssText(result);
52 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
53 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
54 0 : return false;
55 : }
56 0 : return true;
57 : }
58 :
59 : static bool
60 0 : set_cssText(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::css::Rule* self, JSJitSetterCallArgs args)
61 : {
62 0 : binding_detail::FakeString arg0;
63 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
64 0 : return false;
65 : }
66 0 : self->SetCssText(NonNullHelper(Constify(arg0)));
67 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
68 :
69 0 : return true;
70 : }
71 :
72 : static const JSJitInfo cssText_getterinfo = {
73 : { (JSJitGetterOp)get_cssText },
74 : { prototypes::id::CSSRule },
75 : { PrototypeTraits<prototypes::id::CSSRule>::Depth },
76 : JSJitInfo::Getter,
77 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
78 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
79 : false, /* isInfallible. False in setters. */
80 : false, /* isMovable. Not relevant for setters. */
81 : false, /* isEliminatable. Not relevant for setters. */
82 : false, /* isAlwaysInSlot. Only relevant for getters. */
83 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
84 : false, /* isTypedMethod. Only relevant for methods. */
85 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
86 : };
87 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
88 : static_assert(0 < 1, "There is no slot for us");
89 : static const JSJitInfo cssText_setterinfo = {
90 : { (JSJitGetterOp)set_cssText },
91 : { prototypes::id::CSSRule },
92 : { PrototypeTraits<prototypes::id::CSSRule>::Depth },
93 : JSJitInfo::Setter,
94 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
95 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
96 : false, /* isInfallible. False in setters. */
97 : false, /* isMovable. Not relevant for setters. */
98 : false, /* isEliminatable. Not relevant for setters. */
99 : false, /* isAlwaysInSlot. Only relevant for getters. */
100 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
101 : false, /* isTypedMethod. Only relevant for methods. */
102 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
103 : };
104 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
105 : static_assert(0 < 1, "There is no slot for us");
106 :
107 : static bool
108 0 : get_parentRule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::css::Rule* self, JSJitGetterCallArgs args)
109 : {
110 0 : auto result(StrongOrRawPtr<mozilla::css::Rule>(self->GetParentRule()));
111 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
112 0 : if (!result) {
113 0 : args.rval().setNull();
114 0 : return true;
115 : }
116 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
117 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
118 0 : return false;
119 : }
120 0 : return true;
121 : }
122 :
123 : static const JSJitInfo parentRule_getterinfo = {
124 : { (JSJitGetterOp)get_parentRule },
125 : { prototypes::id::CSSRule },
126 : { PrototypeTraits<prototypes::id::CSSRule>::Depth },
127 : JSJitInfo::Getter,
128 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
129 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
130 : false, /* isInfallible. False in setters. */
131 : false, /* isMovable. Not relevant for setters. */
132 : false, /* isEliminatable. Not relevant for setters. */
133 : false, /* isAlwaysInSlot. Only relevant for getters. */
134 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
135 : false, /* isTypedMethod. Only relevant for methods. */
136 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
137 : };
138 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
139 : static_assert(0 < 1, "There is no slot for us");
140 :
141 : static bool
142 0 : get_parentStyleSheet(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::css::Rule* self, JSJitGetterCallArgs args)
143 : {
144 0 : auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->GetParentStyleSheet()));
145 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
146 0 : if (!result) {
147 0 : args.rval().setNull();
148 0 : return true;
149 : }
150 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
151 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
152 0 : return false;
153 : }
154 0 : return true;
155 : }
156 :
157 : static const JSJitInfo parentStyleSheet_getterinfo = {
158 : { (JSJitGetterOp)get_parentStyleSheet },
159 : { prototypes::id::CSSRule },
160 : { PrototypeTraits<prototypes::id::CSSRule>::Depth },
161 : JSJitInfo::Getter,
162 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
163 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
164 : false, /* isInfallible. False in setters. */
165 : false, /* isMovable. Not relevant for setters. */
166 : false, /* isEliminatable. Not relevant for setters. */
167 : false, /* isAlwaysInSlot. Only relevant for getters. */
168 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
169 : false, /* isTypedMethod. Only relevant for methods. */
170 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
171 : };
172 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
173 : static_assert(0 < 1, "There is no slot for us");
174 :
175 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
176 : #if defined(__clang__)
177 : #pragma clang diagnostic push
178 : #pragma clang diagnostic ignored "-Wmissing-braces"
179 : #endif
180 : static const JSPropertySpec sAttributes_specs[] = {
181 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, nullptr, nullptr },
182 : { "cssText", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &cssText_getterinfo, GenericBindingSetter, &cssText_setterinfo },
183 : { "parentRule", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &parentRule_getterinfo, nullptr, nullptr },
184 : { "parentStyleSheet", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &parentStyleSheet_getterinfo, nullptr, nullptr },
185 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
186 : };
187 : #if defined(__clang__)
188 : #pragma clang diagnostic pop
189 : #endif
190 :
191 :
192 : // Can't be const because the pref-enabled boolean needs to be writable
193 : static Prefable<const JSPropertySpec> sAttributes[] = {
194 : { nullptr, &sAttributes_specs[0] },
195 : { nullptr, nullptr }
196 : };
197 :
198 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
199 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
200 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
201 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
202 :
203 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
204 : #if defined(__clang__)
205 : #pragma clang diagnostic push
206 : #pragma clang diagnostic ignored "-Wmissing-braces"
207 : #endif
208 : static const ConstantSpec sConstants_specs[] = {
209 : { "STYLE_RULE", JS::Int32Value(1) },
210 : { "CHARSET_RULE", JS::Int32Value(2) },
211 : { "IMPORT_RULE", JS::Int32Value(3) },
212 : { "MEDIA_RULE", JS::Int32Value(4) },
213 : { "FONT_FACE_RULE", JS::Int32Value(5) },
214 : { "PAGE_RULE", JS::Int32Value(6) },
215 : { "NAMESPACE_RULE", JS::Int32Value(10) },
216 : { "KEYFRAMES_RULE", JS::Int32Value(7) },
217 : { "KEYFRAME_RULE", JS::Int32Value(8) },
218 : { "COUNTER_STYLE_RULE", JS::Int32Value(11) },
219 : { "SUPPORTS_RULE", JS::Int32Value(12) },
220 : { "FONT_FEATURE_VALUES_RULE", JS::Int32Value(14) },
221 : { 0, JS::UndefinedValue() }
222 : };
223 : #if defined(__clang__)
224 : #pragma clang diagnostic pop
225 : #endif
226 :
227 :
228 : // Can't be const because the pref-enabled boolean needs to be writable
229 : static Prefable<const ConstantSpec> sConstants[] = {
230 : { nullptr, &sConstants_specs[0] },
231 : { nullptr, nullptr }
232 : };
233 :
234 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
235 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
236 : static_assert(12 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
237 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
238 :
239 :
240 : static uint16_t sNativeProperties_sortedPropertyIndices[16];
241 : static PropertyInfo sNativeProperties_propertyInfos[16];
242 :
243 : static const NativePropertiesN<2> sNativeProperties = {
244 : false, 0,
245 : false, 0,
246 : false, 0,
247 : true, 0 /* sAttributes */,
248 : false, 0,
249 : false, 0,
250 : true, 1 /* sConstants */,
251 : -1,
252 : 16,
253 : sNativeProperties_sortedPropertyIndices,
254 : {
255 : { sAttributes, &sNativeProperties_propertyInfos[0] },
256 : { sConstants, &sNativeProperties_propertyInfos[4] }
257 : }
258 : };
259 : static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
260 : "We have a property info count that is oversized");
261 :
262 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
263 : {
264 : "Function",
265 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
266 : &sBoringInterfaceObjectClassClassOps,
267 : JS_NULL_CLASS_SPEC,
268 : JS_NULL_CLASS_EXT,
269 : &sInterfaceObjectClassObjectOps
270 : },
271 : eInterface,
272 : true,
273 : prototypes::id::CSSRule,
274 : PrototypeTraits<prototypes::id::CSSRule>::Depth,
275 : sNativePropertyHooks,
276 : "function CSSRule() {\n [native code]\n}",
277 : JS::GetRealmFunctionPrototype
278 : };
279 :
280 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
281 : {
282 : "CSSRulePrototype",
283 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
284 : JS_NULL_CLASS_OPS,
285 : JS_NULL_CLASS_SPEC,
286 : JS_NULL_CLASS_EXT,
287 : JS_NULL_OBJECT_OPS
288 : },
289 : eInterfacePrototype,
290 : false,
291 : prototypes::id::CSSRule,
292 : PrototypeTraits<prototypes::id::CSSRule>::Depth,
293 : sNativePropertyHooks,
294 : "[object CSSRulePrototype]",
295 : JS::GetRealmObjectPrototype
296 : };
297 :
298 : JSObject*
299 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
300 : {
301 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
302 : }
303 :
304 : const NativePropertyHooks sNativePropertyHooks[] = { {
305 : nullptr,
306 : nullptr,
307 : nullptr,
308 : { sNativeProperties.Upcast(), nullptr },
309 : prototypes::id::CSSRule,
310 : constructors::id::CSSRule,
311 : nullptr,
312 : &DefaultXrayExpandoObjectClass
313 : } };
314 :
315 : void
316 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
317 : {
318 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
319 0 : if (!parentProto) {
320 0 : return;
321 : }
322 :
323 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
324 0 : if (!constructorProto) {
325 0 : return;
326 : }
327 :
328 : static bool sIdsInited = false;
329 0 : if (!sIdsInited && NS_IsMainThread()) {
330 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
331 0 : return;
332 : }
333 0 : sIdsInited = true;
334 : }
335 :
336 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSRule);
337 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSRule);
338 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
339 : &sPrototypeClass.mBase, protoCache,
340 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
341 : interfaceCache,
342 : sNativeProperties.Upcast(),
343 : nullptr,
344 : "CSSRule", aDefineOnGlobal,
345 : nullptr,
346 0 : false);
347 : }
348 :
349 : JS::Handle<JSObject*>
350 0 : GetProtoObjectHandle(JSContext* aCx)
351 : {
352 : /* Get the interface prototype object for this class. This will create the
353 : object as needed. */
354 0 : bool aDefineOnGlobal = true;
355 :
356 : /* Make sure our global is sane. Hopefully we can remove this sometime */
357 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
358 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
359 0 : return nullptr;
360 : }
361 :
362 : /* Check to see whether the interface objects are already installed */
363 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
364 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CSSRule)) {
365 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
366 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
367 : }
368 :
369 : /*
370 : * The object might _still_ be null, but that's OK.
371 : *
372 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
373 : * traced by TraceProtoAndIfaceCache() and its contents are never
374 : * changed after they have been set.
375 : *
376 : * Calling address() avoids the read read barrier that does gray
377 : * unmarking, but it's not possible for the object to be gray here.
378 : */
379 :
380 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CSSRule);
381 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
382 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
383 : }
384 :
385 : JSObject*
386 0 : GetProtoObject(JSContext* aCx)
387 : {
388 0 : return GetProtoObjectHandle(aCx);
389 : }
390 :
391 : JS::Handle<JSObject*>
392 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
393 : {
394 : /* Get the interface object for this class. This will create the object as
395 : needed. */
396 :
397 : /* Make sure our global is sane. Hopefully we can remove this sometime */
398 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
399 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
400 0 : return nullptr;
401 : }
402 :
403 : /* Check to see whether the interface objects are already installed */
404 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
405 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CSSRule)) {
406 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
407 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
408 : }
409 :
410 : /*
411 : * The object might _still_ be null, but that's OK.
412 : *
413 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
414 : * traced by TraceProtoAndIfaceCache() and its contents are never
415 : * changed after they have been set.
416 : *
417 : * Calling address() avoids the read read barrier that does gray
418 : * unmarking, but it's not possible for the object to be gray here.
419 : */
420 :
421 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CSSRule);
422 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
423 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
424 : }
425 :
426 : JSObject*
427 0 : GetConstructorObject(JSContext* aCx)
428 : {
429 0 : return GetConstructorObjectHandle(aCx);
430 : }
431 :
432 : } // namespace CSSRuleBinding
433 :
434 :
435 :
436 : } // namespace dom
437 : } // namespace mozilla
|