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