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