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