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