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