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