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