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