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