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