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