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