Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM CSSPrimitiveValue.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "CSSPrimitiveValueBinding.h"
4 : #include "CSSValueBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/FloatingPoint.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/PrimitiveConversions.h"
12 : #include "mozilla/dom/XrayExpandoClass.h"
13 : #include "nsDOMCSSRGBColor.h"
14 : #include "nsDOMCSSRect.h"
15 : #include "nsIDOMCounter.h"
16 : #include "nsISupports.h"
17 : #include "nsROCSSPrimitiveValue.h"
18 : #include "xpcjsid.h"
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 : namespace CSSPrimitiveValueBinding {
24 :
25 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<CSSValueBinding::NativeType>::value,
26 : "Can't inherit from an interface with a different ownership model.");
27 :
28 : static bool
29 0 : get_primitiveType(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, JSJitGetterCallArgs args)
30 : {
31 0 : uint16_t result(self->PrimitiveType());
32 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
33 0 : args.rval().setInt32(int32_t(result));
34 0 : return true;
35 : }
36 :
37 : static const JSJitInfo primitiveType_getterinfo = {
38 : { (JSJitGetterOp)get_primitiveType },
39 : { prototypes::id::CSSPrimitiveValue },
40 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
41 : JSJitInfo::Getter,
42 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
43 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
44 : true, /* isInfallible. False in setters. */
45 : false, /* isMovable. Not relevant for setters. */
46 : false, /* isEliminatable. Not relevant for setters. */
47 : false, /* isAlwaysInSlot. Only relevant for getters. */
48 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
49 : false, /* isTypedMethod. Only relevant for methods. */
50 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
51 : };
52 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
53 : static_assert(0 < 1, "There is no slot for us");
54 :
55 : static bool
56 0 : setFloatValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
57 : {
58 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
59 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSPrimitiveValue.setFloatValue");
60 : }
61 : uint16_t arg0;
62 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) {
63 0 : return false;
64 : }
65 : float arg1;
66 0 : if (!ValueToPrimitive<float, eDefault>(cx, args[1], &arg1)) {
67 0 : return false;
68 0 : } else if (!mozilla::IsFinite(arg1)) {
69 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of CSSPrimitiveValue.setFloatValue");
70 0 : return false;
71 : }
72 0 : binding_detail::FastErrorResult rv;
73 0 : self->SetFloatValue(arg0, arg1, rv);
74 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
75 0 : return false;
76 : }
77 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
78 0 : args.rval().setUndefined();
79 0 : return true;
80 : }
81 :
82 : static const JSJitInfo setFloatValue_methodinfo = {
83 : { (JSJitGetterOp)setFloatValue },
84 : { prototypes::id::CSSPrimitiveValue },
85 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
86 : JSJitInfo::Method,
87 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
88 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
89 : false, /* isInfallible. False in setters. */
90 : false, /* isMovable. Not relevant for setters. */
91 : false, /* isEliminatable. Not relevant for setters. */
92 : false, /* isAlwaysInSlot. Only relevant for getters. */
93 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
94 : false, /* isTypedMethod. Only relevant for methods. */
95 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
96 : };
97 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
98 : static_assert(0 < 1, "There is no slot for us");
99 :
100 : static bool
101 0 : getFloatValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
102 : {
103 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
104 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSPrimitiveValue.getFloatValue");
105 : }
106 : uint16_t arg0;
107 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) {
108 0 : return false;
109 : }
110 0 : binding_detail::FastErrorResult rv;
111 0 : float result(self->GetFloatValue(arg0, rv));
112 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
113 0 : return false;
114 : }
115 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
116 0 : args.rval().set(JS_NumberValue(double(result)));
117 0 : return true;
118 : }
119 :
120 : static const JSJitInfo getFloatValue_methodinfo = {
121 : { (JSJitGetterOp)getFloatValue },
122 : { prototypes::id::CSSPrimitiveValue },
123 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
124 : JSJitInfo::Method,
125 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
126 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
127 : false, /* isInfallible. False in setters. */
128 : false, /* isMovable. Not relevant for setters. */
129 : false, /* isEliminatable. Not relevant for setters. */
130 : false, /* isAlwaysInSlot. Only relevant for getters. */
131 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
132 : false, /* isTypedMethod. Only relevant for methods. */
133 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
134 : };
135 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
136 : static_assert(0 < 1, "There is no slot for us");
137 :
138 : static bool
139 0 : setStringValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
140 : {
141 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
142 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSPrimitiveValue.setStringValue");
143 : }
144 : uint16_t arg0;
145 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) {
146 0 : return false;
147 : }
148 0 : binding_detail::FakeString arg1;
149 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
150 0 : return false;
151 : }
152 0 : binding_detail::FastErrorResult rv;
153 0 : self->SetStringValue(arg0, NonNullHelper(Constify(arg1)), rv);
154 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
155 0 : return false;
156 : }
157 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
158 0 : args.rval().setUndefined();
159 0 : return true;
160 : }
161 :
162 : static const JSJitInfo setStringValue_methodinfo = {
163 : { (JSJitGetterOp)setStringValue },
164 : { prototypes::id::CSSPrimitiveValue },
165 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
166 : JSJitInfo::Method,
167 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
168 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
169 : false, /* isInfallible. False in setters. */
170 : false, /* isMovable. Not relevant for setters. */
171 : false, /* isEliminatable. Not relevant for setters. */
172 : false, /* isAlwaysInSlot. Only relevant for getters. */
173 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
174 : false, /* isTypedMethod. Only relevant for methods. */
175 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
176 : };
177 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
178 : static_assert(0 < 1, "There is no slot for us");
179 :
180 : static bool
181 0 : getStringValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
182 : {
183 0 : binding_detail::FastErrorResult rv;
184 0 : DOMString result;
185 0 : self->GetStringValue(result, rv);
186 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
187 0 : return false;
188 : }
189 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
190 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
191 0 : return false;
192 : }
193 0 : return true;
194 : }
195 :
196 : static const JSJitInfo getStringValue_methodinfo = {
197 : { (JSJitGetterOp)getStringValue },
198 : { prototypes::id::CSSPrimitiveValue },
199 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
200 : JSJitInfo::Method,
201 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
202 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
203 : false, /* isInfallible. False in setters. */
204 : false, /* isMovable. Not relevant for setters. */
205 : false, /* isEliminatable. Not relevant for setters. */
206 : false, /* isAlwaysInSlot. Only relevant for getters. */
207 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
208 : false, /* isTypedMethod. Only relevant for methods. */
209 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
210 : };
211 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
212 : static_assert(0 < 1, "There is no slot for us");
213 :
214 : static bool
215 0 : getCounterValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
216 : {
217 0 : binding_detail::FastErrorResult rv;
218 0 : auto result(StrongOrRawPtr<nsIDOMCounter>(self->GetCounterValue(rv)));
219 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
220 0 : return false;
221 : }
222 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
223 0 : if (!WrapObject(cx, result, args.rval())) {
224 0 : return false;
225 : }
226 0 : return true;
227 : }
228 :
229 : static const JSJitInfo getCounterValue_methodinfo = {
230 : { (JSJitGetterOp)getCounterValue },
231 : { prototypes::id::CSSPrimitiveValue },
232 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
233 : JSJitInfo::Method,
234 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
235 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
236 : false, /* isInfallible. False in setters. */
237 : false, /* isMovable. Not relevant for setters. */
238 : false, /* isEliminatable. Not relevant for setters. */
239 : false, /* isAlwaysInSlot. Only relevant for getters. */
240 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
241 : false, /* isTypedMethod. Only relevant for methods. */
242 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
243 : };
244 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
245 : static_assert(0 < 1, "There is no slot for us");
246 :
247 : static bool
248 0 : getRectValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
249 : {
250 0 : binding_detail::FastErrorResult rv;
251 0 : auto result(StrongOrRawPtr<nsDOMCSSRect>(self->GetRectValue(rv)));
252 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
253 0 : return false;
254 : }
255 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
256 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
257 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
258 0 : return false;
259 : }
260 0 : return true;
261 : }
262 :
263 : static const JSJitInfo getRectValue_methodinfo = {
264 : { (JSJitGetterOp)getRectValue },
265 : { prototypes::id::CSSPrimitiveValue },
266 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
267 : JSJitInfo::Method,
268 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
269 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
270 : false, /* isInfallible. False in setters. */
271 : false, /* isMovable. Not relevant for setters. */
272 : false, /* isEliminatable. Not relevant for setters. */
273 : false, /* isAlwaysInSlot. Only relevant for getters. */
274 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
275 : false, /* isTypedMethod. Only relevant for methods. */
276 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
277 : };
278 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
279 : static_assert(0 < 1, "There is no slot for us");
280 :
281 : static bool
282 0 : getRGBColorValue(JSContext* cx, JS::Handle<JSObject*> obj, nsROCSSPrimitiveValue* self, const JSJitMethodCallArgs& args)
283 : {
284 0 : binding_detail::FastErrorResult rv;
285 0 : auto result(StrongOrRawPtr<nsDOMCSSRGBColor>(self->GetRGBColorValue(rv)));
286 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
287 0 : return false;
288 : }
289 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
290 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
291 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
292 0 : return false;
293 : }
294 0 : return true;
295 : }
296 :
297 : static const JSJitInfo getRGBColorValue_methodinfo = {
298 : { (JSJitGetterOp)getRGBColorValue },
299 : { prototypes::id::CSSPrimitiveValue },
300 : { PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth },
301 : JSJitInfo::Method,
302 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
303 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
304 : false, /* isInfallible. False in setters. */
305 : false, /* isMovable. Not relevant for setters. */
306 : false, /* isEliminatable. Not relevant for setters. */
307 : false, /* isAlwaysInSlot. Only relevant for getters. */
308 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
309 : false, /* isTypedMethod. Only relevant for methods. */
310 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
311 : };
312 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
313 : static_assert(0 < 1, "There is no slot for us");
314 :
315 : static bool
316 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
317 : {
318 0 : nsROCSSPrimitiveValue* self = UnwrapPossiblyNotInitializedDOMObject<nsROCSSPrimitiveValue>(obj);
319 : // We don't want to preserve if we don't have a wrapper, and we
320 : // obviously can't preserve if we're not initialized.
321 0 : if (self && self->GetWrapperPreserveColor()) {
322 0 : PreserveWrapper(self);
323 : }
324 0 : return true;
325 : }
326 :
327 : static void
328 0 : _finalize(js::FreeOp* fop, JSObject* obj)
329 : {
330 0 : nsROCSSPrimitiveValue* self = UnwrapPossiblyNotInitializedDOMObject<nsROCSSPrimitiveValue>(obj);
331 0 : if (self) {
332 0 : ClearWrapper(self, self, obj);
333 0 : AddForDeferredFinalization<nsROCSSPrimitiveValue>(self);
334 : }
335 0 : }
336 :
337 : static void
338 0 : _objectMoved(JSObject* obj, const JSObject* old)
339 : {
340 0 : nsROCSSPrimitiveValue* self = UnwrapPossiblyNotInitializedDOMObject<nsROCSSPrimitiveValue>(obj);
341 0 : if (self) {
342 0 : UpdateWrapper(self, self, obj, old);
343 : }
344 0 : }
345 :
346 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
347 : #if defined(__clang__)
348 : #pragma clang diagnostic push
349 : #pragma clang diagnostic ignored "-Wmissing-braces"
350 : #endif
351 : static const JSFunctionSpec sMethods_specs[] = {
352 : JS_FNSPEC("setFloatValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setFloatValue_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
353 : JS_FNSPEC("getFloatValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getFloatValue_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
354 : JS_FNSPEC("setStringValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setStringValue_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
355 : JS_FNSPEC("getStringValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getStringValue_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
356 : JS_FNSPEC("getCounterValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getCounterValue_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
357 : JS_FNSPEC("getRectValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getRectValue_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
358 : JS_FNSPEC("getRGBColorValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getRGBColorValue_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
359 : JS_FS_END,
360 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
361 : JS_FS_END
362 : };
363 : #if defined(__clang__)
364 : #pragma clang diagnostic pop
365 : #endif
366 :
367 : static PrefableDisablers sMethods_disablers8 = {
368 : true, false, 0, &WantsQueryInterface<nsROCSSPrimitiveValue>::Enabled
369 : };
370 :
371 : // Can't be const because the pref-enabled boolean needs to be writable
372 : static Prefable<const JSFunctionSpec> sMethods[] = {
373 : { nullptr, &sMethods_specs[0] },
374 : { &sMethods_disablers8, &sMethods_specs[8] },
375 : { nullptr, nullptr }
376 : };
377 :
378 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
379 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
380 : static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
381 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
382 :
383 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
384 : #if defined(__clang__)
385 : #pragma clang diagnostic push
386 : #pragma clang diagnostic ignored "-Wmissing-braces"
387 : #endif
388 : static const JSPropertySpec sAttributes_specs[] = {
389 : { "primitiveType", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &primitiveType_getterinfo, nullptr, nullptr },
390 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
391 : };
392 : #if defined(__clang__)
393 : #pragma clang diagnostic pop
394 : #endif
395 :
396 :
397 : // Can't be const because the pref-enabled boolean needs to be writable
398 : static Prefable<const JSPropertySpec> sAttributes[] = {
399 : { nullptr, &sAttributes_specs[0] },
400 : { nullptr, nullptr }
401 : };
402 :
403 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
404 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
405 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
406 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
407 :
408 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
409 : #if defined(__clang__)
410 : #pragma clang diagnostic push
411 : #pragma clang diagnostic ignored "-Wmissing-braces"
412 : #endif
413 : static const ConstantSpec sConstants_specs[] = {
414 : { "CSS_UNKNOWN", JS::Int32Value(0) },
415 : { "CSS_NUMBER", JS::Int32Value(1) },
416 : { "CSS_PERCENTAGE", JS::Int32Value(2) },
417 : { "CSS_EMS", JS::Int32Value(3) },
418 : { "CSS_EXS", JS::Int32Value(4) },
419 : { "CSS_PX", JS::Int32Value(5) },
420 : { "CSS_CM", JS::Int32Value(6) },
421 : { "CSS_MM", JS::Int32Value(7) },
422 : { "CSS_IN", JS::Int32Value(8) },
423 : { "CSS_PT", JS::Int32Value(9) },
424 : { "CSS_PC", JS::Int32Value(10) },
425 : { "CSS_DEG", JS::Int32Value(11) },
426 : { "CSS_RAD", JS::Int32Value(12) },
427 : { "CSS_GRAD", JS::Int32Value(13) },
428 : { "CSS_MS", JS::Int32Value(14) },
429 : { "CSS_S", JS::Int32Value(15) },
430 : { "CSS_HZ", JS::Int32Value(16) },
431 : { "CSS_KHZ", JS::Int32Value(17) },
432 : { "CSS_DIMENSION", JS::Int32Value(18) },
433 : { "CSS_STRING", JS::Int32Value(19) },
434 : { "CSS_URI", JS::Int32Value(20) },
435 : { "CSS_IDENT", JS::Int32Value(21) },
436 : { "CSS_ATTR", JS::Int32Value(22) },
437 : { "CSS_COUNTER", JS::Int32Value(23) },
438 : { "CSS_RECT", JS::Int32Value(24) },
439 : { "CSS_RGBCOLOR", JS::Int32Value(25) },
440 : { 0, JS::UndefinedValue() }
441 : };
442 : #if defined(__clang__)
443 : #pragma clang diagnostic pop
444 : #endif
445 :
446 :
447 : // Can't be const because the pref-enabled boolean needs to be writable
448 : static Prefable<const ConstantSpec> sConstants[] = {
449 : { nullptr, &sConstants_specs[0] },
450 : { nullptr, nullptr }
451 : };
452 :
453 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
454 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
455 : static_assert(26 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
456 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
457 :
458 :
459 : static uint16_t sNativeProperties_sortedPropertyIndices[35];
460 : static PropertyInfo sNativeProperties_propertyInfos[35];
461 :
462 : static const NativePropertiesN<3> sNativeProperties = {
463 : false, 0,
464 : false, 0,
465 : true, 0 /* sMethods */,
466 : true, 1 /* sAttributes */,
467 : false, 0,
468 : false, 0,
469 : true, 2 /* sConstants */,
470 : -1,
471 : 35,
472 : sNativeProperties_sortedPropertyIndices,
473 : {
474 : { sMethods, &sNativeProperties_propertyInfos[0] },
475 : { sAttributes, &sNativeProperties_propertyInfos[8] },
476 : { sConstants, &sNativeProperties_propertyInfos[9] }
477 : }
478 : };
479 : static_assert(35 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
480 : "We have a property info count that is oversized");
481 :
482 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
483 : {
484 : "Function",
485 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
486 : &sBoringInterfaceObjectClassClassOps,
487 : JS_NULL_CLASS_SPEC,
488 : JS_NULL_CLASS_EXT,
489 : &sInterfaceObjectClassObjectOps
490 : },
491 : eInterface,
492 : true,
493 : prototypes::id::CSSPrimitiveValue,
494 : PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth,
495 : sNativePropertyHooks,
496 : "function CSSPrimitiveValue() {\n [native code]\n}",
497 : CSSValueBinding::GetConstructorObject
498 : };
499 :
500 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
501 : {
502 : "CSSPrimitiveValuePrototype",
503 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
504 : JS_NULL_CLASS_OPS,
505 : JS_NULL_CLASS_SPEC,
506 : JS_NULL_CLASS_EXT,
507 : JS_NULL_OBJECT_OPS
508 : },
509 : eInterfacePrototype,
510 : false,
511 : prototypes::id::CSSPrimitiveValue,
512 : PrototypeTraits<prototypes::id::CSSPrimitiveValue>::Depth,
513 : sNativePropertyHooks,
514 : "[object CSSPrimitiveValuePrototype]",
515 : CSSValueBinding::GetProtoObject
516 : };
517 :
518 : JSObject*
519 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
520 : {
521 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
522 : }
523 :
524 : static const js::ClassOps sClassOps = {
525 : _addProperty, /* addProperty */
526 : nullptr, /* delProperty */
527 : nullptr, /* getProperty */
528 : nullptr, /* setProperty */
529 : nullptr, /* enumerate */
530 : nullptr, /* newEnumerate */
531 : nullptr, /* resolve */
532 : nullptr, /* mayResolve */
533 : _finalize, /* finalize */
534 : nullptr, /* call */
535 : nullptr, /* hasInstance */
536 : nullptr, /* construct */
537 : nullptr, /* trace */
538 : };
539 :
540 : static const js::ClassExtension sClassExtension = {
541 : nullptr, /* weakmapKeyDelegateOp */
542 : _objectMoved /* objectMovedOp */
543 : };
544 :
545 : static const DOMJSClass sClass = {
546 : { "CSSPrimitiveValue",
547 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
548 : &sClassOps,
549 : JS_NULL_CLASS_SPEC,
550 : &sClassExtension,
551 : JS_NULL_OBJECT_OPS
552 : },
553 : { prototypes::id::CSSValue, prototypes::id::CSSPrimitiveValue, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
554 : IsBaseOf<nsISupports, nsROCSSPrimitiveValue >::value,
555 : sNativePropertyHooks,
556 : FindAssociatedGlobalForNative<nsROCSSPrimitiveValue>::Get,
557 : GetProtoObjectHandle,
558 : GetCCParticipant<nsROCSSPrimitiveValue>::Get()
559 : };
560 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
561 : "Must have the right minimal number of reserved slots.");
562 : static_assert(1 >= 1,
563 : "Must have enough reserved slots.");
564 :
565 : const JSClass*
566 0 : GetJSClass()
567 : {
568 0 : return sClass.ToJSClass();
569 : }
570 :
571 : bool
572 0 : Wrap(JSContext* aCx, nsROCSSPrimitiveValue* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
573 : {
574 : MOZ_ASSERT(static_cast<nsROCSSPrimitiveValue*>(aObject) ==
575 : reinterpret_cast<nsROCSSPrimitiveValue*>(aObject),
576 : "Multiple inheritance for nsROCSSPrimitiveValue is broken.");
577 : MOZ_ASSERT(static_cast<mozilla::dom::CSSValue*>(aObject) ==
578 : reinterpret_cast<mozilla::dom::CSSValue*>(aObject),
579 : "Multiple inheritance for mozilla::dom::CSSValue is broken.");
580 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
581 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
582 0 : MOZ_ASSERT(!aCache->GetWrapper(),
583 : "You should probably not be using Wrap() directly; use "
584 : "GetOrCreateDOMReflector instead");
585 :
586 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
587 : "nsISupports must be on our primary inheritance chain");
588 :
589 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
590 0 : if (!global) {
591 0 : return false;
592 : }
593 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
594 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
595 :
596 : // That might have ended up wrapping us already, due to the wonders
597 : // of XBL. Check for that, and bail out as needed.
598 0 : aReflector.set(aCache->GetWrapper());
599 0 : if (aReflector) {
600 : #ifdef DEBUG
601 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
602 : #endif // DEBUG
603 0 : return true;
604 : }
605 :
606 0 : JSAutoCompartment ac(aCx, global);
607 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
608 0 : if (!canonicalProto) {
609 0 : return false;
610 : }
611 0 : JS::Rooted<JSObject*> proto(aCx);
612 0 : if (aGivenProto) {
613 0 : proto = aGivenProto;
614 : // Unfortunately, while aGivenProto was in the compartment of aCx
615 : // coming in, we changed compartments to that of "parent" so may need
616 : // to wrap the proto here.
617 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
618 0 : if (!JS_WrapObject(aCx, &proto)) {
619 0 : return false;
620 : }
621 : }
622 : } else {
623 0 : proto = canonicalProto;
624 : }
625 :
626 0 : BindingJSObjectCreator<nsROCSSPrimitiveValue> creator(aCx);
627 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
628 0 : if (!aReflector) {
629 0 : return false;
630 : }
631 :
632 0 : aCache->SetWrapper(aReflector);
633 0 : creator.InitializationSucceeded();
634 :
635 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
636 : aCache->GetWrapperPreserveColor() == aReflector);
637 : // If proto != canonicalProto, we have to preserve our wrapper;
638 : // otherwise we won't be able to properly recreate it later, since
639 : // we won't know what proto to use. Note that we don't check
640 : // aGivenProto here, since it's entirely possible (and even
641 : // somewhat common) to have a non-null aGivenProto which is the
642 : // same as canonicalProto.
643 0 : if (proto != canonicalProto) {
644 0 : PreserveWrapper(aObject);
645 : }
646 :
647 0 : return true;
648 : }
649 :
650 : const NativePropertyHooks sNativePropertyHooks[] = { {
651 : nullptr,
652 : nullptr,
653 : nullptr,
654 : { sNativeProperties.Upcast(), nullptr },
655 : prototypes::id::CSSPrimitiveValue,
656 : constructors::id::CSSPrimitiveValue,
657 : CSSValueBinding::sNativePropertyHooks,
658 : &DefaultXrayExpandoObjectClass
659 : } };
660 :
661 : void
662 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
663 : {
664 0 : JS::Handle<JSObject*> parentProto(CSSValueBinding::GetProtoObjectHandle(aCx));
665 0 : if (!parentProto) {
666 0 : return;
667 : }
668 :
669 0 : JS::Handle<JSObject*> constructorProto(CSSValueBinding::GetConstructorObjectHandle(aCx));
670 0 : if (!constructorProto) {
671 0 : return;
672 : }
673 :
674 : static bool sIdsInited = false;
675 0 : if (!sIdsInited && NS_IsMainThread()) {
676 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
677 0 : return;
678 : }
679 0 : sIdsInited = true;
680 : }
681 :
682 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSPrimitiveValue);
683 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSPrimitiveValue);
684 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
685 : &sPrototypeClass.mBase, protoCache,
686 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
687 : interfaceCache,
688 : sNativeProperties.Upcast(),
689 : nullptr,
690 : "CSSPrimitiveValue", aDefineOnGlobal,
691 : nullptr,
692 0 : false);
693 : }
694 :
695 : JS::Handle<JSObject*>
696 0 : GetProtoObjectHandle(JSContext* aCx)
697 : {
698 : /* Get the interface prototype object for this class. This will create the
699 : object as needed. */
700 0 : bool aDefineOnGlobal = true;
701 :
702 : /* Make sure our global is sane. Hopefully we can remove this sometime */
703 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
704 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
705 0 : return nullptr;
706 : }
707 :
708 : /* Check to see whether the interface objects are already installed */
709 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
710 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CSSPrimitiveValue)) {
711 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
712 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
713 : }
714 :
715 : /*
716 : * The object might _still_ be null, but that's OK.
717 : *
718 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
719 : * traced by TraceProtoAndIfaceCache() and its contents are never
720 : * changed after they have been set.
721 : *
722 : * Calling address() avoids the read read barrier that does gray
723 : * unmarking, but it's not possible for the object to be gray here.
724 : */
725 :
726 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CSSPrimitiveValue);
727 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
728 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
729 : }
730 :
731 : JS::Handle<JSObject*>
732 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
733 : {
734 : /* Get the interface object for this class. This will create the object as
735 : needed. */
736 :
737 : /* Make sure our global is sane. Hopefully we can remove this sometime */
738 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
739 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
740 0 : return nullptr;
741 : }
742 :
743 : /* Check to see whether the interface objects are already installed */
744 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
745 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CSSPrimitiveValue)) {
746 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
747 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
748 : }
749 :
750 : /*
751 : * The object might _still_ be null, but that's OK.
752 : *
753 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
754 : * traced by TraceProtoAndIfaceCache() and its contents are never
755 : * changed after they have been set.
756 : *
757 : * Calling address() avoids the read read barrier that does gray
758 : * unmarking, but it's not possible for the object to be gray here.
759 : */
760 :
761 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CSSPrimitiveValue);
762 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
763 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
764 : }
765 :
766 : JSObject*
767 0 : GetConstructorObject(JSContext* aCx)
768 : {
769 0 : return GetConstructorObjectHandle(aCx);
770 : }
771 :
772 : } // namespace CSSPrimitiveValueBinding
773 :
774 :
775 :
776 : } // namespace dom
777 : } // namespace mozilla
|