/work/obj-fuzz/dom/bindings/StyleRuleChangeEventBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM StyleRuleChangeEvent.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventBinding.h" |
5 | | #include "StyleRuleChangeEventBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/StyleSheet.h" |
9 | | #include "mozilla/css/Rule.h" |
10 | | #include "mozilla/dom/BindingUtils.h" |
11 | | #include "mozilla/dom/DOMJSClass.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/PrimitiveConversions.h" |
15 | | #include "mozilla/dom/ScriptSettings.h" |
16 | | #include "mozilla/dom/StyleRuleChangeEvent.h" |
17 | | #include "mozilla/dom/XrayExpandoClass.h" |
18 | | #include "nsContentUtils.h" |
19 | | |
20 | | namespace mozilla { |
21 | | namespace dom { |
22 | | |
23 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
24 | | using namespace mozilla::dom::binding_detail; |
25 | | |
26 | | |
27 | | |
28 | | StyleRuleChangeEventInit::StyleRuleChangeEventInit() |
29 | | : EventInit(FastDictionaryInitializer()) |
30 | 0 | { |
31 | 0 | // Safe to pass a null context if we pass a null value |
32 | 0 | Init(nullptr, JS::NullHandleValue); |
33 | 0 | } |
34 | | |
35 | | |
36 | | |
37 | | bool |
38 | | StyleRuleChangeEventInit::InitIds(JSContext* cx, StyleRuleChangeEventInitAtoms* atomsCache) |
39 | 0 | { |
40 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
41 | 0 |
|
42 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
43 | 0 | // uninitialized. |
44 | 0 | if (!atomsCache->stylesheet_id.init(cx, "stylesheet") || |
45 | 0 | !atomsCache->rule_id.init(cx, "rule")) { |
46 | 0 | return false; |
47 | 0 | } |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | | bool |
52 | | StyleRuleChangeEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
53 | 0 | { |
54 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
55 | 0 | // Since in that case we will not have to do any property gets |
56 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
57 | 0 | // checkers by static analysis tools |
58 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
59 | 0 | StyleRuleChangeEventInitAtoms* atomsCache = nullptr; |
60 | 0 | if (cx) { |
61 | 0 | atomsCache = GetAtomCache<StyleRuleChangeEventInitAtoms>(cx); |
62 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
63 | 0 | return false; |
64 | 0 | } |
65 | 0 | } |
66 | 0 | |
67 | 0 | // Per spec, we init the parent's members first |
68 | 0 | if (!EventInit::Init(cx, val)) { |
69 | 0 | return false; |
70 | 0 | } |
71 | 0 | |
72 | 0 | bool isNull = val.isNullOrUndefined(); |
73 | 0 | // We only need these if !isNull, in which case we have |cx|. |
74 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
75 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
76 | 0 | if (!isNull) { |
77 | 0 | MOZ_ASSERT(cx); |
78 | 0 | object.emplace(cx, &val.toObject()); |
79 | 0 | temp.emplace(cx); |
80 | 0 | } |
81 | 0 | if (!isNull) { |
82 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->rule_id, temp.ptr())) { |
83 | 0 | return false; |
84 | 0 | } |
85 | 0 | } |
86 | 0 | if (!isNull && !temp->isUndefined()) { |
87 | 0 | if (temp.ref().isObject()) { |
88 | 0 | static_assert(IsRefcounted<mozilla::css::Rule>::value, "We can only store refcounted classes.");{ |
89 | 0 | nsresult rv = UnwrapObject<prototypes::id::CSSRule, mozilla::css::Rule>(temp.ptr(), mRule); |
90 | 0 | if (NS_FAILED(rv)) { |
91 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'rule' member of StyleRuleChangeEventInit", "CSSRule"); |
92 | 0 | return false; |
93 | 0 | } |
94 | 0 | } |
95 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
96 | 0 | mRule = nullptr; |
97 | 0 | } else { |
98 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'rule' member of StyleRuleChangeEventInit"); |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | } else { |
102 | 0 | mRule = nullptr; |
103 | 0 | } |
104 | 0 | mIsAnyMemberPresent = true; |
105 | 0 |
|
106 | 0 | if (!isNull) { |
107 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->stylesheet_id, temp.ptr())) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | if (!isNull && !temp->isUndefined()) { |
112 | 0 | if (temp.ref().isObject()) { |
113 | 0 | static_assert(IsRefcounted<mozilla::StyleSheet>::value, "We can only store refcounted classes.");{ |
114 | 0 | nsresult rv = UnwrapObject<prototypes::id::CSSStyleSheet, mozilla::StyleSheet>(temp.ptr(), mStylesheet); |
115 | 0 | if (NS_FAILED(rv)) { |
116 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'stylesheet' member of StyleRuleChangeEventInit", "CSSStyleSheet"); |
117 | 0 | return false; |
118 | 0 | } |
119 | 0 | } |
120 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
121 | 0 | mStylesheet = nullptr; |
122 | 0 | } else { |
123 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'stylesheet' member of StyleRuleChangeEventInit"); |
124 | 0 | return false; |
125 | 0 | } |
126 | 0 | } else { |
127 | 0 | mStylesheet = nullptr; |
128 | 0 | } |
129 | 0 | mIsAnyMemberPresent = true; |
130 | 0 | return true; |
131 | 0 | } |
132 | | |
133 | | bool |
134 | | StyleRuleChangeEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
135 | 0 | { |
136 | 0 | StyleRuleChangeEventInitAtoms* atomsCache = GetAtomCache<StyleRuleChangeEventInitAtoms>(cx); |
137 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
138 | 0 | return false; |
139 | 0 | } |
140 | 0 | |
141 | 0 | // Per spec, we define the parent's members first |
142 | 0 | if (!EventInit::ToObjectInternal(cx, rval)) { |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
146 | 0 |
|
147 | 0 | do { |
148 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
149 | 0 | JS::Rooted<JS::Value> temp(cx); |
150 | 0 | RefPtr<mozilla::css::Rule> const & currentValue = mRule; |
151 | 0 | if (!currentValue) { |
152 | 0 | temp.setNull(); |
153 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->rule_id, temp, JSPROP_ENUMERATE)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | break; |
157 | 0 | } |
158 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
159 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
160 | 0 | return false; |
161 | 0 | } |
162 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->rule_id, temp, JSPROP_ENUMERATE)) { |
163 | 0 | return false; |
164 | 0 | } |
165 | 0 | break; |
166 | 0 | } while(false); |
167 | 0 |
|
168 | 0 | do { |
169 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
170 | 0 | JS::Rooted<JS::Value> temp(cx); |
171 | 0 | RefPtr<mozilla::StyleSheet> const & currentValue = mStylesheet; |
172 | 0 | if (!currentValue) { |
173 | 0 | temp.setNull(); |
174 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stylesheet_id, temp, JSPROP_ENUMERATE)) { |
175 | 0 | return false; |
176 | 0 | } |
177 | 0 | break; |
178 | 0 | } |
179 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
180 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->stylesheet_id, temp, JSPROP_ENUMERATE)) { |
184 | 0 | return false; |
185 | 0 | } |
186 | 0 | break; |
187 | 0 | } while(false); |
188 | 0 |
|
189 | 0 | return true; |
190 | 0 | } |
191 | | |
192 | | void |
193 | | StyleRuleChangeEventInit::TraceDictionary(JSTracer* trc) |
194 | 0 | { |
195 | 0 | EventInit::TraceDictionary(trc); |
196 | 0 | } |
197 | | |
198 | | |
199 | | |
200 | | StyleRuleChangeEventInit& |
201 | | StyleRuleChangeEventInit::operator=(const StyleRuleChangeEventInit& aOther) |
202 | 0 | { |
203 | 0 | EventInit::operator=(aOther); |
204 | 0 | mRule = aOther.mRule; |
205 | 0 | mStylesheet = aOther.mStylesheet; |
206 | 0 | return *this; |
207 | 0 | } |
208 | | |
209 | | namespace binding_detail { |
210 | | } // namespace binding_detail |
211 | | |
212 | | |
213 | | namespace StyleRuleChangeEvent_Binding { |
214 | | |
215 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value, |
216 | | "Can't inherit from an interface with a different ownership model."); |
217 | | |
218 | | MOZ_CAN_RUN_SCRIPT static bool |
219 | | get_stylesheet(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StyleRuleChangeEvent* self, JSJitGetterCallArgs args) |
220 | 0 | { |
221 | 0 | AUTO_PROFILER_LABEL_FAST("get StyleRuleChangeEvent.stylesheet", DOM, cx); |
222 | 0 |
|
223 | 0 | auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->GetStylesheet())); |
224 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
225 | 0 | if (!result) { |
226 | 0 | args.rval().setNull(); |
227 | 0 | return true; |
228 | 0 | } |
229 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
230 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | return true; |
234 | 0 | } |
235 | | |
236 | | static const JSJitInfo stylesheet_getterinfo = { |
237 | | { (JSJitGetterOp)get_stylesheet }, |
238 | | { prototypes::id::StyleRuleChangeEvent }, |
239 | | { PrototypeTraits<prototypes::id::StyleRuleChangeEvent>::Depth }, |
240 | | JSJitInfo::Getter, |
241 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
242 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
243 | | false, /* isInfallible. False in setters. */ |
244 | | false, /* isMovable. Not relevant for setters. */ |
245 | | false, /* isEliminatable. Not relevant for setters. */ |
246 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
247 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
248 | | false, /* isTypedMethod. Only relevant for methods. */ |
249 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
250 | | }; |
251 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
252 | | static_assert(0 < 1, "There is no slot for us"); |
253 | | |
254 | | MOZ_CAN_RUN_SCRIPT static bool |
255 | | get_rule(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StyleRuleChangeEvent* self, JSJitGetterCallArgs args) |
256 | 0 | { |
257 | 0 | AUTO_PROFILER_LABEL_FAST("get StyleRuleChangeEvent.rule", DOM, cx); |
258 | 0 |
|
259 | 0 | auto result(StrongOrRawPtr<mozilla::css::Rule>(self->GetRule())); |
260 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
261 | 0 | if (!result) { |
262 | 0 | args.rval().setNull(); |
263 | 0 | return true; |
264 | 0 | } |
265 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
266 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
267 | 0 | return false; |
268 | 0 | } |
269 | 0 | return true; |
270 | 0 | } |
271 | | |
272 | | static const JSJitInfo rule_getterinfo = { |
273 | | { (JSJitGetterOp)get_rule }, |
274 | | { prototypes::id::StyleRuleChangeEvent }, |
275 | | { PrototypeTraits<prototypes::id::StyleRuleChangeEvent>::Depth }, |
276 | | JSJitInfo::Getter, |
277 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
278 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
279 | | false, /* isInfallible. False in setters. */ |
280 | | false, /* isMovable. Not relevant for setters. */ |
281 | | false, /* isEliminatable. Not relevant for setters. */ |
282 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
283 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
284 | | false, /* isTypedMethod. Only relevant for methods. */ |
285 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
286 | | }; |
287 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
288 | | static_assert(0 < 1, "There is no slot for us"); |
289 | | |
290 | | MOZ_CAN_RUN_SCRIPT static bool |
291 | | get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StyleRuleChangeEvent* self, JSJitGetterCallArgs args) |
292 | 0 | { |
293 | 0 | AUTO_PROFILER_LABEL_FAST("get StyleRuleChangeEvent.isTrusted", DOM, cx); |
294 | 0 |
|
295 | 0 | bool result(self->IsTrusted()); |
296 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
297 | 0 | args.rval().setBoolean(result); |
298 | 0 | return true; |
299 | 0 | } |
300 | | |
301 | | static const JSJitInfo isTrusted_getterinfo = { |
302 | | { (JSJitGetterOp)get_isTrusted }, |
303 | | { prototypes::id::StyleRuleChangeEvent }, |
304 | | { PrototypeTraits<prototypes::id::StyleRuleChangeEvent>::Depth }, |
305 | | JSJitInfo::Getter, |
306 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
307 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
308 | | true, /* isInfallible. False in setters. */ |
309 | | true, /* isMovable. Not relevant for setters. */ |
310 | | true, /* isEliminatable. Not relevant for setters. */ |
311 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
312 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
313 | | false, /* isTypedMethod. Only relevant for methods. */ |
314 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
315 | | }; |
316 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
317 | | static_assert(0 < 1, "There is no slot for us"); |
318 | | |
319 | | static bool |
320 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
321 | 0 | { |
322 | 0 | mozilla::dom::StyleRuleChangeEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StyleRuleChangeEvent>(obj); |
323 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
324 | 0 | // obviously can't preserve if we're not initialized. |
325 | 0 | if (self && self->GetWrapperPreserveColor()) { |
326 | 0 | PreserveWrapper(self); |
327 | 0 | } |
328 | 0 | return true; |
329 | 0 | } |
330 | | |
331 | | static void |
332 | | _finalize(js::FreeOp* fop, JSObject* obj) |
333 | 0 | { |
334 | 0 | mozilla::dom::StyleRuleChangeEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StyleRuleChangeEvent>(obj); |
335 | 0 | if (self) { |
336 | 0 | ClearWrapper(self, self, obj); |
337 | 0 | AddForDeferredFinalization<mozilla::dom::StyleRuleChangeEvent>(self); |
338 | 0 | } |
339 | 0 | } |
340 | | |
341 | | static size_t |
342 | | _objectMoved(JSObject* obj, JSObject* old) |
343 | 0 | { |
344 | 0 | mozilla::dom::StyleRuleChangeEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StyleRuleChangeEvent>(obj); |
345 | 0 | if (self) { |
346 | 0 | UpdateWrapper(self, self, obj, old); |
347 | 0 | } |
348 | 0 |
|
349 | 0 | return 0; |
350 | 0 | } |
351 | | |
352 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
353 | | #if defined(__clang__) |
354 | | #pragma clang diagnostic push |
355 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
356 | | #endif |
357 | | static const JSPropertySpec sAttributes_specs[] = { |
358 | | { "stylesheet", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &stylesheet_getterinfo, nullptr, nullptr }, |
359 | | { "rule", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &rule_getterinfo, nullptr, nullptr }, |
360 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
361 | | }; |
362 | | #if defined(__clang__) |
363 | | #pragma clang diagnostic pop |
364 | | #endif |
365 | | |
366 | | |
367 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
368 | | { nullptr, &sAttributes_specs[0] }, |
369 | | { nullptr, nullptr } |
370 | | }; |
371 | | |
372 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
373 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
374 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
375 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
376 | | |
377 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
378 | | #if defined(__clang__) |
379 | | #pragma clang diagnostic push |
380 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
381 | | #endif |
382 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
383 | | { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr }, |
384 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
385 | | }; |
386 | | #if defined(__clang__) |
387 | | #pragma clang diagnostic pop |
388 | | #endif |
389 | | |
390 | | |
391 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
392 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
393 | | { nullptr, nullptr } |
394 | | }; |
395 | | |
396 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
397 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
398 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
399 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
400 | | |
401 | | |
402 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
403 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
404 | | |
405 | | static const NativePropertiesN<2> sNativeProperties = { |
406 | | false, 0, |
407 | | false, 0, |
408 | | false, 0, |
409 | | true, 0 /* sAttributes */, |
410 | | false, 0, |
411 | | true, 1 /* sUnforgeableAttributes */, |
412 | | false, 0, |
413 | | -1, |
414 | | 3, |
415 | | sNativeProperties_sortedPropertyIndices, |
416 | | { |
417 | | { sAttributes, &sNativeProperties_propertyInfos[0] }, |
418 | | { sUnforgeableAttributes, &sNativeProperties_propertyInfos[2] } |
419 | | } |
420 | | }; |
421 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
422 | | "We have a property info count that is oversized"); |
423 | | |
424 | | static bool |
425 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
426 | 0 | { |
427 | 0 | AUTO_PROFILER_LABEL_FAST("StyleRuleChangeEvent constructor", DOM, cx); |
428 | 0 |
|
429 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
430 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
431 | 0 | if (!args.isConstructing()) { |
432 | 0 | // XXXbz wish I could get the name from the callee instead of |
433 | 0 | // Adding more relocations |
434 | 0 | return ThrowConstructorWithoutNew(cx, "StyleRuleChangeEvent"); |
435 | 0 | } |
436 | 0 | |
437 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
438 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
439 | 0 | return false; |
440 | 0 | } |
441 | 0 | |
442 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
443 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "StyleRuleChangeEvent"); |
444 | 0 | } |
445 | 0 | GlobalObject global(cx, obj); |
446 | 0 | if (global.Failed()) { |
447 | 0 | return false; |
448 | 0 | } |
449 | 0 | |
450 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
451 | 0 | binding_detail::FakeString arg0; |
452 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
453 | 0 | return false; |
454 | 0 | } |
455 | 0 | binding_detail::FastStyleRuleChangeEventInit arg1; |
456 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of StyleRuleChangeEvent.constructor", false)) { |
457 | 0 | return false; |
458 | 0 | } |
459 | 0 | Maybe<JSAutoRealm> ar; |
460 | 0 | if (objIsXray) { |
461 | 0 | obj = js::CheckedUnwrap(obj); |
462 | 0 | if (!obj) { |
463 | 0 | return false; |
464 | 0 | } |
465 | 0 | ar.emplace(cx, obj); |
466 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
467 | 0 | return false; |
468 | 0 | } |
469 | 0 | } |
470 | 0 | FastErrorResult rv; |
471 | 0 | auto result(StrongOrRawPtr<mozilla::dom::StyleRuleChangeEvent>(mozilla::dom::StyleRuleChangeEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
472 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
473 | 0 | return false; |
474 | 0 | } |
475 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
476 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
477 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
478 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
479 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
480 | 0 | return false; |
481 | 0 | } |
482 | 0 | return true; |
483 | 0 | } |
484 | | |
485 | | static const js::ClassOps sInterfaceObjectClassOps = { |
486 | | nullptr, /* addProperty */ |
487 | | nullptr, /* delProperty */ |
488 | | nullptr, /* enumerate */ |
489 | | nullptr, /* newEnumerate */ |
490 | | nullptr, /* resolve */ |
491 | | nullptr, /* mayResolve */ |
492 | | nullptr, /* finalize */ |
493 | | _constructor, /* call */ |
494 | | nullptr, /* hasInstance */ |
495 | | _constructor, /* construct */ |
496 | | nullptr, /* trace */ |
497 | | }; |
498 | | |
499 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
500 | | { |
501 | | "Function", |
502 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
503 | | &sInterfaceObjectClassOps, |
504 | | JS_NULL_CLASS_SPEC, |
505 | | JS_NULL_CLASS_EXT, |
506 | | &sInterfaceObjectClassObjectOps |
507 | | }, |
508 | | eInterface, |
509 | | true, |
510 | | prototypes::id::StyleRuleChangeEvent, |
511 | | PrototypeTraits<prototypes::id::StyleRuleChangeEvent>::Depth, |
512 | | sNativePropertyHooks, |
513 | | "function StyleRuleChangeEvent() {\n [native code]\n}", |
514 | | Event_Binding::GetConstructorObject |
515 | | }; |
516 | | |
517 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
518 | | { |
519 | | "StyleRuleChangeEventPrototype", |
520 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
521 | | JS_NULL_CLASS_OPS, |
522 | | JS_NULL_CLASS_SPEC, |
523 | | JS_NULL_CLASS_EXT, |
524 | | JS_NULL_OBJECT_OPS |
525 | | }, |
526 | | eInterfacePrototype, |
527 | | false, |
528 | | prototypes::id::StyleRuleChangeEvent, |
529 | | PrototypeTraits<prototypes::id::StyleRuleChangeEvent>::Depth, |
530 | | sNativePropertyHooks, |
531 | | "[object StyleRuleChangeEventPrototype]", |
532 | | Event_Binding::GetProtoObject |
533 | | }; |
534 | | |
535 | | bool |
536 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
537 | 0 | { |
538 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
539 | 0 | } |
540 | | |
541 | | static const js::ClassOps sClassOps = { |
542 | | _addProperty, /* addProperty */ |
543 | | nullptr, /* delProperty */ |
544 | | nullptr, /* enumerate */ |
545 | | nullptr, /* newEnumerate */ |
546 | | nullptr, /* resolve */ |
547 | | nullptr, /* mayResolve */ |
548 | | _finalize, /* finalize */ |
549 | | nullptr, /* call */ |
550 | | nullptr, /* hasInstance */ |
551 | | nullptr, /* construct */ |
552 | | nullptr, /* trace */ |
553 | | }; |
554 | | |
555 | | static const js::ClassExtension sClassExtension = { |
556 | | nullptr, /* weakmapKeyDelegateOp */ |
557 | | _objectMoved /* objectMovedOp */ |
558 | | }; |
559 | | |
560 | | static const DOMJSClass sClass = { |
561 | | { "StyleRuleChangeEvent", |
562 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE, |
563 | | &sClassOps, |
564 | | JS_NULL_CLASS_SPEC, |
565 | | &sClassExtension, |
566 | | JS_NULL_OBJECT_OPS |
567 | | }, |
568 | | { prototypes::id::Event, prototypes::id::StyleRuleChangeEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
569 | | IsBaseOf<nsISupports, mozilla::dom::StyleRuleChangeEvent >::value, |
570 | | sNativePropertyHooks, |
571 | | FindAssociatedGlobalForNative<mozilla::dom::StyleRuleChangeEvent>::Get, |
572 | | GetProtoObjectHandle, |
573 | | GetCCParticipant<mozilla::dom::StyleRuleChangeEvent>::Get() |
574 | | }; |
575 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
576 | | "Must have the right minimal number of reserved slots."); |
577 | | static_assert(1 >= 1, |
578 | | "Must have enough reserved slots."); |
579 | | |
580 | | const JSClass* |
581 | | GetJSClass() |
582 | 0 | { |
583 | 0 | return sClass.ToJSClass(); |
584 | 0 | } |
585 | | |
586 | | bool |
587 | | Wrap(JSContext* aCx, mozilla::dom::StyleRuleChangeEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
588 | 0 | { |
589 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::StyleRuleChangeEvent>::value, |
590 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
591 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::StyleRuleChangeEvent*>(aObject) == |
592 | 0 | reinterpret_cast<mozilla::dom::StyleRuleChangeEvent*>(aObject), |
593 | 0 | "Multiple inheritance for mozilla::dom::StyleRuleChangeEvent is broken."); |
594 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) == |
595 | 0 | reinterpret_cast<mozilla::dom::Event*>(aObject), |
596 | 0 | "Multiple inheritance for mozilla::dom::Event is broken."); |
597 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
598 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
599 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
600 | 0 | "You should probably not be using Wrap() directly; use " |
601 | 0 | "GetOrCreateDOMReflector instead"); |
602 | 0 |
|
603 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
604 | 0 | "nsISupports must be on our primary inheritance chain"); |
605 | 0 |
|
606 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
607 | 0 | if (!global) { |
608 | 0 | return false; |
609 | 0 | } |
610 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
611 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
612 | 0 |
|
613 | 0 | // That might have ended up wrapping us already, due to the wonders |
614 | 0 | // of XBL. Check for that, and bail out as needed. |
615 | 0 | aReflector.set(aCache->GetWrapper()); |
616 | 0 | if (aReflector) { |
617 | | #ifdef DEBUG |
618 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
619 | | #endif // DEBUG |
620 | | return true; |
621 | 0 | } |
622 | 0 |
|
623 | 0 | JSAutoRealm ar(aCx, global); |
624 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
625 | 0 | if (!canonicalProto) { |
626 | 0 | return false; |
627 | 0 | } |
628 | 0 | JS::Rooted<JSObject*> proto(aCx); |
629 | 0 | if (aGivenProto) { |
630 | 0 | proto = aGivenProto; |
631 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
632 | 0 | // coming in, we changed compartments to that of "parent" so may need |
633 | 0 | // to wrap the proto here. |
634 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
635 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
636 | 0 | return false; |
637 | 0 | } |
638 | 0 | } |
639 | 0 | } else { |
640 | 0 | proto = canonicalProto; |
641 | 0 | } |
642 | 0 |
|
643 | 0 | BindingJSObjectCreator<mozilla::dom::StyleRuleChangeEvent> creator(aCx); |
644 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
645 | 0 | if (!aReflector) { |
646 | 0 | return false; |
647 | 0 | } |
648 | 0 | |
649 | 0 | aCache->SetWrapper(aReflector); |
650 | 0 |
|
651 | 0 | // Important: do unforgeable property setup after we have handed |
652 | 0 | // over ownership of the C++ object to obj as needed, so that if |
653 | 0 | // we fail and it ends up GCed it won't have problems in the |
654 | 0 | // finalizer trying to drop its ownership of the C++ object. |
655 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
656 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
657 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
658 | 0 | aCache->ReleaseWrapper(aObject); |
659 | 0 | aCache->ClearWrapper(); |
660 | 0 | return false; |
661 | 0 | } |
662 | 0 | creator.InitializationSucceeded(); |
663 | 0 |
|
664 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
665 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
666 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
667 | 0 | // otherwise we won't be able to properly recreate it later, since |
668 | 0 | // we won't know what proto to use. Note that we don't check |
669 | 0 | // aGivenProto here, since it's entirely possible (and even |
670 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
671 | 0 | // same as canonicalProto. |
672 | 0 | if (proto != canonicalProto) { |
673 | 0 | PreserveWrapper(aObject); |
674 | 0 | } |
675 | 0 |
|
676 | 0 | return true; |
677 | 0 | } |
678 | | |
679 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
680 | | nullptr, |
681 | | nullptr, |
682 | | nullptr, |
683 | | { sNativeProperties.Upcast(), nullptr }, |
684 | | prototypes::id::StyleRuleChangeEvent, |
685 | | constructors::id::StyleRuleChangeEvent, |
686 | | Event_Binding::sNativePropertyHooks, |
687 | | &DefaultXrayExpandoObjectClass |
688 | | } }; |
689 | | |
690 | | void |
691 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
692 | 0 | { |
693 | 0 | JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx)); |
694 | 0 | if (!parentProto) { |
695 | 0 | return; |
696 | 0 | } |
697 | 0 | |
698 | 0 | JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx)); |
699 | 0 | if (!constructorProto) { |
700 | 0 | return; |
701 | 0 | } |
702 | 0 | |
703 | 0 | static bool sIdsInited = false; |
704 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
705 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
706 | 0 | return; |
707 | 0 | } |
708 | 0 | sIdsInited = true; |
709 | 0 | } |
710 | 0 |
|
711 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::StyleRuleChangeEvent); |
712 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::StyleRuleChangeEvent); |
713 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
714 | 0 | &sPrototypeClass.mBase, protoCache, |
715 | 0 | nullptr, |
716 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
717 | 0 | interfaceCache, |
718 | 0 | sNativeProperties.Upcast(), |
719 | 0 | nullptr, |
720 | 0 | "StyleRuleChangeEvent", aDefineOnGlobal, |
721 | 0 | nullptr, |
722 | 0 | false); |
723 | 0 |
|
724 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
725 | 0 | { |
726 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
727 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
728 | 0 | if (!unforgeableHolder) { |
729 | 0 | *protoCache = nullptr; |
730 | 0 | if (interfaceCache) { |
731 | 0 | *interfaceCache = nullptr; |
732 | 0 | } |
733 | 0 | return; |
734 | 0 | } |
735 | 0 | } |
736 | 0 |
|
737 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
738 | 0 | *protoCache = nullptr; |
739 | 0 | if (interfaceCache) { |
740 | 0 | *interfaceCache = nullptr; |
741 | 0 | } |
742 | 0 | return; |
743 | 0 | } |
744 | 0 |
|
745 | 0 | if (*protoCache) { |
746 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
747 | 0 | JS::ObjectValue(*unforgeableHolder)); |
748 | 0 | } |
749 | 0 | } |
750 | | |
751 | | JSObject* |
752 | | GetConstructorObject(JSContext* aCx) |
753 | 0 | { |
754 | 0 | return GetConstructorObjectHandle(aCx); |
755 | 0 | } |
756 | | |
757 | | } // namespace StyleRuleChangeEvent_Binding |
758 | | |
759 | | |
760 | | |
761 | | } // namespace dom |
762 | | } // namespace mozilla |