Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM CSSStyleDeclaration.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "CSSStyleDeclarationBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/css/Rule.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/CSSValue.h"
9 : #include "mozilla/dom/CustomElementRegistry.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/DOMJSProxyHandler.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 : #include "nsContentUtils.h"
17 : #include "nsICSSDeclaration.h"
18 : #include "nsISupports.h"
19 : #include "xpcjsid.h"
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 : namespace CSSStyleDeclarationBinding {
25 :
26 : static bool
27 0 : get_cssText(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, JSJitGetterCallArgs args)
28 : {
29 0 : DOMString result;
30 0 : self->GetCssText(result);
31 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
32 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
33 0 : return false;
34 : }
35 0 : return true;
36 : }
37 :
38 : static bool
39 0 : set_cssText(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, JSJitSetterCallArgs args)
40 : {
41 0 : binding_detail::FakeString arg0;
42 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
43 0 : return false;
44 : }
45 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
46 0 : Maybe<AutoCEReaction> ceReaction;
47 0 : if (reactionsStack) {
48 0 : ceReaction.emplace(reactionsStack);
49 : }
50 0 : binding_detail::FastErrorResult rv;
51 0 : self->SetCssText(NonNullHelper(Constify(arg0)), rv);
52 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
53 0 : return false;
54 : }
55 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
56 :
57 0 : return true;
58 : }
59 :
60 : static const JSJitInfo cssText_getterinfo = {
61 : { (JSJitGetterOp)get_cssText },
62 : { prototypes::id::CSSStyleDeclaration },
63 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
64 : JSJitInfo::Getter,
65 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
66 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
67 : false, /* isInfallible. False in setters. */
68 : false, /* isMovable. Not relevant for setters. */
69 : false, /* isEliminatable. Not relevant for setters. */
70 : false, /* isAlwaysInSlot. Only relevant for getters. */
71 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
72 : false, /* isTypedMethod. Only relevant for methods. */
73 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
74 : };
75 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
76 : static_assert(0 < 1, "There is no slot for us");
77 : static const JSJitInfo cssText_setterinfo = {
78 : { (JSJitGetterOp)set_cssText },
79 : { prototypes::id::CSSStyleDeclaration },
80 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
81 : JSJitInfo::Setter,
82 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
83 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
84 : false, /* isInfallible. False in setters. */
85 : false, /* isMovable. Not relevant for setters. */
86 : false, /* isEliminatable. Not relevant for setters. */
87 : false, /* isAlwaysInSlot. Only relevant for getters. */
88 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
89 : false, /* isTypedMethod. Only relevant for methods. */
90 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
91 : };
92 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
93 : static_assert(0 < 1, "There is no slot for us");
94 :
95 : static bool
96 0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, JSJitGetterCallArgs args)
97 : {
98 0 : uint32_t result(self->Length());
99 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
100 0 : args.rval().setNumber(result);
101 0 : return true;
102 : }
103 :
104 : static const JSJitInfo length_getterinfo = {
105 : { (JSJitGetterOp)get_length },
106 : { prototypes::id::CSSStyleDeclaration },
107 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
108 : JSJitInfo::Getter,
109 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
110 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
111 : true, /* isInfallible. False in setters. */
112 : false, /* isMovable. Not relevant for setters. */
113 : false, /* isEliminatable. Not relevant for setters. */
114 : false, /* isAlwaysInSlot. Only relevant for getters. */
115 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
116 : false, /* isTypedMethod. Only relevant for methods. */
117 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
118 : };
119 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
120 : static_assert(0 < 1, "There is no slot for us");
121 :
122 : static bool
123 0 : item(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
124 : {
125 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
126 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.item");
127 : }
128 : uint32_t arg0;
129 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
130 0 : return false;
131 : }
132 0 : DOMString result;
133 0 : self->Item(arg0, result);
134 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
135 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
136 0 : return false;
137 : }
138 0 : return true;
139 : }
140 :
141 : static const JSJitInfo item_methodinfo = {
142 : { (JSJitGetterOp)item },
143 : { prototypes::id::CSSStyleDeclaration },
144 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
145 : JSJitInfo::Method,
146 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
147 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
148 : false, /* isInfallible. False in setters. */
149 : false, /* isMovable. Not relevant for setters. */
150 : false, /* isEliminatable. Not relevant for setters. */
151 : false, /* isAlwaysInSlot. Only relevant for getters. */
152 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
153 : false, /* isTypedMethod. Only relevant for methods. */
154 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
155 : };
156 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
157 : static_assert(0 < 1, "There is no slot for us");
158 :
159 : static bool
160 0 : getPropertyValue(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
161 : {
162 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
163 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.getPropertyValue");
164 : }
165 0 : binding_detail::FakeString arg0;
166 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
167 0 : return false;
168 : }
169 0 : binding_detail::FastErrorResult rv;
170 0 : DOMString result;
171 0 : self->GetPropertyValue(NonNullHelper(Constify(arg0)), result, rv);
172 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
173 0 : return false;
174 : }
175 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
176 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
177 0 : return false;
178 : }
179 0 : return true;
180 : }
181 :
182 : static const JSJitInfo getPropertyValue_methodinfo = {
183 : { (JSJitGetterOp)getPropertyValue },
184 : { prototypes::id::CSSStyleDeclaration },
185 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
186 : JSJitInfo::Method,
187 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
188 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
189 : false, /* isInfallible. False in setters. */
190 : false, /* isMovable. Not relevant for setters. */
191 : false, /* isEliminatable. Not relevant for setters. */
192 : false, /* isAlwaysInSlot. Only relevant for getters. */
193 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
194 : false, /* isTypedMethod. Only relevant for methods. */
195 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
196 : };
197 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
198 : static_assert(0 < 1, "There is no slot for us");
199 :
200 : static bool
201 0 : getPropertyCSSValue(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
202 : {
203 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
204 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.getPropertyCSSValue");
205 : }
206 0 : binding_detail::FakeString arg0;
207 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
208 0 : return false;
209 : }
210 0 : binding_detail::FastErrorResult rv;
211 0 : auto result(StrongOrRawPtr<mozilla::dom::CSSValue>(self->GetPropertyCSSValue(NonNullHelper(Constify(arg0)), rv)));
212 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
213 0 : return false;
214 : }
215 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
216 0 : if (!result) {
217 0 : args.rval().setNull();
218 0 : return true;
219 : }
220 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
221 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
222 0 : return false;
223 : }
224 0 : return true;
225 : }
226 :
227 : static const JSJitInfo getPropertyCSSValue_methodinfo = {
228 : { (JSJitGetterOp)getPropertyCSSValue },
229 : { prototypes::id::CSSStyleDeclaration },
230 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
231 : JSJitInfo::Method,
232 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
233 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
234 : false, /* isInfallible. False in setters. */
235 : false, /* isMovable. Not relevant for setters. */
236 : false, /* isEliminatable. Not relevant for setters. */
237 : false, /* isAlwaysInSlot. Only relevant for getters. */
238 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
239 : false, /* isTypedMethod. Only relevant for methods. */
240 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
241 : };
242 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
243 : static_assert(0 < 1, "There is no slot for us");
244 :
245 : static bool
246 0 : getPropertyPriority(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
247 : {
248 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
249 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.getPropertyPriority");
250 : }
251 0 : binding_detail::FakeString arg0;
252 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
253 0 : return false;
254 : }
255 0 : DOMString result;
256 0 : self->GetPropertyPriority(NonNullHelper(Constify(arg0)), result);
257 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
258 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
259 0 : return false;
260 : }
261 0 : return true;
262 : }
263 :
264 : static const JSJitInfo getPropertyPriority_methodinfo = {
265 : { (JSJitGetterOp)getPropertyPriority },
266 : { prototypes::id::CSSStyleDeclaration },
267 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
268 : JSJitInfo::Method,
269 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
270 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
271 : false, /* isInfallible. False in setters. */
272 : false, /* isMovable. Not relevant for setters. */
273 : false, /* isEliminatable. Not relevant for setters. */
274 : false, /* isAlwaysInSlot. Only relevant for getters. */
275 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
276 : false, /* isTypedMethod. Only relevant for methods. */
277 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
278 : };
279 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
280 : static_assert(0 < 1, "There is no slot for us");
281 :
282 : static bool
283 0 : setProperty(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
284 : {
285 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
286 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.setProperty");
287 : }
288 0 : binding_detail::FakeString arg0;
289 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
290 0 : return false;
291 : }
292 0 : binding_detail::FakeString arg1;
293 0 : if (!ConvertJSValueToString(cx, args[1], eEmpty, eStringify, arg1)) {
294 0 : return false;
295 : }
296 0 : binding_detail::FakeString arg2;
297 0 : if (args.hasDefined(2)) {
298 0 : if (!ConvertJSValueToString(cx, args[2], eEmpty, eStringify, arg2)) {
299 0 : return false;
300 : }
301 : } else {
302 : static const char16_t data[] = { 0 };
303 0 : arg2.Rebind(data, ArrayLength(data) - 1);
304 : }
305 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
306 0 : Maybe<AutoCEReaction> ceReaction;
307 0 : if (reactionsStack) {
308 0 : ceReaction.emplace(reactionsStack);
309 : }
310 0 : binding_detail::FastErrorResult rv;
311 0 : self->SetProperty(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv);
312 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
313 0 : return false;
314 : }
315 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
316 0 : args.rval().setUndefined();
317 0 : return true;
318 : }
319 :
320 : static const JSJitInfo setProperty_methodinfo = {
321 : { (JSJitGetterOp)setProperty },
322 : { prototypes::id::CSSStyleDeclaration },
323 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
324 : JSJitInfo::Method,
325 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
326 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
327 : false, /* isInfallible. False in setters. */
328 : false, /* isMovable. Not relevant for setters. */
329 : false, /* isEliminatable. Not relevant for setters. */
330 : false, /* isAlwaysInSlot. Only relevant for getters. */
331 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
332 : false, /* isTypedMethod. Only relevant for methods. */
333 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
334 : };
335 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
336 : static_assert(0 < 1, "There is no slot for us");
337 :
338 : static bool
339 9 : removeProperty(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
340 : {
341 9 : if (MOZ_UNLIKELY(args.length() < 1)) {
342 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.removeProperty");
343 : }
344 18 : binding_detail::FakeString arg0;
345 9 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
346 0 : return false;
347 : }
348 9 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
349 18 : Maybe<AutoCEReaction> ceReaction;
350 9 : if (reactionsStack) {
351 9 : ceReaction.emplace(reactionsStack);
352 : }
353 18 : binding_detail::FastErrorResult rv;
354 18 : DOMString result;
355 9 : self->RemoveProperty(NonNullHelper(Constify(arg0)), result, rv);
356 9 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
357 0 : return false;
358 : }
359 9 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
360 9 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
361 0 : return false;
362 : }
363 9 : return true;
364 : }
365 :
366 : static const JSJitInfo removeProperty_methodinfo = {
367 : { (JSJitGetterOp)removeProperty },
368 : { prototypes::id::CSSStyleDeclaration },
369 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
370 : JSJitInfo::Method,
371 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
372 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
373 : false, /* isInfallible. False in setters. */
374 : false, /* isMovable. Not relevant for setters. */
375 : false, /* isEliminatable. Not relevant for setters. */
376 : false, /* isAlwaysInSlot. Only relevant for getters. */
377 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
378 : false, /* isTypedMethod. Only relevant for methods. */
379 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
380 : };
381 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
382 : static_assert(0 < 1, "There is no slot for us");
383 :
384 : static bool
385 0 : get_parentRule(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, JSJitGetterCallArgs args)
386 : {
387 0 : auto result(StrongOrRawPtr<mozilla::css::Rule>(self->GetParentRule()));
388 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
389 0 : if (!result) {
390 0 : args.rval().setNull();
391 0 : return true;
392 : }
393 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
394 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
395 0 : return false;
396 : }
397 0 : return true;
398 : }
399 :
400 : static const JSJitInfo parentRule_getterinfo = {
401 : { (JSJitGetterOp)get_parentRule },
402 : { prototypes::id::CSSStyleDeclaration },
403 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
404 : JSJitInfo::Getter,
405 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
406 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
407 : false, /* isInfallible. False in setters. */
408 : false, /* isMovable. Not relevant for setters. */
409 : false, /* isEliminatable. Not relevant for setters. */
410 : false, /* isAlwaysInSlot. Only relevant for getters. */
411 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
412 : false, /* isTypedMethod. Only relevant for methods. */
413 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
414 : };
415 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
416 : static_assert(0 < 1, "There is no slot for us");
417 :
418 : static bool
419 0 : getAuthoredPropertyValue(JSContext* cx, JS::Handle<JSObject*> obj, nsICSSDeclaration* self, const JSJitMethodCallArgs& args)
420 : {
421 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
422 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSStyleDeclaration.getAuthoredPropertyValue");
423 : }
424 0 : binding_detail::FakeString arg0;
425 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
426 0 : return false;
427 : }
428 0 : binding_detail::FastErrorResult rv;
429 0 : DOMString result;
430 0 : self->GetAuthoredPropertyValue(NonNullHelper(Constify(arg0)), result, rv);
431 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
432 0 : return false;
433 : }
434 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
435 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
436 0 : return false;
437 : }
438 0 : return true;
439 : }
440 :
441 : static const JSJitInfo getAuthoredPropertyValue_methodinfo = {
442 : { (JSJitGetterOp)getAuthoredPropertyValue },
443 : { prototypes::id::CSSStyleDeclaration },
444 : { PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth },
445 : JSJitInfo::Method,
446 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
447 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
448 : false, /* isInfallible. False in setters. */
449 : false, /* isMovable. Not relevant for setters. */
450 : false, /* isEliminatable. Not relevant for setters. */
451 : false, /* isAlwaysInSlot. Only relevant for getters. */
452 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
453 : false, /* isTypedMethod. Only relevant for methods. */
454 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
455 : };
456 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
457 : static_assert(0 < 1, "There is no slot for us");
458 :
459 : static void
460 0 : _objectMoved(JSObject* obj, const JSObject* old)
461 : {
462 0 : nsICSSDeclaration* self = UnwrapPossiblyNotInitializedDOMObject<nsICSSDeclaration>(obj);
463 0 : if (self) {
464 0 : UpdateWrapper(self, self, obj, old);
465 : }
466 0 : }
467 :
468 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
469 : #if defined(__clang__)
470 : #pragma clang diagnostic push
471 : #pragma clang diagnostic ignored "-Wmissing-braces"
472 : #endif
473 : static const JSFunctionSpec sMethods_specs[] = {
474 : JS_FNSPEC("item", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
475 : JS_FNSPEC("getPropertyValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getPropertyValue_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
476 : JS_FNSPEC("getPropertyCSSValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getPropertyCSSValue_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
477 : JS_FNSPEC("getPropertyPriority", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getPropertyPriority_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
478 : JS_FNSPEC("setProperty", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setProperty_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
479 : JS_FNSPEC("removeProperty", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&removeProperty_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
480 : JS_FS_END,
481 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
482 : JS_FS_END,
483 : JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
484 : JS_FS_END
485 : };
486 : #if defined(__clang__)
487 : #pragma clang diagnostic pop
488 : #endif
489 :
490 : static PrefableDisablers sMethods_disablers7 = {
491 : true, false, 0, &WantsQueryInterface<nsICSSDeclaration>::Enabled
492 : };
493 :
494 : // Can't be const because the pref-enabled boolean needs to be writable
495 : static Prefable<const JSFunctionSpec> sMethods[] = {
496 : { nullptr, &sMethods_specs[0] },
497 : { &sMethods_disablers7, &sMethods_specs[7] },
498 : { nullptr, &sMethods_specs[9] },
499 : { nullptr, nullptr }
500 : };
501 :
502 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
503 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
504 : static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
505 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
506 :
507 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
508 : #if defined(__clang__)
509 : #pragma clang diagnostic push
510 : #pragma clang diagnostic ignored "-Wmissing-braces"
511 : #endif
512 : static const JSFunctionSpec sChromeMethods_specs[] = {
513 : JS_FNSPEC("getAuthoredPropertyValue", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getAuthoredPropertyValue_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
514 : JS_FS_END
515 : };
516 : #if defined(__clang__)
517 : #pragma clang diagnostic pop
518 : #endif
519 :
520 :
521 : // Can't be const because the pref-enabled boolean needs to be writable
522 : static Prefable<const JSFunctionSpec> sChromeMethods[] = {
523 : { nullptr, &sChromeMethods_specs[0] },
524 : { nullptr, nullptr }
525 : };
526 :
527 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
528 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
529 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
530 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
531 :
532 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
533 : #if defined(__clang__)
534 : #pragma clang diagnostic push
535 : #pragma clang diagnostic ignored "-Wmissing-braces"
536 : #endif
537 : static const JSPropertySpec sAttributes_specs[] = {
538 : { "cssText", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &cssText_getterinfo, GenericBindingSetter, &cssText_setterinfo },
539 : { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
540 : { "parentRule", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &parentRule_getterinfo, nullptr, nullptr },
541 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
542 : };
543 : #if defined(__clang__)
544 : #pragma clang diagnostic pop
545 : #endif
546 :
547 :
548 : // Can't be const because the pref-enabled boolean needs to be writable
549 : static Prefable<const JSPropertySpec> sAttributes[] = {
550 : { nullptr, &sAttributes_specs[0] },
551 : { nullptr, nullptr }
552 : };
553 :
554 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
555 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
556 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
557 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
558 :
559 :
560 : static uint16_t sNativeProperties_sortedPropertyIndices[11];
561 : static PropertyInfo sNativeProperties_propertyInfos[11];
562 :
563 : static const NativePropertiesN<2> sNativeProperties = {
564 : false, 0,
565 : false, 0,
566 : true, 0 /* sMethods */,
567 : true, 1 /* sAttributes */,
568 : false, 0,
569 : false, 0,
570 : false, 0,
571 : -1,
572 : 11,
573 : sNativeProperties_sortedPropertyIndices,
574 : {
575 : { sMethods, &sNativeProperties_propertyInfos[0] },
576 : { sAttributes, &sNativeProperties_propertyInfos[8] }
577 : }
578 : };
579 : static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
580 : "We have a property info count that is oversized");
581 :
582 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
583 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
584 :
585 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
586 : false, 0,
587 : false, 0,
588 : true, 0 /* sChromeMethods */,
589 : false, 0,
590 : false, 0,
591 : false, 0,
592 : false, 0,
593 : -1,
594 : 1,
595 : sChromeOnlyNativeProperties_sortedPropertyIndices,
596 : {
597 : { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
598 : }
599 : };
600 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
601 : "We have a property info count that is oversized");
602 :
603 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
604 : {
605 : "Function",
606 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
607 : &sBoringInterfaceObjectClassClassOps,
608 : JS_NULL_CLASS_SPEC,
609 : JS_NULL_CLASS_EXT,
610 : &sInterfaceObjectClassObjectOps
611 : },
612 : eInterface,
613 : true,
614 : prototypes::id::CSSStyleDeclaration,
615 : PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth,
616 : sNativePropertyHooks,
617 : "function CSSStyleDeclaration() {\n [native code]\n}",
618 : JS::GetRealmFunctionPrototype
619 : };
620 :
621 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
622 : {
623 : "CSSStyleDeclarationPrototype",
624 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
625 : JS_NULL_CLASS_OPS,
626 : JS_NULL_CLASS_SPEC,
627 : JS_NULL_CLASS_EXT,
628 : JS_NULL_OBJECT_OPS
629 : },
630 : eInterfacePrototype,
631 : false,
632 : prototypes::id::CSSStyleDeclaration,
633 : PrototypeTraits<prototypes::id::CSSStyleDeclaration>::Depth,
634 : sNativePropertyHooks,
635 : "[object CSSStyleDeclarationPrototype]",
636 : JS::GetRealmObjectPrototype
637 : };
638 :
639 : JSObject*
640 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
641 : {
642 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
643 : }
644 :
645 : static_assert(IsBaseOf<nsISupports, nsICSSDeclaration >::value,
646 : "We don't support non-nsISupports native classes for "
647 : "proxy-based bindings yet");
648 :
649 :
650 : class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
651 : {
652 : public:
653 : explicit constexpr DOMProxyHandler()
654 : {
655 : }
656 :
657 : virtual bool
658 : getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
659 :
660 : virtual bool
661 : defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
662 :
663 : using mozilla::dom::DOMProxyHandler::defineProperty;
664 :
665 : virtual bool
666 : ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
667 :
668 : virtual bool
669 : hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
670 :
671 : virtual bool
672 : get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
673 :
674 : virtual const char*
675 : className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
676 :
677 : virtual bool
678 : finalizeInBackground(const JS::Value& priv) const override;
679 :
680 : virtual void
681 : finalize(JSFreeOp* fop, JSObject* proxy) const override;
682 :
683 : static const DOMProxyHandler*
684 : getInstance();
685 :
686 : virtual bool
687 : delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
688 :
689 : virtual bool
690 : getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
691 : };
692 :
693 : MOZ_ALWAYS_INLINE bool
694 0 : IsProxy(JSObject* obj)
695 : {
696 0 : return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
697 : }
698 :
699 : MOZ_ALWAYS_INLINE nsICSSDeclaration*
700 0 : UnwrapProxy(JSObject* obj)
701 : {
702 0 : MOZ_ASSERT(js::IsProxy(obj));
703 0 : if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
704 0 : MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
705 0 : obj = js::UncheckedUnwrap(obj);
706 : }
707 0 : MOZ_ASSERT(IsProxy(obj));
708 0 : return static_cast<nsICSSDeclaration*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
709 : }
710 :
711 : bool
712 0 : DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
713 : {
714 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
715 0 : uint32_t index = GetArrayIndexFromId(cx, id);
716 0 : if (IsArrayIndex(index)) {
717 0 : nsICSSDeclaration* self = UnwrapProxy(proxy);
718 0 : bool found = false;
719 0 : DOMString result;
720 0 : self->IndexedGetter(index, found, result);
721 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
722 :
723 0 : if (found) {
724 0 : if (!xpc::NonVoidStringToJsval(cx, result, desc.value())) {
725 0 : return false;
726 : }
727 0 : FillPropertyDescriptor(desc, proxy, true);
728 0 : return true;
729 : }
730 : }
731 :
732 0 : JS::Rooted<JSObject*> expando(cx);
733 0 : if (!isXray && (expando = GetExpandoObject(proxy))) {
734 0 : if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
735 0 : return false;
736 : }
737 0 : if (desc.object()) {
738 : // Pretend the property lives on the wrapper.
739 0 : desc.object().set(proxy);
740 0 : return true;
741 : }
742 : }
743 :
744 0 : desc.object().set(nullptr);
745 0 : return true;
746 : }
747 :
748 : bool
749 0 : DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
750 : {
751 0 : if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
752 0 : *defined = true;
753 0 : return opresult.failNoIndexedSetter();
754 : }
755 0 : return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
756 : }
757 :
758 :
759 : bool
760 0 : DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
761 : {
762 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
763 :
764 0 : uint32_t length = UnwrapProxy(proxy)->Length();
765 0 : MOZ_ASSERT(int32_t(length) >= 0);
766 0 : for (int32_t i = 0; i < int32_t(length); ++i) {
767 0 : if (!props.append(INT_TO_JSID(i))) {
768 0 : return false;
769 : }
770 : }
771 :
772 0 : JS::Rooted<JSObject*> expando(cx);
773 0 : if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
774 0 : !js::GetPropertyKeys(cx, expando, flags, &props)) {
775 0 : return false;
776 : }
777 :
778 0 : return true;
779 : }
780 :
781 : bool
782 0 : DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
783 : {
784 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
785 : "Should not have a XrayWrapper here");
786 :
787 0 : uint32_t index = GetArrayIndexFromId(cx, id);
788 0 : if (IsArrayIndex(index)) {
789 0 : bool found = false;
790 0 : nsICSSDeclaration* self = UnwrapProxy(proxy);
791 0 : DOMString result;
792 0 : self->IndexedGetter(index, found, result);
793 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
794 : (void)result;
795 :
796 0 : *bp = found;
797 0 : return true;
798 : }
799 :
800 :
801 0 : JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
802 0 : if (expando) {
803 0 : bool b = true;
804 0 : bool ok = JS_HasPropertyById(cx, expando, id, &b);
805 0 : *bp = !!b;
806 0 : if (!ok || *bp) {
807 0 : return ok;
808 : }
809 : }
810 :
811 0 : *bp = false;
812 0 : return true;
813 : }
814 :
815 : bool
816 0 : DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
817 : {
818 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
819 : "Should not have a XrayWrapper here");
820 :
821 0 : uint32_t index = GetArrayIndexFromId(cx, id);
822 0 : if (IsArrayIndex(index)) {
823 0 : nsICSSDeclaration* self = UnwrapProxy(proxy);
824 0 : bool found = false;
825 0 : DOMString result;
826 0 : self->IndexedGetter(index, found, result);
827 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
828 :
829 0 : if (found) {
830 0 : if (!xpc::NonVoidStringToJsval(cx, result, vp)) {
831 0 : return false;
832 : }
833 0 : return true;
834 : }
835 : // Even if we don't have this index, we don't forward the
836 : // get on to our expando object.
837 : } else {
838 : { // Scope for expando
839 0 : JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
840 0 : if (expando) {
841 : bool hasProp;
842 0 : if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
843 0 : return false;
844 : }
845 :
846 0 : if (hasProp) {
847 : // Forward the get to the expando object, but our receiver is whatever our
848 : // receiver is.
849 0 : return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
850 : }
851 : }
852 : }
853 : }
854 :
855 : bool foundOnPrototype;
856 0 : if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
857 0 : return false;
858 : }
859 :
860 0 : if (foundOnPrototype) {
861 0 : return true;
862 : }
863 :
864 0 : vp.setUndefined();
865 0 : return true;
866 : }
867 :
868 : const char*
869 0 : DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
870 : {
871 0 : return "CSSStyleDeclaration";
872 : }
873 :
874 : bool
875 0 : DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
876 : {
877 0 : return false;
878 : }
879 :
880 : void
881 0 : DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
882 : {
883 0 : nsICSSDeclaration* self = UnwrapPossiblyNotInitializedDOMObject<nsICSSDeclaration>(proxy);
884 0 : if (self) {
885 0 : ClearWrapper(self, self, proxy);
886 0 : AddForDeferredFinalization<nsICSSDeclaration>(self);
887 : }
888 0 : }
889 :
890 : const DOMProxyHandler*
891 0 : DOMProxyHandler::getInstance()
892 : {
893 : static const DOMProxyHandler instance;
894 0 : return &instance;
895 : }
896 :
897 : bool
898 0 : DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
899 : {
900 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
901 : "Should not have a XrayWrapper here");
902 :
903 0 : uint32_t index = GetArrayIndexFromId(cx, id);
904 0 : if (IsArrayIndex(index)) {
905 : bool deleteSucceeded;
906 0 : bool found = false;
907 0 : nsICSSDeclaration* self = UnwrapProxy(proxy);
908 0 : DOMString result;
909 0 : self->IndexedGetter(index, found, result);
910 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
911 : (void)result;
912 0 : deleteSucceeded = !found;
913 0 : return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
914 : }
915 :
916 0 : return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
917 : }
918 :
919 : bool
920 0 : DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
921 : {
922 0 : JS::Rooted<JS::Value> temp(cx);
923 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
924 : "Should not have a XrayWrapper here");
925 :
926 0 : nsICSSDeclaration* self = UnwrapProxy(proxy);
927 0 : uint32_t length = self->Length();
928 : // Compute the end of the indices we'll get ourselves
929 0 : uint32_t ourEnd = std::max(begin, std::min(end, length));
930 :
931 0 : for (uint32_t index = begin; index < ourEnd; ++index) {
932 0 : bool found = false;
933 0 : DOMString result;
934 0 : self->IndexedGetter(index, found, result);
935 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
936 :
937 0 : MOZ_ASSERT(found);
938 0 : if (!xpc::NonVoidStringToJsval(cx, result, &temp)) {
939 0 : return false;
940 : }
941 0 : if (!adder->append(cx, temp)) return false;
942 0 : continue;
943 : }
944 :
945 0 : if (end > ourEnd) {
946 0 : JS::Rooted<JSObject*> proto(cx);
947 0 : if (!js::GetObjectProto(cx, proxy, &proto)) {
948 0 : return false;
949 : }
950 0 : return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
951 : }
952 :
953 0 : return true;
954 : }
955 :
956 : static const js::ClassExtension sClassExtension = PROXY_MAKE_EXT(
957 : _objectMoved
958 : );
959 :
960 : static const DOMJSClass sClass = {
961 : PROXY_CLASS_WITH_EXT("CSSStyleDeclaration",
962 : JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
963 : &sClassExtension),
964 : { prototypes::id::CSSStyleDeclaration, 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 },
965 : IsBaseOf<nsISupports, nsICSSDeclaration >::value,
966 : sNativePropertyHooks,
967 : FindAssociatedGlobalForNative<nsICSSDeclaration>::Get,
968 : GetProtoObjectHandle,
969 : GetCCParticipant<nsICSSDeclaration>::Get()
970 : };
971 :
972 : bool
973 0 : Wrap(JSContext* aCx, nsICSSDeclaration* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
974 : {
975 : MOZ_ASSERT(static_cast<nsICSSDeclaration*>(aObject) ==
976 : reinterpret_cast<nsICSSDeclaration*>(aObject),
977 : "Multiple inheritance for nsICSSDeclaration is broken.");
978 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
979 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
980 0 : MOZ_ASSERT(!aCache->GetWrapper(),
981 : "You should probably not be using Wrap() directly; use "
982 : "GetOrCreateDOMReflector instead");
983 :
984 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
985 : "nsISupports must be on our primary inheritance chain");
986 :
987 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
988 0 : if (!global) {
989 0 : return false;
990 : }
991 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
992 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
993 :
994 : // That might have ended up wrapping us already, due to the wonders
995 : // of XBL. Check for that, and bail out as needed.
996 0 : aReflector.set(aCache->GetWrapper());
997 0 : if (aReflector) {
998 : #ifdef DEBUG
999 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1000 : #endif // DEBUG
1001 0 : return true;
1002 : }
1003 :
1004 0 : JSAutoCompartment ac(aCx, global);
1005 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1006 0 : if (!canonicalProto) {
1007 0 : return false;
1008 : }
1009 0 : JS::Rooted<JSObject*> proto(aCx);
1010 0 : if (aGivenProto) {
1011 0 : proto = aGivenProto;
1012 : // Unfortunately, while aGivenProto was in the compartment of aCx
1013 : // coming in, we changed compartments to that of "parent" so may need
1014 : // to wrap the proto here.
1015 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1016 0 : if (!JS_WrapObject(aCx, &proto)) {
1017 0 : return false;
1018 : }
1019 : }
1020 : } else {
1021 0 : proto = canonicalProto;
1022 : }
1023 :
1024 0 : BindingJSObjectCreator<nsICSSDeclaration> creator(aCx);
1025 0 : JS::Rooted<JS::Value> expandoValue(aCx, JS::UndefinedValue());
1026 0 : creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
1027 0 : proto, aObject, expandoValue, aReflector);
1028 0 : if (!aReflector) {
1029 0 : return false;
1030 : }
1031 :
1032 :
1033 0 : aCache->SetWrapper(aReflector);
1034 0 : creator.InitializationSucceeded();
1035 :
1036 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1037 : aCache->GetWrapperPreserveColor() == aReflector);
1038 : // If proto != canonicalProto, we have to preserve our wrapper;
1039 : // otherwise we won't be able to properly recreate it later, since
1040 : // we won't know what proto to use. Note that we don't check
1041 : // aGivenProto here, since it's entirely possible (and even
1042 : // somewhat common) to have a non-null aGivenProto which is the
1043 : // same as canonicalProto.
1044 0 : if (proto != canonicalProto) {
1045 0 : PreserveWrapper(aObject);
1046 : }
1047 :
1048 0 : return true;
1049 : }
1050 :
1051 : static bool
1052 0 : ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
1053 : {
1054 0 : return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
1055 : }
1056 :
1057 : static bool
1058 0 : EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
1059 : {
1060 0 : return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
1061 : }
1062 :
1063 : const NativePropertyHooks sNativePropertyHooks[] = { {
1064 : ResolveOwnProperty,
1065 : EnumerateOwnProperties,
1066 : nullptr,
1067 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1068 : prototypes::id::CSSStyleDeclaration,
1069 : constructors::id::CSSStyleDeclaration,
1070 : nullptr,
1071 : &DefaultXrayExpandoObjectClass
1072 : } };
1073 :
1074 : void
1075 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1076 : {
1077 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1078 1 : if (!parentProto) {
1079 0 : return;
1080 : }
1081 :
1082 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1083 1 : if (!constructorProto) {
1084 0 : return;
1085 : }
1086 :
1087 : static bool sIdsInited = false;
1088 1 : if (!sIdsInited && NS_IsMainThread()) {
1089 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1090 0 : return;
1091 : }
1092 1 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1093 0 : return;
1094 : }
1095 1 : sIdsInited = true;
1096 : }
1097 :
1098 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSStyleDeclaration);
1099 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSStyleDeclaration);
1100 3 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1101 : &sPrototypeClass.mBase, protoCache,
1102 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1103 : interfaceCache,
1104 : sNativeProperties.Upcast(),
1105 1 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
1106 : "CSSStyleDeclaration", aDefineOnGlobal,
1107 : nullptr,
1108 1 : false);
1109 : }
1110 :
1111 : JS::Handle<JSObject*>
1112 1 : GetProtoObjectHandle(JSContext* aCx)
1113 : {
1114 : /* Get the interface prototype object for this class. This will create the
1115 : object as needed. */
1116 1 : bool aDefineOnGlobal = true;
1117 :
1118 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1119 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1120 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1121 0 : return nullptr;
1122 : }
1123 :
1124 : /* Check to see whether the interface objects are already installed */
1125 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1126 1 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CSSStyleDeclaration)) {
1127 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1128 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1129 : }
1130 :
1131 : /*
1132 : * The object might _still_ be null, but that's OK.
1133 : *
1134 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1135 : * traced by TraceProtoAndIfaceCache() and its contents are never
1136 : * changed after they have been set.
1137 : *
1138 : * Calling address() avoids the read read barrier that does gray
1139 : * unmarking, but it's not possible for the object to be gray here.
1140 : */
1141 :
1142 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CSSStyleDeclaration);
1143 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1144 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1145 : }
1146 :
1147 : JSObject*
1148 0 : GetProtoObject(JSContext* aCx)
1149 : {
1150 0 : return GetProtoObjectHandle(aCx);
1151 : }
1152 :
1153 : JS::Handle<JSObject*>
1154 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1155 : {
1156 : /* Get the interface object for this class. This will create the object as
1157 : needed. */
1158 :
1159 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1160 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1161 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1162 0 : return nullptr;
1163 : }
1164 :
1165 : /* Check to see whether the interface objects are already installed */
1166 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1167 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CSSStyleDeclaration)) {
1168 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1169 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1170 : }
1171 :
1172 : /*
1173 : * The object might _still_ be null, but that's OK.
1174 : *
1175 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1176 : * traced by TraceProtoAndIfaceCache() and its contents are never
1177 : * changed after they have been set.
1178 : *
1179 : * Calling address() avoids the read read barrier that does gray
1180 : * unmarking, but it's not possible for the object to be gray here.
1181 : */
1182 :
1183 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CSSStyleDeclaration);
1184 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1185 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1186 : }
1187 :
1188 : JSObject*
1189 0 : GetConstructorObject(JSContext* aCx)
1190 : {
1191 0 : return GetConstructorObjectHandle(aCx);
1192 : }
1193 :
1194 : } // namespace CSSStyleDeclarationBinding
1195 :
1196 :
1197 :
1198 : } // namespace dom
1199 : } // namespace mozilla
|