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