/work/obj-fuzz/dom/bindings/StyleSheetListBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM StyleSheetList.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "StyleSheetListBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/StyleSheetInlines.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/DOMJSProxyHandler.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/Nullable.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/dom/StyleSheetList.h" |
14 | | #include "mozilla/dom/XrayExpandoClass.h" |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | |
19 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
20 | | using namespace mozilla::dom::binding_detail; |
21 | | |
22 | | |
23 | | namespace StyleSheetList_Binding { |
24 | | |
25 | | MOZ_CAN_RUN_SCRIPT static bool |
26 | | get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StyleSheetList* self, JSJitGetterCallArgs args) |
27 | 0 | { |
28 | 0 | AUTO_PROFILER_LABEL_FAST("get StyleSheetList.length", DOM, cx); |
29 | 0 |
|
30 | 0 | uint32_t result(self->Length()); |
31 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
32 | 0 | args.rval().setNumber(result); |
33 | 0 | return true; |
34 | 0 | } |
35 | | |
36 | | static const JSJitInfo length_getterinfo = { |
37 | | { (JSJitGetterOp)get_length }, |
38 | | { prototypes::id::StyleSheetList }, |
39 | | { PrototypeTraits<prototypes::id::StyleSheetList>::Depth }, |
40 | | JSJitInfo::Getter, |
41 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
42 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
43 | | true, /* isInfallible. False in setters. */ |
44 | | false, /* isMovable. Not relevant for setters. */ |
45 | | false, /* isEliminatable. Not relevant for setters. */ |
46 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
47 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
48 | | false, /* isTypedMethod. Only relevant for methods. */ |
49 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
50 | | }; |
51 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
52 | | static_assert(0 < 1, "There is no slot for us"); |
53 | | |
54 | | MOZ_CAN_RUN_SCRIPT static bool |
55 | | item(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StyleSheetList* self, const JSJitMethodCallArgs& args) |
56 | 0 | { |
57 | 0 | AUTO_PROFILER_LABEL_FAST("StyleSheetList.item", DOM, cx); |
58 | 0 |
|
59 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
60 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "StyleSheetList.item"); |
61 | 0 | } |
62 | 0 | uint32_t arg0; |
63 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
64 | 0 | return false; |
65 | 0 | } |
66 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->Item(arg0))); |
67 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
68 | 0 | if (!result) { |
69 | 0 | args.rval().setNull(); |
70 | 0 | return true; |
71 | 0 | } |
72 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
73 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
74 | 0 | return false; |
75 | 0 | } |
76 | 0 | return true; |
77 | 0 | } |
78 | | |
79 | | static const JSJitInfo item_methodinfo = { |
80 | | { (JSJitGetterOp)item }, |
81 | | { prototypes::id::StyleSheetList }, |
82 | | { PrototypeTraits<prototypes::id::StyleSheetList>::Depth }, |
83 | | JSJitInfo::Method, |
84 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
85 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
86 | | false, /* isInfallible. False in setters. */ |
87 | | false, /* isMovable. Not relevant for setters. */ |
88 | | false, /* isEliminatable. Not relevant for setters. */ |
89 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
90 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
91 | | false, /* isTypedMethod. Only relevant for methods. */ |
92 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
93 | | }; |
94 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
95 | | static_assert(0 < 1, "There is no slot for us"); |
96 | | |
97 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
98 | | #if defined(__clang__) |
99 | | #pragma clang diagnostic push |
100 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
101 | | #endif |
102 | | static const JSFunctionSpec sMethods_specs[] = { |
103 | | JS_FNSPEC("item", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
104 | | JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"), |
105 | | JS_FS_END |
106 | | }; |
107 | | #if defined(__clang__) |
108 | | #pragma clang diagnostic pop |
109 | | #endif |
110 | | |
111 | | |
112 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
113 | | { nullptr, &sMethods_specs[0] }, |
114 | | { nullptr, nullptr } |
115 | | }; |
116 | | |
117 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
118 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
119 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
120 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
121 | | |
122 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
123 | | #if defined(__clang__) |
124 | | #pragma clang diagnostic push |
125 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
126 | | #endif |
127 | | static const JSPropertySpec sAttributes_specs[] = { |
128 | | { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr }, |
129 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
130 | | }; |
131 | | #if defined(__clang__) |
132 | | #pragma clang diagnostic pop |
133 | | #endif |
134 | | |
135 | | |
136 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
137 | | { nullptr, &sAttributes_specs[0] }, |
138 | | { nullptr, nullptr } |
139 | | }; |
140 | | |
141 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
142 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
143 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
144 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
145 | | |
146 | | |
147 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
148 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
149 | | |
150 | | static const NativePropertiesN<2> sNativeProperties = { |
151 | | false, 0, |
152 | | false, 0, |
153 | | true, 0 /* sMethods */, |
154 | | true, 1 /* sAttributes */, |
155 | | false, 0, |
156 | | false, 0, |
157 | | false, 0, |
158 | | -1, |
159 | | 3, |
160 | | sNativeProperties_sortedPropertyIndices, |
161 | | { |
162 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
163 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
164 | | } |
165 | | }; |
166 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
167 | | "We have a property info count that is oversized"); |
168 | | |
169 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
170 | | { |
171 | | "Function", |
172 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
173 | | &sBoringInterfaceObjectClassClassOps, |
174 | | JS_NULL_CLASS_SPEC, |
175 | | JS_NULL_CLASS_EXT, |
176 | | &sInterfaceObjectClassObjectOps |
177 | | }, |
178 | | eInterface, |
179 | | true, |
180 | | prototypes::id::StyleSheetList, |
181 | | PrototypeTraits<prototypes::id::StyleSheetList>::Depth, |
182 | | sNativePropertyHooks, |
183 | | "function StyleSheetList() {\n [native code]\n}", |
184 | | JS::GetRealmFunctionPrototype |
185 | | }; |
186 | | |
187 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
188 | | { |
189 | | "StyleSheetListPrototype", |
190 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
191 | | JS_NULL_CLASS_OPS, |
192 | | JS_NULL_CLASS_SPEC, |
193 | | JS_NULL_CLASS_EXT, |
194 | | JS_NULL_OBJECT_OPS |
195 | | }, |
196 | | eInterfacePrototype, |
197 | | false, |
198 | | prototypes::id::StyleSheetList, |
199 | | PrototypeTraits<prototypes::id::StyleSheetList>::Depth, |
200 | | sNativePropertyHooks, |
201 | | "[object StyleSheetListPrototype]", |
202 | | JS::GetRealmObjectPrototype |
203 | | }; |
204 | | |
205 | | static_assert(IsBaseOf<nsISupports, mozilla::dom::StyleSheetList >::value, |
206 | | "We don't support non-nsISupports native classes for " |
207 | | "proxy-based bindings yet"); |
208 | | |
209 | | |
210 | | class DOMProxyHandler : public mozilla::dom::DOMProxyHandler |
211 | | { |
212 | | public: |
213 | | explicit constexpr DOMProxyHandler() |
214 | 0 | { |
215 | 0 | } |
216 | | |
217 | | virtual bool |
218 | | getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override; |
219 | | |
220 | | virtual bool |
221 | | defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override; |
222 | | |
223 | | using mozilla::dom::DOMProxyHandler::defineProperty; |
224 | | |
225 | | virtual bool |
226 | | ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override; |
227 | | |
228 | | virtual bool |
229 | | hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override; |
230 | | |
231 | | virtual bool |
232 | | get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override; |
233 | | |
234 | | virtual const char* |
235 | | className(JSContext* cx, JS::Handle<JSObject*> proxy) const override; |
236 | | |
237 | | virtual bool |
238 | | finalizeInBackground(const JS::Value& priv) const override; |
239 | | |
240 | | virtual void |
241 | | finalize(JSFreeOp* fop, JSObject* proxy) const override; |
242 | | |
243 | | static const DOMProxyHandler* |
244 | | getInstance(); |
245 | | |
246 | | virtual bool |
247 | | delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override; |
248 | | |
249 | | virtual bool |
250 | | getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override; |
251 | | |
252 | | virtual size_t |
253 | | objectMoved(JSObject* obj, JSObject* old) const override; |
254 | | }; |
255 | | |
256 | | MOZ_ALWAYS_INLINE bool |
257 | | IsProxy(JSObject* obj) |
258 | 0 | { |
259 | 0 | return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); |
260 | 0 | } |
261 | | |
262 | | MOZ_ALWAYS_INLINE mozilla::dom::StyleSheetList* |
263 | | UnwrapProxy(JSObject* obj) |
264 | 0 | { |
265 | 0 | MOZ_ASSERT(js::IsProxy(obj)); |
266 | 0 | if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { |
267 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); |
268 | 0 | obj = js::UncheckedUnwrap(obj); |
269 | 0 | } |
270 | 0 | MOZ_ASSERT(IsProxy(obj)); |
271 | 0 | return static_cast<mozilla::dom::StyleSheetList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); |
272 | 0 | } |
273 | | |
274 | | bool |
275 | | DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const |
276 | 0 | { |
277 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
278 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
279 | 0 | if (IsArrayIndex(index)) { |
280 | 0 | mozilla::dom::StyleSheetList* self = UnwrapProxy(proxy); |
281 | 0 | bool found = false; |
282 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->IndexedGetter(index, found))); |
283 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
284 | 0 |
|
285 | 0 | if (found) { |
286 | 0 | if (!result) { |
287 | 0 | desc.value().setNull(); |
288 | 0 | FillPropertyDescriptor(desc, proxy, true); |
289 | 0 | return true; |
290 | 0 | } |
291 | 0 | if (!GetOrCreateDOMReflector(cx, result, desc.value())) { |
292 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
293 | 0 | return false; |
294 | 0 | } |
295 | 0 | FillPropertyDescriptor(desc, proxy, true); |
296 | 0 | return true; |
297 | 0 | } |
298 | 0 | } |
299 | 0 |
|
300 | 0 | JS::Rooted<JSObject*> expando(cx); |
301 | 0 | if (!isXray && (expando = GetExpandoObject(proxy))) { |
302 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { |
303 | 0 | return false; |
304 | 0 | } |
305 | 0 | if (desc.object()) { |
306 | 0 | // Pretend the property lives on the wrapper. |
307 | 0 | desc.object().set(proxy); |
308 | 0 | return true; |
309 | 0 | } |
310 | 0 | } |
311 | 0 | |
312 | 0 | desc.object().set(nullptr); |
313 | 0 | return true; |
314 | 0 | } |
315 | | |
316 | | bool |
317 | | DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const |
318 | 0 | { |
319 | 0 | if (IsArrayIndex(GetArrayIndexFromId(cx, id))) { |
320 | 0 | *defined = true; |
321 | 0 | return opresult.failNoIndexedSetter(); |
322 | 0 | } |
323 | 0 | return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined); |
324 | 0 | } |
325 | | |
326 | | |
327 | | bool |
328 | | DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const |
329 | 0 | { |
330 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
331 | 0 |
|
332 | 0 | uint32_t length = UnwrapProxy(proxy)->Length(); |
333 | 0 | MOZ_ASSERT(int32_t(length) >= 0); |
334 | 0 | for (int32_t i = 0; i < int32_t(length); ++i) { |
335 | 0 | if (!props.append(INT_TO_JSID(i))) { |
336 | 0 | return false; |
337 | 0 | } |
338 | 0 | } |
339 | 0 |
|
340 | 0 | JS::Rooted<JSObject*> expando(cx); |
341 | 0 | if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) && |
342 | 0 | !js::GetPropertyKeys(cx, expando, flags, &props)) { |
343 | 0 | return false; |
344 | 0 | } |
345 | 0 | |
346 | 0 | return true; |
347 | 0 | } |
348 | | |
349 | | bool |
350 | | DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const |
351 | 0 | { |
352 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
353 | 0 | "Should not have a XrayWrapper here"); |
354 | 0 |
|
355 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
356 | 0 | if (IsArrayIndex(index)) { |
357 | 0 | bool found = false; |
358 | 0 | mozilla::dom::StyleSheetList* self = UnwrapProxy(proxy); |
359 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->IndexedGetter(index, found))); |
360 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
361 | 0 | (void)result; |
362 | 0 |
|
363 | 0 | *bp = found; |
364 | 0 | return true; |
365 | 0 | } |
366 | 0 |
|
367 | 0 |
|
368 | 0 | JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy)); |
369 | 0 | if (expando) { |
370 | 0 | bool b = true; |
371 | 0 | bool ok = JS_HasPropertyById(cx, expando, id, &b); |
372 | 0 | *bp = !!b; |
373 | 0 | if (!ok || *bp) { |
374 | 0 | return ok; |
375 | 0 | } |
376 | 0 | } |
377 | 0 | |
378 | 0 | *bp = false; |
379 | 0 | return true; |
380 | 0 | } |
381 | | |
382 | | bool |
383 | | DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const |
384 | 0 | { |
385 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
386 | 0 | "Should not have a XrayWrapper here"); |
387 | 0 |
|
388 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
389 | 0 | if (IsArrayIndex(index)) { |
390 | 0 | mozilla::dom::StyleSheetList* self = UnwrapProxy(proxy); |
391 | 0 | bool found = false; |
392 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->IndexedGetter(index, found))); |
393 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
394 | 0 |
|
395 | 0 | if (found) { |
396 | 0 | if (!result) { |
397 | 0 | vp.setNull(); |
398 | 0 | return true; |
399 | 0 | } |
400 | 0 | if (!GetOrCreateDOMReflector(cx, result, vp)) { |
401 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
402 | 0 | return false; |
403 | 0 | } |
404 | 0 | return true; |
405 | 0 | } |
406 | 0 | // Even if we don't have this index, we don't forward the |
407 | 0 | // get on to our expando object. |
408 | 0 | } else { |
409 | 0 | { // Scope for expando |
410 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
411 | 0 | if (expando) { |
412 | 0 | bool hasProp; |
413 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
414 | 0 | return false; |
415 | 0 | } |
416 | 0 | |
417 | 0 | if (hasProp) { |
418 | 0 | // Forward the get to the expando object, but our receiver is whatever our |
419 | 0 | // receiver is. |
420 | 0 | return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp); |
421 | 0 | } |
422 | 0 | } |
423 | 0 | } |
424 | 0 | } |
425 | 0 | |
426 | 0 | bool foundOnPrototype; |
427 | 0 | if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { |
428 | 0 | return false; |
429 | 0 | } |
430 | 0 | |
431 | 0 | if (foundOnPrototype) { |
432 | 0 | return true; |
433 | 0 | } |
434 | 0 | |
435 | 0 | vp.setUndefined(); |
436 | 0 | return true; |
437 | 0 | } |
438 | | |
439 | | const char* |
440 | | DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const |
441 | 0 | { |
442 | 0 | return "StyleSheetList"; |
443 | 0 | } |
444 | | |
445 | | bool |
446 | | DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const |
447 | 0 | { |
448 | 0 | return false; |
449 | 0 | } |
450 | | |
451 | | void |
452 | | DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const |
453 | 0 | { |
454 | 0 | mozilla::dom::StyleSheetList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StyleSheetList>(proxy); |
455 | 0 | if (self) { |
456 | 0 | ClearWrapper(self, self, proxy); |
457 | 0 | AddForDeferredFinalization<mozilla::dom::StyleSheetList>(self); |
458 | 0 | } |
459 | 0 | } |
460 | | |
461 | | const DOMProxyHandler* |
462 | | DOMProxyHandler::getInstance() |
463 | 0 | { |
464 | 0 | static const DOMProxyHandler instance; |
465 | 0 | return &instance; |
466 | 0 | } |
467 | | |
468 | | bool |
469 | | DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const |
470 | 0 | { |
471 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
472 | 0 | "Should not have a XrayWrapper here"); |
473 | 0 |
|
474 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
475 | 0 | if (IsArrayIndex(index)) { |
476 | 0 | bool deleteSucceeded; |
477 | 0 | bool found = false; |
478 | 0 | mozilla::dom::StyleSheetList* self = UnwrapProxy(proxy); |
479 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->IndexedGetter(index, found))); |
480 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
481 | 0 | (void)result; |
482 | 0 | deleteSucceeded = !found; |
483 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
484 | 0 | } |
485 | 0 |
|
486 | 0 | return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); |
487 | 0 | } |
488 | | |
489 | | bool |
490 | | DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const |
491 | 0 | { |
492 | 0 | JS::Rooted<JS::Value> temp(cx); |
493 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
494 | 0 | "Should not have a XrayWrapper here"); |
495 | 0 |
|
496 | 0 | mozilla::dom::StyleSheetList* self = UnwrapProxy(proxy); |
497 | 0 | uint32_t length = self->Length(); |
498 | 0 | // Compute the end of the indices we'll get ourselves |
499 | 0 | uint32_t ourEnd = std::max(begin, std::min(end, length)); |
500 | 0 |
|
501 | 0 | for (uint32_t index = begin; index < ourEnd; ++index) { |
502 | 0 | bool found = false; |
503 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->IndexedGetter(index, found))); |
504 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
505 | 0 |
|
506 | 0 | MOZ_ASSERT(found); |
507 | 0 | if (!result) { |
508 | 0 | temp.setNull(); |
509 | 0 | if (!adder->append(cx, temp)) return false; |
510 | 0 | continue; |
511 | 0 | } |
512 | 0 | if (!GetOrCreateDOMReflector(cx, result, &temp)) { |
513 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
514 | 0 | return false; |
515 | 0 | } |
516 | 0 | if (!adder->append(cx, temp)) return false; |
517 | 0 | continue; |
518 | 0 | } |
519 | 0 |
|
520 | 0 | if (end > ourEnd) { |
521 | 0 | JS::Rooted<JSObject*> proto(cx); |
522 | 0 | if (!js::GetObjectProto(cx, proxy, &proto)) { |
523 | 0 | return false; |
524 | 0 | } |
525 | 0 | return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder); |
526 | 0 | } |
527 | 0 | |
528 | 0 | return true; |
529 | 0 | } |
530 | | |
531 | | size_t |
532 | | DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const |
533 | 0 | { |
534 | 0 | mozilla::dom::StyleSheetList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StyleSheetList>(obj); |
535 | 0 | if (self) { |
536 | 0 | UpdateWrapper(self, self, obj, old); |
537 | 0 | } |
538 | 0 |
|
539 | 0 | return 0; |
540 | 0 | } |
541 | | |
542 | | static const DOMJSClass sClass = { |
543 | | PROXY_CLASS_DEF("StyleSheetList", |
544 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)), |
545 | | { prototypes::id::StyleSheetList, 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 }, |
546 | | IsBaseOf<nsISupports, mozilla::dom::StyleSheetList >::value, |
547 | | sNativePropertyHooks, |
548 | | FindAssociatedGlobalForNative<mozilla::dom::StyleSheetList>::Get, |
549 | | GetProtoObjectHandle, |
550 | | GetCCParticipant<mozilla::dom::StyleSheetList>::Get() |
551 | | }; |
552 | | |
553 | | bool |
554 | | Wrap(JSContext* aCx, mozilla::dom::StyleSheetList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
555 | 0 | { |
556 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::StyleSheetList>::value, |
557 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
558 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::StyleSheetList*>(aObject) == |
559 | 0 | reinterpret_cast<mozilla::dom::StyleSheetList*>(aObject), |
560 | 0 | "Multiple inheritance for mozilla::dom::StyleSheetList is broken."); |
561 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
562 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
563 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
564 | 0 | "You should probably not be using Wrap() directly; use " |
565 | 0 | "GetOrCreateDOMReflector instead"); |
566 | 0 |
|
567 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
568 | 0 | "nsISupports must be on our primary inheritance chain"); |
569 | 0 |
|
570 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
571 | 0 | if (!global) { |
572 | 0 | return false; |
573 | 0 | } |
574 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
575 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
576 | 0 |
|
577 | 0 | // That might have ended up wrapping us already, due to the wonders |
578 | 0 | // of XBL. Check for that, and bail out as needed. |
579 | 0 | aReflector.set(aCache->GetWrapper()); |
580 | 0 | if (aReflector) { |
581 | | #ifdef DEBUG |
582 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
583 | | #endif // DEBUG |
584 | | return true; |
585 | 0 | } |
586 | 0 |
|
587 | 0 | JSAutoRealm ar(aCx, global); |
588 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
589 | 0 | if (!canonicalProto) { |
590 | 0 | return false; |
591 | 0 | } |
592 | 0 | JS::Rooted<JSObject*> proto(aCx); |
593 | 0 | if (aGivenProto) { |
594 | 0 | proto = aGivenProto; |
595 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
596 | 0 | // coming in, we changed compartments to that of "parent" so may need |
597 | 0 | // to wrap the proto here. |
598 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
599 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
600 | 0 | return false; |
601 | 0 | } |
602 | 0 | } |
603 | 0 | } else { |
604 | 0 | proto = canonicalProto; |
605 | 0 | } |
606 | 0 |
|
607 | 0 | BindingJSObjectCreator<mozilla::dom::StyleSheetList> creator(aCx); |
608 | 0 | creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), |
609 | 0 | proto, aObject, JS::UndefinedHandleValue, aReflector); |
610 | 0 | if (!aReflector) { |
611 | 0 | return false; |
612 | 0 | } |
613 | 0 | |
614 | 0 | aCache->SetWrapper(aReflector); |
615 | 0 | creator.InitializationSucceeded(); |
616 | 0 |
|
617 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
618 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
619 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
620 | 0 | // otherwise we won't be able to properly recreate it later, since |
621 | 0 | // we won't know what proto to use. Note that we don't check |
622 | 0 | // aGivenProto here, since it's entirely possible (and even |
623 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
624 | 0 | // same as canonicalProto. |
625 | 0 | if (proto != canonicalProto) { |
626 | 0 | PreserveWrapper(aObject); |
627 | 0 | } |
628 | 0 |
|
629 | 0 | return true; |
630 | 0 | } |
631 | | |
632 | | static bool |
633 | | ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc) |
634 | 0 | { |
635 | 0 | return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc); |
636 | 0 | } |
637 | | |
638 | | static bool |
639 | | EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props) |
640 | 0 | { |
641 | 0 | return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props); |
642 | 0 | } |
643 | | |
644 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
645 | | ResolveOwnProperty, |
646 | | EnumerateOwnProperties, |
647 | | nullptr, |
648 | | { sNativeProperties.Upcast(), nullptr }, |
649 | | prototypes::id::StyleSheetList, |
650 | | constructors::id::StyleSheetList, |
651 | | nullptr, |
652 | | &DefaultXrayExpandoObjectClass |
653 | | } }; |
654 | | |
655 | | void |
656 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
657 | 0 | { |
658 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
659 | 0 | if (!parentProto) { |
660 | 0 | return; |
661 | 0 | } |
662 | 0 | |
663 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
664 | 0 | if (!constructorProto) { |
665 | 0 | return; |
666 | 0 | } |
667 | 0 | |
668 | 0 | static bool sIdsInited = false; |
669 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
670 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
671 | 0 | return; |
672 | 0 | } |
673 | 0 | sIdsInited = true; |
674 | 0 | } |
675 | 0 |
|
676 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::StyleSheetList); |
677 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::StyleSheetList); |
678 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
679 | 0 | &sPrototypeClass.mBase, protoCache, |
680 | 0 | nullptr, |
681 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
682 | 0 | interfaceCache, |
683 | 0 | sNativeProperties.Upcast(), |
684 | 0 | nullptr, |
685 | 0 | "StyleSheetList", aDefineOnGlobal, |
686 | 0 | nullptr, |
687 | 0 | false); |
688 | 0 | } |
689 | | |
690 | | JSObject* |
691 | | GetConstructorObject(JSContext* aCx) |
692 | 0 | { |
693 | 0 | return GetConstructorObjectHandle(aCx); |
694 | 0 | } |
695 | | |
696 | | } // namespace StyleSheetList_Binding |
697 | | |
698 | | |
699 | | |
700 | | } // namespace dom |
701 | | } // namespace mozilla |