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