Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM PushEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "ExtendableEventBinding.h"
5 : #include "PushEventBinding.h"
6 : #include "ServiceWorkerEvents.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/UnionConversions.h"
16 : #include "nsThreadUtils.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : bool
22 0 : ArrayBufferViewOrArrayBufferOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
23 : {
24 0 : switch (mType) {
25 : case eUninitialized: {
26 0 : return false;
27 : break;
28 : }
29 : case eArrayBufferView: {
30 0 : rval.setObject(*mValue.mArrayBufferView.Value().Obj());
31 0 : if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
32 0 : return false;
33 : }
34 0 : return true;
35 : break;
36 : }
37 : case eArrayBuffer: {
38 0 : rval.setObject(*mValue.mArrayBuffer.Value().Obj());
39 0 : if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
40 0 : return false;
41 : }
42 0 : return true;
43 : break;
44 : }
45 : case eUSVString: {
46 0 : if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
47 0 : return false;
48 : }
49 0 : return true;
50 : break;
51 : }
52 : default: {
53 0 : return false;
54 : break;
55 : }
56 : }
57 :
58 : return false;
59 : }
60 :
61 :
62 : ArrayBufferView&
63 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::RawSetAsArrayBufferView()
64 : {
65 0 : if (mType == eArrayBufferView) {
66 0 : return mValue.mArrayBufferView.Value();
67 : }
68 0 : MOZ_ASSERT(mType == eUninitialized);
69 0 : mType = eArrayBufferView;
70 0 : return mValue.mArrayBufferView.SetValue();
71 : }
72 :
73 : ArrayBufferView&
74 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::SetAsArrayBufferView()
75 : {
76 0 : if (mType == eArrayBufferView) {
77 0 : return mValue.mArrayBufferView.Value();
78 : }
79 0 : Uninit();
80 0 : mType = eArrayBufferView;
81 0 : return mValue.mArrayBufferView.SetValue();
82 : }
83 :
84 : bool
85 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::TrySetToArrayBufferView(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
86 : {
87 0 : tryNext = false;
88 : { // scope for memberSlot
89 0 : ArrayBufferView& memberSlot = RawSetAsArrayBufferView();
90 0 : if (!memberSlot.Init(&value.toObject())) {
91 0 : DestroyArrayBufferView();
92 0 : tryNext = true;
93 0 : return true;
94 : }
95 : }
96 0 : return true;
97 : }
98 :
99 : void
100 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::DestroyArrayBufferView()
101 : {
102 0 : MOZ_ASSERT(IsArrayBufferView(), "Wrong type!");
103 0 : mValue.mArrayBufferView.Destroy();
104 0 : mType = eUninitialized;
105 0 : }
106 :
107 :
108 :
109 :
110 : ArrayBuffer&
111 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::RawSetAsArrayBuffer()
112 : {
113 0 : if (mType == eArrayBuffer) {
114 0 : return mValue.mArrayBuffer.Value();
115 : }
116 0 : MOZ_ASSERT(mType == eUninitialized);
117 0 : mType = eArrayBuffer;
118 0 : return mValue.mArrayBuffer.SetValue();
119 : }
120 :
121 : ArrayBuffer&
122 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::SetAsArrayBuffer()
123 : {
124 0 : if (mType == eArrayBuffer) {
125 0 : return mValue.mArrayBuffer.Value();
126 : }
127 0 : Uninit();
128 0 : mType = eArrayBuffer;
129 0 : return mValue.mArrayBuffer.SetValue();
130 : }
131 :
132 : bool
133 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::TrySetToArrayBuffer(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
134 : {
135 0 : tryNext = false;
136 : { // scope for memberSlot
137 0 : ArrayBuffer& memberSlot = RawSetAsArrayBuffer();
138 0 : if (!memberSlot.Init(&value.toObject())) {
139 0 : DestroyArrayBuffer();
140 0 : tryNext = true;
141 0 : return true;
142 : }
143 : }
144 0 : return true;
145 : }
146 :
147 : void
148 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::DestroyArrayBuffer()
149 : {
150 0 : MOZ_ASSERT(IsArrayBuffer(), "Wrong type!");
151 0 : mValue.mArrayBuffer.Destroy();
152 0 : mType = eUninitialized;
153 0 : }
154 :
155 :
156 :
157 :
158 : nsString&
159 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::RawSetAsUSVString()
160 : {
161 0 : if (mType == eUSVString) {
162 0 : return mValue.mUSVString.Value();
163 : }
164 0 : MOZ_ASSERT(mType == eUninitialized);
165 0 : mType = eUSVString;
166 0 : return mValue.mUSVString.SetValue();
167 : }
168 :
169 : nsString&
170 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::SetAsUSVString()
171 : {
172 0 : if (mType == eUSVString) {
173 0 : return mValue.mUSVString.Value();
174 : }
175 0 : Uninit();
176 0 : mType = eUSVString;
177 0 : return mValue.mUSVString.SetValue();
178 : }
179 :
180 : bool
181 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::TrySetToUSVString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
182 : {
183 0 : tryNext = false;
184 : { // scope for memberSlot
185 0 : nsString& memberSlot = RawSetAsUSVString();
186 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
187 0 : return false;
188 : }
189 0 : NormalizeUSVString(memberSlot);
190 : }
191 0 : return true;
192 : }
193 :
194 :
195 : void
196 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::DestroyUSVString()
197 : {
198 0 : MOZ_ASSERT(IsUSVString(), "Wrong type!");
199 0 : mValue.mUSVString.Destroy();
200 0 : mType = eUninitialized;
201 0 : }
202 :
203 :
204 :
205 :
206 : void
207 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::Uninit()
208 : {
209 0 : switch (mType) {
210 : case eUninitialized: {
211 0 : break;
212 : }
213 : case eArrayBufferView: {
214 0 : DestroyArrayBufferView();
215 0 : break;
216 : }
217 : case eArrayBuffer: {
218 0 : DestroyArrayBuffer();
219 0 : break;
220 : }
221 : case eUSVString: {
222 0 : DestroyUSVString();
223 0 : break;
224 : }
225 : }
226 0 : }
227 :
228 : bool
229 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
230 : {
231 0 : switch (mType) {
232 : case eUninitialized: {
233 0 : return false;
234 : break;
235 : }
236 : case eArrayBufferView: {
237 0 : rval.setObject(*mValue.mArrayBufferView.Value().Obj());
238 0 : if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
239 0 : return false;
240 : }
241 0 : return true;
242 : break;
243 : }
244 : case eArrayBuffer: {
245 0 : rval.setObject(*mValue.mArrayBuffer.Value().Obj());
246 0 : if (!MaybeWrapNonDOMObjectValue(cx, rval)) {
247 0 : return false;
248 : }
249 0 : return true;
250 : break;
251 : }
252 : case eUSVString: {
253 0 : if (!xpc::NonVoidStringToJsval(cx, mValue.mUSVString.Value(), rval)) {
254 0 : return false;
255 : }
256 0 : return true;
257 : break;
258 : }
259 : default: {
260 0 : return false;
261 : break;
262 : }
263 : }
264 :
265 : return false;
266 : }
267 :
268 : void
269 0 : OwningArrayBufferViewOrArrayBufferOrUSVString::TraceUnion(JSTracer* trc)
270 : {
271 0 : switch (mType) {
272 : case eArrayBufferView: {
273 0 : mValue.mArrayBufferView.Value().TraceSelf(trc);
274 0 : break;
275 : }
276 : case eArrayBuffer: {
277 0 : mValue.mArrayBuffer.Value().TraceSelf(trc);
278 0 : break;
279 : }
280 : default: {
281 0 : break;
282 : }
283 : }
284 0 : }
285 :
286 :
287 :
288 0 : PushEventInit::PushEventInit()
289 0 : : ExtendableEventInit(FastDictionaryInitializer())
290 : {
291 : // Safe to pass a null context if we pass a null value
292 0 : Init(nullptr, JS::NullHandleValue);
293 0 : }
294 :
295 :
296 : bool
297 0 : PushEventInit::InitIds(JSContext* cx, PushEventInitAtoms* atomsCache)
298 : {
299 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
300 :
301 : // Initialize these in reverse order so that any failure leaves the first one
302 : // uninitialized.
303 0 : if (!atomsCache->data_id.init(cx, "data")) {
304 0 : return false;
305 : }
306 0 : return true;
307 : }
308 :
309 : bool
310 0 : PushEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
311 : {
312 : // Passing a null JSContext is OK only if we're initing from null,
313 : // Since in that case we will not have to do any property gets
314 : // Also evaluate isNullOrUndefined in order to avoid false-positive
315 : // checkers by static analysis tools
316 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
317 0 : PushEventInitAtoms* atomsCache = nullptr;
318 0 : if (cx) {
319 0 : atomsCache = GetAtomCache<PushEventInitAtoms>(cx);
320 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
321 0 : return false;
322 : }
323 : }
324 :
325 : // Per spec, we init the parent's members first
326 0 : if (!ExtendableEventInit::Init(cx, val)) {
327 0 : return false;
328 : }
329 :
330 0 : bool isNull = val.isNullOrUndefined();
331 : // We only need these if !isNull, in which case we have |cx|.
332 0 : Maybe<JS::Rooted<JSObject *> > object;
333 0 : Maybe<JS::Rooted<JS::Value> > temp;
334 0 : if (!isNull) {
335 0 : MOZ_ASSERT(cx);
336 0 : object.emplace(cx, &val.toObject());
337 0 : temp.emplace(cx);
338 : }
339 0 : if (!isNull) {
340 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) {
341 0 : return false;
342 : }
343 : }
344 0 : if (!isNull && !temp->isUndefined()) {
345 0 : mData.Construct();
346 : {
347 0 : bool done = false, failed = false, tryNext;
348 0 : if (temp.ref().isObject()) {
349 0 : done = (failed = !(mData.Value()).TrySetToArrayBufferView(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext ||
350 0 : (failed = !(mData.Value()).TrySetToArrayBuffer(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
351 :
352 : }
353 0 : if (!done) {
354 : do {
355 0 : done = (failed = !(mData.Value()).TrySetToUSVString(cx, temp.ref(), tryNext)) || !tryNext;
356 0 : break;
357 : } while (0);
358 : }
359 0 : if (failed) {
360 0 : return false;
361 : }
362 0 : if (!done) {
363 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'data' member of PushEventInit", "ArrayBufferView, ArrayBuffer");
364 0 : return false;
365 : }
366 : }
367 0 : mIsAnyMemberPresent = true;
368 : }
369 0 : return true;
370 : }
371 :
372 : bool
373 0 : PushEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
374 : {
375 0 : PushEventInitAtoms* atomsCache = GetAtomCache<PushEventInitAtoms>(cx);
376 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
377 0 : return false;
378 : }
379 :
380 : // Per spec, we define the parent's members first
381 0 : if (!ExtendableEventInit::ToObjectInternal(cx, rval)) {
382 0 : return false;
383 : }
384 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
385 :
386 0 : if (mData.WasPassed()) {
387 : do {
388 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
389 0 : JS::Rooted<JS::Value> temp(cx);
390 0 : OwningArrayBufferViewOrArrayBufferOrUSVString const & currentValue = mData.InternalValue();
391 0 : if (!currentValue.ToJSVal(cx, obj, &temp)) {
392 0 : return false;
393 : }
394 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
395 0 : return false;
396 : }
397 0 : break;
398 : } while(0);
399 : }
400 :
401 0 : return true;
402 : }
403 :
404 : void
405 0 : PushEventInit::TraceDictionary(JSTracer* trc)
406 : {
407 0 : ExtendableEventInit::TraceDictionary(trc);
408 0 : if (mData.WasPassed()) {
409 0 : mData.Value().TraceUnion(trc);
410 : }
411 0 : }
412 :
413 : namespace binding_detail {
414 : } // namespace binding_detail
415 :
416 :
417 : namespace PushEventBinding {
418 :
419 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<ExtendableEventBinding::NativeType>::value,
420 : "Can't inherit from an interface with a different ownership model.");
421 :
422 : static bool
423 0 : get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::PushEvent* self, JSJitGetterCallArgs args)
424 : {
425 0 : auto result(StrongOrRawPtr<mozilla::dom::workers::PushMessageData>(self->GetData()));
426 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
427 0 : if (!result) {
428 0 : args.rval().setNull();
429 0 : return true;
430 : }
431 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
432 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
433 0 : return false;
434 : }
435 0 : return true;
436 : }
437 :
438 : static const JSJitInfo data_getterinfo = {
439 : { (JSJitGetterOp)get_data },
440 : { prototypes::id::PushEvent },
441 : { PrototypeTraits<prototypes::id::PushEvent>::Depth },
442 : JSJitInfo::Getter,
443 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
444 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
445 : false, /* isInfallible. False in setters. */
446 : false, /* isMovable. Not relevant for setters. */
447 : false, /* isEliminatable. Not relevant for setters. */
448 : false, /* isAlwaysInSlot. Only relevant for getters. */
449 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
450 : false, /* isTypedMethod. Only relevant for methods. */
451 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
452 : };
453 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
454 : static_assert(0 < 1, "There is no slot for us");
455 :
456 : static bool
457 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::PushEvent* self, JSJitGetterCallArgs args)
458 : {
459 0 : bool result(self->IsTrusted());
460 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
461 0 : args.rval().setBoolean(result);
462 0 : return true;
463 : }
464 :
465 : static const JSJitInfo isTrusted_getterinfo = {
466 : { (JSJitGetterOp)get_isTrusted },
467 : { prototypes::id::PushEvent },
468 : { PrototypeTraits<prototypes::id::PushEvent>::Depth },
469 : JSJitInfo::Getter,
470 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
471 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
472 : true, /* isInfallible. False in setters. */
473 : true, /* isMovable. Not relevant for setters. */
474 : true, /* isEliminatable. Not relevant for setters. */
475 : false, /* isAlwaysInSlot. Only relevant for getters. */
476 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
477 : false, /* isTypedMethod. Only relevant for methods. */
478 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
479 : };
480 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
481 : static_assert(0 < 1, "There is no slot for us");
482 :
483 : static bool
484 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
485 : {
486 0 : mozilla::dom::workers::PushEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::workers::PushEvent>(obj);
487 : // We don't want to preserve if we don't have a wrapper, and we
488 : // obviously can't preserve if we're not initialized.
489 0 : if (self && self->GetWrapperPreserveColor()) {
490 0 : PreserveWrapper(self);
491 : }
492 0 : return true;
493 : }
494 :
495 : static void
496 0 : _finalize(js::FreeOp* fop, JSObject* obj)
497 : {
498 0 : mozilla::dom::workers::PushEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::workers::PushEvent>(obj);
499 0 : if (self) {
500 0 : ClearWrapper(self, self, obj);
501 0 : AddForDeferredFinalization<mozilla::dom::workers::PushEvent>(self);
502 : }
503 0 : }
504 :
505 : static void
506 0 : _objectMoved(JSObject* obj, const JSObject* old)
507 : {
508 0 : mozilla::dom::workers::PushEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::workers::PushEvent>(obj);
509 0 : if (self) {
510 0 : UpdateWrapper(self, self, obj, old);
511 : }
512 0 : }
513 :
514 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
515 : #if defined(__clang__)
516 : #pragma clang diagnostic push
517 : #pragma clang diagnostic ignored "-Wmissing-braces"
518 : #endif
519 : static const JSPropertySpec sAttributes_specs[] = {
520 : { "data", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &data_getterinfo, nullptr, nullptr },
521 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
522 : };
523 : #if defined(__clang__)
524 : #pragma clang diagnostic pop
525 : #endif
526 :
527 :
528 : // Can't be const because the pref-enabled boolean needs to be writable
529 : static Prefable<const JSPropertySpec> sAttributes[] = {
530 : { nullptr, &sAttributes_specs[0] },
531 : { nullptr, nullptr }
532 : };
533 :
534 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
535 : #if defined(__clang__)
536 : #pragma clang diagnostic push
537 : #pragma clang diagnostic ignored "-Wmissing-braces"
538 : #endif
539 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
540 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
541 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
542 : };
543 : #if defined(__clang__)
544 : #pragma clang diagnostic pop
545 : #endif
546 :
547 :
548 : // Can't be const because the pref-enabled boolean needs to be writable
549 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
550 : { nullptr, &sUnforgeableAttributes_specs[0] },
551 : { nullptr, nullptr }
552 : };
553 :
554 :
555 : static const NativePropertiesN<2> sNativeProperties = {
556 : false, 0,
557 : false, 0,
558 : false, 0,
559 : true, 0 /* sAttributes */,
560 : false, 0,
561 : true, 1 /* sUnforgeableAttributes */,
562 : false, 0,
563 : -1,
564 : 0,
565 : nullptr,
566 : {
567 : { sAttributes, nullptr },
568 : { sUnforgeableAttributes, nullptr }
569 : }
570 : };
571 :
572 : static bool
573 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
574 : {
575 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
576 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
577 0 : if (!args.isConstructing()) {
578 : // XXXbz wish I could get the name from the callee instead of
579 : // Adding more relocations
580 0 : return ThrowConstructorWithoutNew(cx, "PushEvent");
581 : }
582 :
583 0 : GlobalObject global(cx, obj);
584 0 : if (global.Failed()) {
585 0 : return false;
586 : }
587 :
588 0 : JS::Rooted<JSObject*> desiredProto(cx);
589 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
590 0 : return false;
591 : }
592 :
593 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
594 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PushEvent");
595 : }
596 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
597 0 : binding_detail::FakeString arg0;
598 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
599 0 : return false;
600 : }
601 0 : RootedDictionary<binding_detail::FastPushEventInit> arg1(cx);
602 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of PushEvent.constructor", false)) {
603 0 : return false;
604 : }
605 0 : Maybe<JSAutoCompartment> ac;
606 0 : if (objIsXray) {
607 0 : obj = js::CheckedUnwrap(obj);
608 0 : if (!obj) {
609 0 : return false;
610 : }
611 0 : ac.emplace(cx, obj);
612 0 : if (!JS_WrapObject(cx, &desiredProto)) {
613 0 : return false;
614 : }
615 0 : if (arg1.mData.WasPassed()) {
616 0 : if (arg1.mData.Value().IsArrayBufferView()) {
617 0 : if (!arg1.mData.Value().GetAsArrayBufferView().WrapIntoNewCompartment(cx)) {
618 0 : return false;
619 : }
620 : }
621 0 : else if (arg1.mData.Value().IsArrayBuffer()) {
622 0 : if (!arg1.mData.Value().GetAsArrayBuffer().WrapIntoNewCompartment(cx)) {
623 0 : return false;
624 : }
625 : }
626 : }
627 : }
628 0 : binding_detail::FastErrorResult rv;
629 0 : auto result(StrongOrRawPtr<mozilla::dom::workers::PushEvent>(mozilla::dom::workers::PushEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
630 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
631 0 : return false;
632 : }
633 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
634 : static_assert(!IsPointer<decltype(result)>::value,
635 : "NewObject implies that we need to keep the object alive with a strong reference.");
636 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
637 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
638 0 : return false;
639 : }
640 0 : return true;
641 : }
642 :
643 : static const js::ClassOps sInterfaceObjectClassOps = {
644 : nullptr, /* addProperty */
645 : nullptr, /* delProperty */
646 : nullptr, /* getProperty */
647 : nullptr, /* setProperty */
648 : nullptr, /* enumerate */
649 : nullptr, /* newEnumerate */
650 : nullptr, /* resolve */
651 : nullptr, /* mayResolve */
652 : nullptr, /* finalize */
653 : _constructor, /* call */
654 : nullptr, /* hasInstance */
655 : _constructor, /* construct */
656 : nullptr, /* trace */
657 : };
658 :
659 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
660 : {
661 : "Function",
662 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
663 : &sInterfaceObjectClassOps,
664 : JS_NULL_CLASS_SPEC,
665 : JS_NULL_CLASS_EXT,
666 : &sInterfaceObjectClassObjectOps
667 : },
668 : eInterface,
669 : true,
670 : prototypes::id::PushEvent,
671 : PrototypeTraits<prototypes::id::PushEvent>::Depth,
672 : &sEmptyNativePropertyHooks,
673 : "function PushEvent() {\n [native code]\n}",
674 : ExtendableEventBinding::GetConstructorObject
675 : };
676 :
677 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
678 : {
679 : "PushEventPrototype",
680 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
681 : JS_NULL_CLASS_OPS,
682 : JS_NULL_CLASS_SPEC,
683 : JS_NULL_CLASS_EXT,
684 : JS_NULL_OBJECT_OPS
685 : },
686 : eInterfacePrototype,
687 : false,
688 : prototypes::id::PushEvent,
689 : PrototypeTraits<prototypes::id::PushEvent>::Depth,
690 : &sEmptyNativePropertyHooks,
691 : "[object PushEventPrototype]",
692 : ExtendableEventBinding::GetProtoObject
693 : };
694 :
695 : bool
696 1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
697 : {
698 1 : MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?");
699 :
700 1 : const char* name = js::GetObjectClass(aObj)->name;
701 1 : if (strcmp(name, "ServiceWorkerGlobalScope")) {
702 1 : return false;
703 : }
704 :
705 0 : return nsContentUtils::PushEnabled(aCx, aObj);
706 : }
707 :
708 : static const js::ClassOps sClassOps = {
709 : _addProperty, /* addProperty */
710 : nullptr, /* delProperty */
711 : nullptr, /* getProperty */
712 : nullptr, /* setProperty */
713 : nullptr, /* enumerate */
714 : nullptr, /* newEnumerate */
715 : nullptr, /* resolve */
716 : nullptr, /* mayResolve */
717 : _finalize, /* finalize */
718 : nullptr, /* call */
719 : nullptr, /* hasInstance */
720 : nullptr, /* construct */
721 : nullptr, /* trace */
722 : };
723 :
724 : static const js::ClassExtension sClassExtension = {
725 : nullptr, /* weakmapKeyDelegateOp */
726 : _objectMoved /* objectMovedOp */
727 : };
728 :
729 : static const DOMJSClass sClass = {
730 : { "PushEvent",
731 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
732 : &sClassOps,
733 : JS_NULL_CLASS_SPEC,
734 : &sClassExtension,
735 : JS_NULL_OBJECT_OPS
736 : },
737 : { prototypes::id::Event, prototypes::id::ExtendableEvent, prototypes::id::PushEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
738 : IsBaseOf<nsISupports, mozilla::dom::workers::PushEvent >::value,
739 : &sEmptyNativePropertyHooks,
740 : FindAssociatedGlobalForNative<mozilla::dom::workers::PushEvent>::Get,
741 : GetProtoObjectHandle,
742 : GetCCParticipant<mozilla::dom::workers::PushEvent>::Get()
743 : };
744 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
745 : "Must have the right minimal number of reserved slots.");
746 : static_assert(1 >= 1,
747 : "Must have enough reserved slots.");
748 :
749 : const JSClass*
750 0 : GetJSClass()
751 : {
752 0 : return sClass.ToJSClass();
753 : }
754 :
755 : bool
756 0 : Wrap(JSContext* aCx, mozilla::dom::workers::PushEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
757 : {
758 : MOZ_ASSERT(static_cast<mozilla::dom::workers::PushEvent*>(aObject) ==
759 : reinterpret_cast<mozilla::dom::workers::PushEvent*>(aObject),
760 : "Multiple inheritance for mozilla::dom::workers::PushEvent is broken.");
761 : MOZ_ASSERT(static_cast<mozilla::dom::workers::ExtendableEvent*>(aObject) ==
762 : reinterpret_cast<mozilla::dom::workers::ExtendableEvent*>(aObject),
763 : "Multiple inheritance for mozilla::dom::workers::ExtendableEvent is broken.");
764 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
765 : reinterpret_cast<mozilla::dom::Event*>(aObject),
766 : "Multiple inheritance for mozilla::dom::Event is broken.");
767 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
768 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
769 0 : MOZ_ASSERT(!aCache->GetWrapper(),
770 : "You should probably not be using Wrap() directly; use "
771 : "GetOrCreateDOMReflector instead");
772 :
773 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
774 : "nsISupports must be on our primary inheritance chain");
775 :
776 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
777 0 : if (!global) {
778 0 : return false;
779 : }
780 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
781 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
782 :
783 : // That might have ended up wrapping us already, due to the wonders
784 : // of XBL. Check for that, and bail out as needed.
785 0 : aReflector.set(aCache->GetWrapper());
786 0 : if (aReflector) {
787 : #ifdef DEBUG
788 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
789 : #endif // DEBUG
790 0 : return true;
791 : }
792 :
793 0 : JSAutoCompartment ac(aCx, global);
794 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
795 0 : if (!canonicalProto) {
796 0 : return false;
797 : }
798 0 : JS::Rooted<JSObject*> proto(aCx);
799 0 : if (aGivenProto) {
800 0 : proto = aGivenProto;
801 : // Unfortunately, while aGivenProto was in the compartment of aCx
802 : // coming in, we changed compartments to that of "parent" so may need
803 : // to wrap the proto here.
804 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
805 0 : if (!JS_WrapObject(aCx, &proto)) {
806 0 : return false;
807 : }
808 : }
809 : } else {
810 0 : proto = canonicalProto;
811 : }
812 :
813 0 : BindingJSObjectCreator<mozilla::dom::workers::PushEvent> creator(aCx);
814 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
815 0 : if (!aReflector) {
816 0 : return false;
817 : }
818 :
819 0 : aCache->SetWrapper(aReflector);
820 :
821 : // Important: do unforgeable property setup after we have handed
822 : // over ownership of the C++ object to obj as needed, so that if
823 : // we fail and it ends up GCed it won't have problems in the
824 : // finalizer trying to drop its ownership of the C++ object.
825 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
826 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
827 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
828 0 : aCache->ReleaseWrapper(aObject);
829 0 : aCache->ClearWrapper();
830 0 : return false;
831 : }
832 0 : creator.InitializationSucceeded();
833 :
834 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
835 : aCache->GetWrapperPreserveColor() == aReflector);
836 : // If proto != canonicalProto, we have to preserve our wrapper;
837 : // otherwise we won't be able to properly recreate it later, since
838 : // we won't know what proto to use. Note that we don't check
839 : // aGivenProto here, since it's entirely possible (and even
840 : // somewhat common) to have a non-null aGivenProto which is the
841 : // same as canonicalProto.
842 0 : if (proto != canonicalProto) {
843 0 : PreserveWrapper(aObject);
844 : }
845 :
846 0 : return true;
847 : }
848 :
849 : void
850 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
851 : {
852 0 : JS::Handle<JSObject*> parentProto(ExtendableEventBinding::GetProtoObjectHandle(aCx));
853 0 : if (!parentProto) {
854 0 : return;
855 : }
856 :
857 0 : JS::Handle<JSObject*> constructorProto(ExtendableEventBinding::GetConstructorObjectHandle(aCx));
858 0 : if (!constructorProto) {
859 0 : return;
860 : }
861 :
862 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PushEvent);
863 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PushEvent);
864 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
865 : &sPrototypeClass.mBase, protoCache,
866 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
867 : interfaceCache,
868 : sNativeProperties.Upcast(),
869 : nullptr,
870 : "PushEvent", aDefineOnGlobal,
871 : nullptr,
872 0 : false);
873 :
874 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
875 : {
876 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
877 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
878 0 : if (!unforgeableHolder) {
879 0 : *protoCache = nullptr;
880 0 : if (interfaceCache) {
881 0 : *interfaceCache = nullptr;
882 : }
883 0 : return;
884 : }
885 : }
886 :
887 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
888 0 : *protoCache = nullptr;
889 0 : if (interfaceCache) {
890 0 : *interfaceCache = nullptr;
891 : }
892 0 : return;
893 : }
894 :
895 0 : if (*protoCache) {
896 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
897 0 : JS::ObjectValue(*unforgeableHolder));
898 : }
899 : }
900 :
901 : JS::Handle<JSObject*>
902 0 : GetProtoObjectHandle(JSContext* aCx)
903 : {
904 : /* Get the interface prototype object for this class. This will create the
905 : object as needed. */
906 0 : bool aDefineOnGlobal = true;
907 :
908 : /* Make sure our global is sane. Hopefully we can remove this sometime */
909 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
910 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
911 0 : return nullptr;
912 : }
913 :
914 : /* Check to see whether the interface objects are already installed */
915 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
916 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PushEvent)) {
917 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
918 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
919 : }
920 :
921 : /*
922 : * The object might _still_ be null, but that's OK.
923 : *
924 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
925 : * traced by TraceProtoAndIfaceCache() and its contents are never
926 : * changed after they have been set.
927 : *
928 : * Calling address() avoids the read read barrier that does gray
929 : * unmarking, but it's not possible for the object to be gray here.
930 : */
931 :
932 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PushEvent);
933 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
934 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
935 : }
936 :
937 : JS::Handle<JSObject*>
938 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
939 : {
940 : /* Get the interface object for this class. This will create the object as
941 : needed. */
942 :
943 : /* Make sure our global is sane. Hopefully we can remove this sometime */
944 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
945 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
946 0 : return nullptr;
947 : }
948 :
949 : /* Check to see whether the interface objects are already installed */
950 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
951 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::PushEvent)) {
952 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
953 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
954 : }
955 :
956 : /*
957 : * The object might _still_ be null, but that's OK.
958 : *
959 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
960 : * traced by TraceProtoAndIfaceCache() and its contents are never
961 : * changed after they have been set.
962 : *
963 : * Calling address() avoids the read read barrier that does gray
964 : * unmarking, but it's not possible for the object to be gray here.
965 : */
966 :
967 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::PushEvent);
968 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
969 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
970 : }
971 :
972 : JSObject*
973 0 : GetConstructorObject(JSContext* aCx)
974 : {
975 0 : return GetConstructorObjectHandle(aCx);
976 : }
977 :
978 : } // namespace PushEventBinding
979 :
980 :
981 :
982 : } // namespace dom
983 : } // namespace mozilla
|