Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM ExtendableMessageEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "ExtendableEventBinding.h"
5 : #include "ExtendableMessageEventBinding.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/MessagePort.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/ServiceWorkerEvents.h"
16 : #include "mozilla/dom/UnionConversions.h"
17 : #include "mozilla/dom/workers/bindings/ServiceWorker.h"
18 : #include "mozilla/dom/workers/bindings/ServiceWorkerClient.h"
19 : #include "nsThreadUtils.h"
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 : void
25 0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningClientOrServiceWorkerOrMessagePort& aUnion, const char* aName, uint32_t aFlags)
26 : {
27 0 : if (aUnion.IsClient()) {
28 0 : ImplCycleCollectionTraverse(aCallback, aUnion.GetAsClient(), "mClient", aFlags);
29 0 : } else if (aUnion.IsServiceWorker()) {
30 0 : ImplCycleCollectionTraverse(aCallback, aUnion.GetAsServiceWorker(), "mServiceWorker", aFlags);
31 0 : } else if (aUnion.IsMessagePort()) {
32 0 : ImplCycleCollectionTraverse(aCallback, aUnion.GetAsMessagePort(), "mMessagePort", aFlags);
33 : }
34 0 : }
35 :
36 :
37 : void
38 0 : ImplCycleCollectionUnlink(OwningClientOrServiceWorkerOrMessagePort& aUnion)
39 : {
40 0 : aUnion.Uninit();
41 0 : }
42 :
43 :
44 : bool
45 0 : ClientOrServiceWorkerOrMessagePort::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
46 : {
47 0 : switch (mType) {
48 : case eUninitialized: {
49 0 : return false;
50 : break;
51 : }
52 : case eClient: {
53 0 : if (!GetOrCreateDOMReflector(cx, mValue.mClient.Value(), rval)) {
54 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
55 0 : return false;
56 : }
57 0 : return true;
58 : break;
59 : }
60 : case eServiceWorker: {
61 0 : if (!GetOrCreateDOMReflector(cx, mValue.mServiceWorker.Value(), rval)) {
62 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
63 0 : return false;
64 : }
65 0 : return true;
66 : break;
67 : }
68 : case eMessagePort: {
69 0 : if (!GetOrCreateDOMReflector(cx, mValue.mMessagePort.Value(), rval)) {
70 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
71 0 : return false;
72 : }
73 0 : return true;
74 : break;
75 : }
76 : default: {
77 0 : return false;
78 : break;
79 : }
80 : }
81 :
82 : return false;
83 : }
84 :
85 :
86 : OwningNonNull<mozilla::dom::workers::ServiceWorkerClient>&
87 0 : OwningClientOrServiceWorkerOrMessagePort::RawSetAsClient()
88 : {
89 0 : if (mType == eClient) {
90 0 : return mValue.mClient.Value();
91 : }
92 0 : MOZ_ASSERT(mType == eUninitialized);
93 0 : mType = eClient;
94 0 : return mValue.mClient.SetValue();
95 : }
96 :
97 : OwningNonNull<mozilla::dom::workers::ServiceWorkerClient>&
98 0 : OwningClientOrServiceWorkerOrMessagePort::SetAsClient()
99 : {
100 0 : if (mType == eClient) {
101 0 : return mValue.mClient.Value();
102 : }
103 0 : Uninit();
104 0 : mType = eClient;
105 0 : return mValue.mClient.SetValue();
106 : }
107 :
108 : bool
109 0 : OwningClientOrServiceWorkerOrMessagePort::TrySetToClient(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
110 : {
111 0 : tryNext = false;
112 : { // scope for memberSlot
113 0 : OwningNonNull<mozilla::dom::workers::ServiceWorkerClient>& memberSlot = RawSetAsClient();
114 : static_assert(IsRefcounted<mozilla::dom::workers::ServiceWorkerClient>::value, "We can only store refcounted classes.");{
115 0 : nsresult rv = UnwrapObject<prototypes::id::Client, mozilla::dom::workers::ServiceWorkerClient>(value, memberSlot);
116 0 : if (NS_FAILED(rv)) {
117 0 : DestroyClient();
118 0 : tryNext = true;
119 0 : return true;
120 : }
121 : }
122 : }
123 0 : return true;
124 : }
125 :
126 : void
127 0 : OwningClientOrServiceWorkerOrMessagePort::DestroyClient()
128 : {
129 0 : MOZ_ASSERT(IsClient(), "Wrong type!");
130 0 : mValue.mClient.Destroy();
131 0 : mType = eUninitialized;
132 0 : }
133 :
134 :
135 :
136 :
137 : OwningNonNull<mozilla::dom::workers::ServiceWorker>&
138 0 : OwningClientOrServiceWorkerOrMessagePort::RawSetAsServiceWorker()
139 : {
140 0 : if (mType == eServiceWorker) {
141 0 : return mValue.mServiceWorker.Value();
142 : }
143 0 : MOZ_ASSERT(mType == eUninitialized);
144 0 : mType = eServiceWorker;
145 0 : return mValue.mServiceWorker.SetValue();
146 : }
147 :
148 : OwningNonNull<mozilla::dom::workers::ServiceWorker>&
149 0 : OwningClientOrServiceWorkerOrMessagePort::SetAsServiceWorker()
150 : {
151 0 : if (mType == eServiceWorker) {
152 0 : return mValue.mServiceWorker.Value();
153 : }
154 0 : Uninit();
155 0 : mType = eServiceWorker;
156 0 : return mValue.mServiceWorker.SetValue();
157 : }
158 :
159 : bool
160 0 : OwningClientOrServiceWorkerOrMessagePort::TrySetToServiceWorker(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
161 : {
162 0 : tryNext = false;
163 : { // scope for memberSlot
164 0 : OwningNonNull<mozilla::dom::workers::ServiceWorker>& memberSlot = RawSetAsServiceWorker();
165 : static_assert(IsRefcounted<mozilla::dom::workers::ServiceWorker>::value, "We can only store refcounted classes.");{
166 0 : nsresult rv = UnwrapObject<prototypes::id::ServiceWorker, mozilla::dom::workers::ServiceWorker>(value, memberSlot);
167 0 : if (NS_FAILED(rv)) {
168 0 : DestroyServiceWorker();
169 0 : tryNext = true;
170 0 : return true;
171 : }
172 : }
173 : }
174 0 : return true;
175 : }
176 :
177 : void
178 0 : OwningClientOrServiceWorkerOrMessagePort::DestroyServiceWorker()
179 : {
180 0 : MOZ_ASSERT(IsServiceWorker(), "Wrong type!");
181 0 : mValue.mServiceWorker.Destroy();
182 0 : mType = eUninitialized;
183 0 : }
184 :
185 :
186 :
187 :
188 : OwningNonNull<mozilla::dom::MessagePort>&
189 0 : OwningClientOrServiceWorkerOrMessagePort::RawSetAsMessagePort()
190 : {
191 0 : if (mType == eMessagePort) {
192 0 : return mValue.mMessagePort.Value();
193 : }
194 0 : MOZ_ASSERT(mType == eUninitialized);
195 0 : mType = eMessagePort;
196 0 : return mValue.mMessagePort.SetValue();
197 : }
198 :
199 : OwningNonNull<mozilla::dom::MessagePort>&
200 0 : OwningClientOrServiceWorkerOrMessagePort::SetAsMessagePort()
201 : {
202 0 : if (mType == eMessagePort) {
203 0 : return mValue.mMessagePort.Value();
204 : }
205 0 : Uninit();
206 0 : mType = eMessagePort;
207 0 : return mValue.mMessagePort.SetValue();
208 : }
209 :
210 : bool
211 0 : OwningClientOrServiceWorkerOrMessagePort::TrySetToMessagePort(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
212 : {
213 0 : tryNext = false;
214 : { // scope for memberSlot
215 0 : OwningNonNull<mozilla::dom::MessagePort>& memberSlot = RawSetAsMessagePort();
216 : static_assert(IsRefcounted<mozilla::dom::MessagePort>::value, "We can only store refcounted classes.");{
217 0 : nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(value, memberSlot);
218 0 : if (NS_FAILED(rv)) {
219 0 : DestroyMessagePort();
220 0 : tryNext = true;
221 0 : return true;
222 : }
223 : }
224 : }
225 0 : return true;
226 : }
227 :
228 : void
229 0 : OwningClientOrServiceWorkerOrMessagePort::DestroyMessagePort()
230 : {
231 0 : MOZ_ASSERT(IsMessagePort(), "Wrong type!");
232 0 : mValue.mMessagePort.Destroy();
233 0 : mType = eUninitialized;
234 0 : }
235 :
236 :
237 :
238 :
239 : void
240 0 : OwningClientOrServiceWorkerOrMessagePort::Uninit()
241 : {
242 0 : switch (mType) {
243 : case eUninitialized: {
244 0 : break;
245 : }
246 : case eClient: {
247 0 : DestroyClient();
248 0 : break;
249 : }
250 : case eServiceWorker: {
251 0 : DestroyServiceWorker();
252 0 : break;
253 : }
254 : case eMessagePort: {
255 0 : DestroyMessagePort();
256 0 : break;
257 : }
258 : }
259 0 : }
260 :
261 : bool
262 0 : OwningClientOrServiceWorkerOrMessagePort::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
263 : {
264 0 : switch (mType) {
265 : case eUninitialized: {
266 0 : return false;
267 : break;
268 : }
269 : case eClient: {
270 0 : if (!GetOrCreateDOMReflector(cx, mValue.mClient.Value(), rval)) {
271 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
272 0 : return false;
273 : }
274 0 : return true;
275 : break;
276 : }
277 : case eServiceWorker: {
278 0 : if (!GetOrCreateDOMReflector(cx, mValue.mServiceWorker.Value(), rval)) {
279 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
280 0 : return false;
281 : }
282 0 : return true;
283 : break;
284 : }
285 : case eMessagePort: {
286 0 : if (!GetOrCreateDOMReflector(cx, mValue.mMessagePort.Value(), rval)) {
287 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
288 0 : return false;
289 : }
290 0 : return true;
291 : break;
292 : }
293 : default: {
294 0 : return false;
295 : break;
296 : }
297 : }
298 :
299 : return false;
300 : }
301 :
302 : void
303 0 : OwningClientOrServiceWorkerOrMessagePort::TraceUnion(JSTracer* trc)
304 : {
305 0 : }
306 :
307 : OwningClientOrServiceWorkerOrMessagePort&
308 0 : OwningClientOrServiceWorkerOrMessagePort::operator=(const OwningClientOrServiceWorkerOrMessagePort& aOther)
309 : {
310 0 : switch (aOther.mType) {
311 : case eUninitialized: {
312 0 : MOZ_ASSERT(mType == eUninitialized,
313 : "We need to destroy ourselves?");
314 0 : break;
315 : }
316 : case eClient: {
317 0 : SetAsClient() = aOther.GetAsClient();
318 0 : break;
319 : }
320 : case eServiceWorker: {
321 0 : SetAsServiceWorker() = aOther.GetAsServiceWorker();
322 0 : break;
323 : }
324 : case eMessagePort: {
325 0 : SetAsMessagePort() = aOther.GetAsMessagePort();
326 0 : break;
327 : }
328 : }
329 0 : return *this;
330 : }
331 :
332 :
333 :
334 0 : ExtendableMessageEventInit::ExtendableMessageEventInit()
335 0 : : ExtendableEventInit(FastDictionaryInitializer()),
336 0 : mData(JS::UndefinedValue())
337 : {
338 : // Safe to pass a null context if we pass a null value
339 0 : Init(nullptr, JS::NullHandleValue);
340 0 : }
341 :
342 :
343 : bool
344 0 : ExtendableMessageEventInit::InitIds(JSContext* cx, ExtendableMessageEventInitAtoms* atomsCache)
345 : {
346 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
347 :
348 : // Initialize these in reverse order so that any failure leaves the first one
349 : // uninitialized.
350 0 : if (!atomsCache->source_id.init(cx, "source") ||
351 0 : !atomsCache->ports_id.init(cx, "ports") ||
352 0 : !atomsCache->origin_id.init(cx, "origin") ||
353 0 : !atomsCache->lastEventId_id.init(cx, "lastEventId") ||
354 0 : !atomsCache->data_id.init(cx, "data")) {
355 0 : return false;
356 : }
357 0 : return true;
358 : }
359 :
360 : bool
361 0 : ExtendableMessageEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
362 : {
363 : // Passing a null JSContext is OK only if we're initing from null,
364 : // Since in that case we will not have to do any property gets
365 : // Also evaluate isNullOrUndefined in order to avoid false-positive
366 : // checkers by static analysis tools
367 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
368 0 : ExtendableMessageEventInitAtoms* atomsCache = nullptr;
369 0 : if (cx) {
370 0 : atomsCache = GetAtomCache<ExtendableMessageEventInitAtoms>(cx);
371 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
372 0 : return false;
373 : }
374 : }
375 :
376 : // Per spec, we init the parent's members first
377 0 : if (!ExtendableEventInit::Init(cx, val)) {
378 0 : return false;
379 : }
380 :
381 0 : bool isNull = val.isNullOrUndefined();
382 : // We only need these if !isNull, in which case we have |cx|.
383 0 : Maybe<JS::Rooted<JSObject *> > object;
384 0 : Maybe<JS::Rooted<JS::Value> > temp;
385 0 : if (!isNull) {
386 0 : MOZ_ASSERT(cx);
387 0 : object.emplace(cx, &val.toObject());
388 0 : temp.emplace(cx);
389 : }
390 0 : if (!isNull) {
391 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) {
392 0 : return false;
393 : }
394 : }
395 0 : if (!isNull && !temp->isUndefined()) {
396 : #ifdef __clang__
397 : #pragma clang diagnostic push
398 : #pragma clang diagnostic ignored "-Wunreachable-code"
399 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
400 : #endif // __clang__
401 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
402 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'data' member of ExtendableMessageEventInit");
403 0 : return false;
404 : }
405 : #ifdef __clang__
406 : #pragma clang diagnostic pop
407 : #endif // __clang__
408 0 : mData = temp.ref();
409 : } else {
410 0 : mData = JS::NullValue();
411 : }
412 0 : mIsAnyMemberPresent = true;
413 :
414 0 : if (!isNull) {
415 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->lastEventId_id, temp.ptr())) {
416 0 : return false;
417 : }
418 : }
419 0 : if (!isNull && !temp->isUndefined()) {
420 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLastEventId)) {
421 0 : return false;
422 : }
423 : } else {
424 : static const char16_t data[] = { 0 };
425 0 : mLastEventId.Rebind(data, ArrayLength(data) - 1);
426 : }
427 0 : mIsAnyMemberPresent = true;
428 :
429 0 : if (!isNull) {
430 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->origin_id, temp.ptr())) {
431 0 : return false;
432 : }
433 : }
434 0 : if (!isNull && !temp->isUndefined()) {
435 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mOrigin)) {
436 0 : return false;
437 : }
438 : } else {
439 : static const char16_t data[] = { 0 };
440 0 : mOrigin.Rebind(data, ArrayLength(data) - 1);
441 : }
442 0 : mIsAnyMemberPresent = true;
443 :
444 0 : if (!isNull) {
445 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->ports_id, temp.ptr())) {
446 0 : return false;
447 : }
448 : }
449 0 : if (!isNull && !temp->isUndefined()) {
450 0 : if (temp.ref().isObject()) {
451 0 : JS::ForOfIterator iter(cx);
452 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
453 0 : return false;
454 : }
455 0 : if (!iter.valueIsIterable()) {
456 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'ports' member of ExtendableMessageEventInit");
457 0 : return false;
458 : }
459 0 : Sequence<OwningNonNull<mozilla::dom::MessagePort>> &arr = mPorts;
460 0 : JS::Rooted<JS::Value> temp(cx);
461 : while (true) {
462 : bool done;
463 0 : if (!iter.next(&temp, &done)) {
464 0 : return false;
465 : }
466 0 : if (done) {
467 0 : break;
468 : }
469 0 : OwningNonNull<mozilla::dom::MessagePort>* slotPtr = arr.AppendElement(mozilla::fallible);
470 0 : if (!slotPtr) {
471 0 : JS_ReportOutOfMemory(cx);
472 0 : return false;
473 : }
474 0 : OwningNonNull<mozilla::dom::MessagePort>& slot = *slotPtr;
475 0 : if (temp.isObject()) {
476 : static_assert(IsRefcounted<mozilla::dom::MessagePort>::value, "We can only store refcounted classes.");{
477 0 : nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(&temp, slot);
478 0 : if (NS_FAILED(rv)) {
479 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'ports' member of ExtendableMessageEventInit", "MessagePort");
480 0 : return false;
481 : }
482 : }
483 : } else {
484 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'ports' member of ExtendableMessageEventInit");
485 0 : return false;
486 : }
487 0 : }
488 : } else {
489 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'ports' member of ExtendableMessageEventInit");
490 0 : return false;
491 : }
492 : } else {
493 : /* Array is already empty; nothing to do */
494 : }
495 0 : mIsAnyMemberPresent = true;
496 :
497 0 : if (!isNull) {
498 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->source_id, temp.ptr())) {
499 0 : return false;
500 : }
501 : }
502 0 : if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
503 0 : mSource.SetNull();
504 : } else {
505 : {
506 0 : bool done = false, failed = false, tryNext;
507 0 : if (temp.ref().isObject()) {
508 0 : done = (failed = !mSource.SetValue().TrySetToClient(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext ||
509 0 : (failed = !mSource.SetValue().TrySetToServiceWorker(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext ||
510 0 : (failed = !mSource.SetValue().TrySetToMessagePort(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
511 :
512 : }
513 0 : if (failed) {
514 0 : return false;
515 : }
516 0 : if (!done) {
517 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'source' member of ExtendableMessageEventInit", "Client, ServiceWorker, MessagePort");
518 0 : return false;
519 : }
520 : }
521 : }
522 0 : mIsAnyMemberPresent = true;
523 0 : return true;
524 : }
525 :
526 : bool
527 0 : ExtendableMessageEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
528 : {
529 0 : ExtendableMessageEventInitAtoms* atomsCache = GetAtomCache<ExtendableMessageEventInitAtoms>(cx);
530 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
531 0 : return false;
532 : }
533 :
534 : // Per spec, we define the parent's members first
535 0 : if (!ExtendableEventInit::ToObjectInternal(cx, rval)) {
536 0 : return false;
537 : }
538 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
539 :
540 : do {
541 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
542 0 : JS::Rooted<JS::Value> temp(cx);
543 0 : JS::Value const & currentValue = mData;
544 0 : JS::ExposeValueToActiveJS(currentValue);
545 0 : temp.set(currentValue);
546 0 : if (!MaybeWrapValue(cx, &temp)) {
547 0 : return false;
548 : }
549 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
550 0 : return false;
551 : }
552 0 : break;
553 : } while(0);
554 :
555 : do {
556 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
557 0 : JS::Rooted<JS::Value> temp(cx);
558 0 : nsString const & currentValue = mLastEventId;
559 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
560 0 : return false;
561 : }
562 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->lastEventId_id, temp, JSPROP_ENUMERATE)) {
563 0 : return false;
564 : }
565 0 : break;
566 : } while(0);
567 :
568 : do {
569 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
570 0 : JS::Rooted<JS::Value> temp(cx);
571 0 : nsString const & currentValue = mOrigin;
572 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
573 0 : return false;
574 : }
575 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->origin_id, temp, JSPROP_ENUMERATE)) {
576 0 : return false;
577 : }
578 0 : break;
579 : } while(0);
580 :
581 : do {
582 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
583 0 : JS::Rooted<JS::Value> temp(cx);
584 0 : Sequence<OwningNonNull<mozilla::dom::MessagePort>> const & currentValue = mPorts;
585 :
586 0 : uint32_t length = currentValue.Length();
587 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
588 0 : if (!returnArray) {
589 0 : return false;
590 : }
591 : // Scope for 'tmp'
592 : {
593 0 : JS::Rooted<JS::Value> tmp(cx);
594 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
595 : // Control block to let us common up the JS_DefineElement calls when there
596 : // are different ways to succeed at wrapping the object.
597 : do {
598 0 : if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) {
599 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
600 0 : return false;
601 : }
602 0 : break;
603 : } while (0);
604 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
605 : JSPROP_ENUMERATE)) {
606 0 : return false;
607 : }
608 : }
609 : }
610 0 : temp.setObject(*returnArray);
611 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->ports_id, temp, JSPROP_ENUMERATE)) {
612 0 : return false;
613 : }
614 0 : break;
615 : } while(0);
616 :
617 : do {
618 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
619 0 : JS::Rooted<JS::Value> temp(cx);
620 0 : Nullable<OwningClientOrServiceWorkerOrMessagePort > const & currentValue = mSource;
621 0 : if (currentValue.IsNull()) {
622 0 : temp.setNull();
623 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->source_id, temp, JSPROP_ENUMERATE)) {
624 0 : return false;
625 : }
626 0 : break;
627 : }
628 0 : if (!currentValue.Value().ToJSVal(cx, obj, &temp)) {
629 0 : return false;
630 : }
631 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->source_id, temp, JSPROP_ENUMERATE)) {
632 0 : return false;
633 : }
634 0 : break;
635 : } while(0);
636 :
637 0 : return true;
638 : }
639 :
640 : void
641 0 : ExtendableMessageEventInit::TraceDictionary(JSTracer* trc)
642 : {
643 0 : ExtendableEventInit::TraceDictionary(trc);
644 0 : JS::UnsafeTraceRoot(trc, &mData, "ExtendableMessageEventInit.mData");
645 0 : }
646 :
647 : namespace binding_detail {
648 : } // namespace binding_detail
649 :
650 :
651 : namespace ExtendableMessageEventBinding {
652 :
653 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<ExtendableEventBinding::NativeType>::value,
654 : "Can't inherit from an interface with a different ownership model.");
655 :
656 : static bool
657 0 : get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::ExtendableMessageEvent* self, JSJitGetterCallArgs args)
658 : {
659 0 : binding_detail::FastErrorResult rv;
660 0 : JS::Rooted<JS::Value> result(cx);
661 0 : self->GetData(cx, &result, rv);
662 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
663 0 : return false;
664 : }
665 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
666 0 : JS::ExposeValueToActiveJS(result);
667 0 : args.rval().set(result);
668 0 : if (!MaybeWrapValue(cx, args.rval())) {
669 0 : return false;
670 : }
671 0 : return true;
672 : }
673 :
674 : static const JSJitInfo data_getterinfo = {
675 : { (JSJitGetterOp)get_data },
676 : { prototypes::id::ExtendableMessageEvent },
677 : { PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth },
678 : JSJitInfo::Getter,
679 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
680 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
681 : false, /* isInfallible. False in setters. */
682 : false, /* isMovable. Not relevant for setters. */
683 : false, /* isEliminatable. Not relevant for setters. */
684 : false, /* isAlwaysInSlot. Only relevant for getters. */
685 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
686 : false, /* isTypedMethod. Only relevant for methods. */
687 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
688 : };
689 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
690 : static_assert(0 < 2, "There is no slot for us");
691 :
692 : static bool
693 0 : get_origin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::ExtendableMessageEvent* self, JSJitGetterCallArgs args)
694 : {
695 0 : DOMString result;
696 0 : self->GetOrigin(result);
697 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
698 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
699 0 : return false;
700 : }
701 0 : return true;
702 : }
703 :
704 : static const JSJitInfo origin_getterinfo = {
705 : { (JSJitGetterOp)get_origin },
706 : { prototypes::id::ExtendableMessageEvent },
707 : { PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth },
708 : JSJitInfo::Getter,
709 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
710 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
711 : false, /* isInfallible. False in setters. */
712 : false, /* isMovable. Not relevant for setters. */
713 : false, /* isEliminatable. Not relevant for setters. */
714 : false, /* isAlwaysInSlot. Only relevant for getters. */
715 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
716 : false, /* isTypedMethod. Only relevant for methods. */
717 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
718 : };
719 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
720 : static_assert(0 < 2, "There is no slot for us");
721 :
722 : static bool
723 0 : get_lastEventId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::ExtendableMessageEvent* self, JSJitGetterCallArgs args)
724 : {
725 0 : DOMString result;
726 0 : self->GetLastEventId(result);
727 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
728 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
729 0 : return false;
730 : }
731 0 : return true;
732 : }
733 :
734 : static const JSJitInfo lastEventId_getterinfo = {
735 : { (JSJitGetterOp)get_lastEventId },
736 : { prototypes::id::ExtendableMessageEvent },
737 : { PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth },
738 : JSJitInfo::Getter,
739 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
740 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
741 : false, /* isInfallible. False in setters. */
742 : false, /* isMovable. Not relevant for setters. */
743 : false, /* isEliminatable. Not relevant for setters. */
744 : false, /* isAlwaysInSlot. Only relevant for getters. */
745 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
746 : false, /* isTypedMethod. Only relevant for methods. */
747 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
748 : };
749 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
750 : static_assert(0 < 2, "There is no slot for us");
751 :
752 : static bool
753 0 : get_source(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::ExtendableMessageEvent* self, JSJitGetterCallArgs args)
754 : {
755 0 : Nullable<OwningClientOrServiceWorkerOrMessagePort> result;
756 0 : self->GetSource(result);
757 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
758 0 : if (result.IsNull()) {
759 0 : args.rval().setNull();
760 0 : return true;
761 : }
762 0 : if (!result.Value().ToJSVal(cx, obj, args.rval())) {
763 0 : return false;
764 : }
765 0 : return true;
766 : }
767 :
768 : static const JSJitInfo source_getterinfo = {
769 : { (JSJitGetterOp)get_source },
770 : { prototypes::id::ExtendableMessageEvent },
771 : { PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth },
772 : JSJitInfo::Getter,
773 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
774 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
775 : false, /* isInfallible. False in setters. */
776 : false, /* isMovable. Not relevant for setters. */
777 : false, /* isEliminatable. Not relevant for setters. */
778 : false, /* isAlwaysInSlot. Only relevant for getters. */
779 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
780 : false, /* isTypedMethod. Only relevant for methods. */
781 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
782 : };
783 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
784 : static_assert(0 < 2, "There is no slot for us");
785 :
786 : static bool
787 0 : get_ports(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::ExtendableMessageEvent* self, JSJitGetterCallArgs args)
788 : {
789 : // Have to either root across the getter call or reget after.
790 0 : JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
791 0 : MOZ_ASSERT(IsDOMObject(slotStorage));
792 0 : const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 0);
793 0 : MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
794 : {
795 : // Scope for cachedVal
796 0 : JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
797 0 : if (!cachedVal.isUndefined()) {
798 0 : args.rval().set(cachedVal);
799 : // The cached value is in the compartment of slotStorage,
800 : // so wrap into the caller compartment as needed.
801 0 : return MaybeWrapNonDOMObjectValue(cx, args.rval());
802 : }
803 : }
804 :
805 0 : nsTArray<StrongPtrForMember<mozilla::dom::MessagePort>::Type> result;
806 0 : self->GetPorts(result);
807 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
808 : {
809 0 : JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
810 0 : JSAutoCompartment ac(cx, conversionScope);
811 : do { // block we break out of when done wrapping
812 :
813 0 : uint32_t length = result.Length();
814 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
815 0 : if (!returnArray) {
816 0 : return false;
817 : }
818 : // Scope for 'tmp'
819 : {
820 0 : JS::Rooted<JS::Value> tmp(cx);
821 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
822 : // Control block to let us common up the JS_DefineElement calls when there
823 : // are different ways to succeed at wrapping the object.
824 : do {
825 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
826 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
827 0 : return false;
828 : }
829 0 : break;
830 : } while (0);
831 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
832 : JSPROP_ENUMERATE)) {
833 0 : return false;
834 : }
835 : }
836 : }
837 0 : args.rval().setObject(*returnArray);
838 0 : break;
839 : } while (0);
840 0 : JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject());
841 0 : if (!JS_FreezeObject(cx, rvalObj)) {
842 0 : return false;
843 : }
844 : }
845 : { // And now store things in the compartment of our slotStorage.
846 0 : JSAutoCompartment ac(cx, slotStorage);
847 : // Make a copy so that we don't do unnecessary wrapping on args.rval().
848 0 : JS::Rooted<JS::Value> storedVal(cx, args.rval());
849 0 : if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
850 0 : return false;
851 : }
852 0 : js::SetReservedSlot(slotStorage, slotIndex, storedVal);
853 0 : PreserveWrapper(self);
854 : }
855 : // And now make sure args.rval() is in the caller compartment
856 0 : return MaybeWrapNonDOMObjectValue(cx, args.rval());
857 : }
858 :
859 : static const JSJitInfo ports_getterinfo = {
860 : { (JSJitGetterOp)get_ports },
861 : { prototypes::id::ExtendableMessageEvent },
862 : { PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth },
863 : JSJitInfo::Getter,
864 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
865 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
866 : false, /* isInfallible. False in setters. */
867 : true, /* isMovable. Not relevant for setters. */
868 : true, /* isEliminatable. Not relevant for setters. */
869 : false, /* isAlwaysInSlot. Only relevant for getters. */
870 : true, /* isLazilyCachedInSlot. Only relevant for getters. */
871 : false, /* isTypedMethod. Only relevant for methods. */
872 : (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */
873 : };
874 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
875 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
876 :
877 : static bool
878 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::workers::ExtendableMessageEvent* self, JSJitGetterCallArgs args)
879 : {
880 0 : bool result(self->IsTrusted());
881 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
882 0 : args.rval().setBoolean(result);
883 0 : return true;
884 : }
885 :
886 : static const JSJitInfo isTrusted_getterinfo = {
887 : { (JSJitGetterOp)get_isTrusted },
888 : { prototypes::id::ExtendableMessageEvent },
889 : { PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth },
890 : JSJitInfo::Getter,
891 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
892 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
893 : true, /* isInfallible. False in setters. */
894 : true, /* isMovable. Not relevant for setters. */
895 : true, /* isEliminatable. Not relevant for setters. */
896 : false, /* isAlwaysInSlot. Only relevant for getters. */
897 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
898 : false, /* isTypedMethod. Only relevant for methods. */
899 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
900 : };
901 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
902 : static_assert(0 < 2, "There is no slot for us");
903 :
904 : static bool
905 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
906 : {
907 0 : mozilla::dom::workers::ExtendableMessageEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::workers::ExtendableMessageEvent>(obj);
908 : // We don't want to preserve if we don't have a wrapper, and we
909 : // obviously can't preserve if we're not initialized.
910 0 : if (self && self->GetWrapperPreserveColor()) {
911 0 : PreserveWrapper(self);
912 : }
913 0 : return true;
914 : }
915 :
916 : static void
917 0 : _finalize(js::FreeOp* fop, JSObject* obj)
918 : {
919 0 : mozilla::dom::workers::ExtendableMessageEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::workers::ExtendableMessageEvent>(obj);
920 0 : if (self) {
921 0 : ClearWrapper(self, self, obj);
922 0 : AddForDeferredFinalization<mozilla::dom::workers::ExtendableMessageEvent>(self);
923 : }
924 0 : }
925 :
926 : static void
927 0 : _objectMoved(JSObject* obj, const JSObject* old)
928 : {
929 0 : mozilla::dom::workers::ExtendableMessageEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::workers::ExtendableMessageEvent>(obj);
930 0 : if (self) {
931 0 : UpdateWrapper(self, self, obj, old);
932 : }
933 0 : }
934 :
935 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
936 : #if defined(__clang__)
937 : #pragma clang diagnostic push
938 : #pragma clang diagnostic ignored "-Wmissing-braces"
939 : #endif
940 : static const JSPropertySpec sAttributes_specs[] = {
941 : { "data", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &data_getterinfo, nullptr, nullptr },
942 : { "origin", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &origin_getterinfo, nullptr, nullptr },
943 : { "lastEventId", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &lastEventId_getterinfo, nullptr, nullptr },
944 : { "source", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &source_getterinfo, nullptr, nullptr },
945 : { "ports", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ports_getterinfo, nullptr, nullptr },
946 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
947 : };
948 : #if defined(__clang__)
949 : #pragma clang diagnostic pop
950 : #endif
951 :
952 :
953 : // Can't be const because the pref-enabled boolean needs to be writable
954 : static Prefable<const JSPropertySpec> sAttributes[] = {
955 : { nullptr, &sAttributes_specs[0] },
956 : { nullptr, nullptr }
957 : };
958 :
959 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
960 : #if defined(__clang__)
961 : #pragma clang diagnostic push
962 : #pragma clang diagnostic ignored "-Wmissing-braces"
963 : #endif
964 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
965 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
966 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
967 : };
968 : #if defined(__clang__)
969 : #pragma clang diagnostic pop
970 : #endif
971 :
972 :
973 : // Can't be const because the pref-enabled boolean needs to be writable
974 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
975 : { nullptr, &sUnforgeableAttributes_specs[0] },
976 : { nullptr, nullptr }
977 : };
978 :
979 :
980 : static const NativePropertiesN<2> sNativeProperties = {
981 : false, 0,
982 : false, 0,
983 : false, 0,
984 : true, 0 /* sAttributes */,
985 : false, 0,
986 : true, 1 /* sUnforgeableAttributes */,
987 : false, 0,
988 : -1,
989 : 0,
990 : nullptr,
991 : {
992 : { sAttributes, nullptr },
993 : { sUnforgeableAttributes, nullptr }
994 : }
995 : };
996 :
997 : static bool
998 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
999 : {
1000 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1001 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
1002 0 : if (!args.isConstructing()) {
1003 : // XXXbz wish I could get the name from the callee instead of
1004 : // Adding more relocations
1005 0 : return ThrowConstructorWithoutNew(cx, "ExtendableMessageEvent");
1006 : }
1007 :
1008 0 : GlobalObject global(cx, obj);
1009 0 : if (global.Failed()) {
1010 0 : return false;
1011 : }
1012 :
1013 0 : JS::Rooted<JSObject*> desiredProto(cx);
1014 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
1015 0 : return false;
1016 : }
1017 :
1018 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1019 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ExtendableMessageEvent");
1020 : }
1021 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1022 0 : binding_detail::FakeString arg0;
1023 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1024 0 : return false;
1025 : }
1026 0 : RootedDictionary<binding_detail::FastExtendableMessageEventInit> arg1(cx);
1027 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of ExtendableMessageEvent.constructor", false)) {
1028 0 : return false;
1029 : }
1030 0 : Maybe<JSAutoCompartment> ac;
1031 0 : if (objIsXray) {
1032 0 : obj = js::CheckedUnwrap(obj);
1033 0 : if (!obj) {
1034 0 : return false;
1035 : }
1036 0 : ac.emplace(cx, obj);
1037 0 : if (!JS_WrapObject(cx, &desiredProto)) {
1038 0 : return false;
1039 : }
1040 0 : if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg1.mData))) {
1041 0 : return false;
1042 : }
1043 : }
1044 0 : binding_detail::FastErrorResult rv;
1045 0 : auto result(StrongOrRawPtr<mozilla::dom::workers::ExtendableMessageEvent>(mozilla::dom::workers::ExtendableMessageEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
1046 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1047 0 : return false;
1048 : }
1049 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1050 : static_assert(!IsPointer<decltype(result)>::value,
1051 : "NewObject implies that we need to keep the object alive with a strong reference.");
1052 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1053 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1054 0 : return false;
1055 : }
1056 0 : return true;
1057 : }
1058 :
1059 : static const js::ClassOps sInterfaceObjectClassOps = {
1060 : nullptr, /* addProperty */
1061 : nullptr, /* delProperty */
1062 : nullptr, /* getProperty */
1063 : nullptr, /* setProperty */
1064 : nullptr, /* enumerate */
1065 : nullptr, /* newEnumerate */
1066 : nullptr, /* resolve */
1067 : nullptr, /* mayResolve */
1068 : nullptr, /* finalize */
1069 : _constructor, /* call */
1070 : nullptr, /* hasInstance */
1071 : _constructor, /* construct */
1072 : nullptr, /* trace */
1073 : };
1074 :
1075 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1076 : {
1077 : "Function",
1078 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1079 : &sInterfaceObjectClassOps,
1080 : JS_NULL_CLASS_SPEC,
1081 : JS_NULL_CLASS_EXT,
1082 : &sInterfaceObjectClassObjectOps
1083 : },
1084 : eInterface,
1085 : true,
1086 : prototypes::id::ExtendableMessageEvent,
1087 : PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth,
1088 : &sEmptyNativePropertyHooks,
1089 : "function ExtendableMessageEvent() {\n [native code]\n}",
1090 : ExtendableEventBinding::GetConstructorObject
1091 : };
1092 :
1093 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1094 : {
1095 : "ExtendableMessageEventPrototype",
1096 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
1097 : JS_NULL_CLASS_OPS,
1098 : JS_NULL_CLASS_SPEC,
1099 : JS_NULL_CLASS_EXT,
1100 : JS_NULL_OBJECT_OPS
1101 : },
1102 : eInterfacePrototype,
1103 : false,
1104 : prototypes::id::ExtendableMessageEvent,
1105 : PrototypeTraits<prototypes::id::ExtendableMessageEvent>::Depth,
1106 : &sEmptyNativePropertyHooks,
1107 : "[object ExtendableMessageEventPrototype]",
1108 : ExtendableEventBinding::GetProtoObject
1109 : };
1110 :
1111 : bool
1112 1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1113 : {
1114 1 : MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?");
1115 :
1116 1 : const char* name = js::GetObjectClass(aObj)->name;
1117 1 : if (strcmp(name, "ServiceWorkerGlobalScope")) {
1118 1 : return false;
1119 : }
1120 :
1121 0 : return true;
1122 : }
1123 :
1124 : static const js::ClassOps sClassOps = {
1125 : _addProperty, /* addProperty */
1126 : nullptr, /* delProperty */
1127 : nullptr, /* getProperty */
1128 : nullptr, /* setProperty */
1129 : nullptr, /* enumerate */
1130 : nullptr, /* newEnumerate */
1131 : nullptr, /* resolve */
1132 : nullptr, /* mayResolve */
1133 : _finalize, /* finalize */
1134 : nullptr, /* call */
1135 : nullptr, /* hasInstance */
1136 : nullptr, /* construct */
1137 : nullptr, /* trace */
1138 : };
1139 :
1140 : static const js::ClassExtension sClassExtension = {
1141 : nullptr, /* weakmapKeyDelegateOp */
1142 : _objectMoved /* objectMovedOp */
1143 : };
1144 :
1145 : static const DOMJSClass sClass = {
1146 : { "ExtendableMessageEvent",
1147 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2) | JSCLASS_SKIP_NURSERY_FINALIZE,
1148 : &sClassOps,
1149 : JS_NULL_CLASS_SPEC,
1150 : &sClassExtension,
1151 : JS_NULL_OBJECT_OPS
1152 : },
1153 : { prototypes::id::Event, prototypes::id::ExtendableEvent, prototypes::id::ExtendableMessageEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1154 : IsBaseOf<nsISupports, mozilla::dom::workers::ExtendableMessageEvent >::value,
1155 : &sEmptyNativePropertyHooks,
1156 : FindAssociatedGlobalForNative<mozilla::dom::workers::ExtendableMessageEvent>::Get,
1157 : GetProtoObjectHandle,
1158 : GetCCParticipant<mozilla::dom::workers::ExtendableMessageEvent>::Get()
1159 : };
1160 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1161 : "Must have the right minimal number of reserved slots.");
1162 : static_assert(2 >= 2,
1163 : "Must have enough reserved slots.");
1164 :
1165 : const JSClass*
1166 0 : GetJSClass()
1167 : {
1168 0 : return sClass.ToJSClass();
1169 : }
1170 :
1171 : bool
1172 0 : Wrap(JSContext* aCx, mozilla::dom::workers::ExtendableMessageEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1173 : {
1174 : MOZ_ASSERT(static_cast<mozilla::dom::workers::ExtendableMessageEvent*>(aObject) ==
1175 : reinterpret_cast<mozilla::dom::workers::ExtendableMessageEvent*>(aObject),
1176 : "Multiple inheritance for mozilla::dom::workers::ExtendableMessageEvent is broken.");
1177 : MOZ_ASSERT(static_cast<mozilla::dom::workers::ExtendableEvent*>(aObject) ==
1178 : reinterpret_cast<mozilla::dom::workers::ExtendableEvent*>(aObject),
1179 : "Multiple inheritance for mozilla::dom::workers::ExtendableEvent is broken.");
1180 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
1181 : reinterpret_cast<mozilla::dom::Event*>(aObject),
1182 : "Multiple inheritance for mozilla::dom::Event is broken.");
1183 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1184 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1185 0 : MOZ_ASSERT(!aCache->GetWrapper(),
1186 : "You should probably not be using Wrap() directly; use "
1187 : "GetOrCreateDOMReflector instead");
1188 :
1189 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1190 : "nsISupports must be on our primary inheritance chain");
1191 :
1192 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1193 0 : if (!global) {
1194 0 : return false;
1195 : }
1196 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
1197 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1198 :
1199 : // That might have ended up wrapping us already, due to the wonders
1200 : // of XBL. Check for that, and bail out as needed.
1201 0 : aReflector.set(aCache->GetWrapper());
1202 0 : if (aReflector) {
1203 : #ifdef DEBUG
1204 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1205 : #endif // DEBUG
1206 0 : return true;
1207 : }
1208 :
1209 0 : JSAutoCompartment ac(aCx, global);
1210 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1211 0 : if (!canonicalProto) {
1212 0 : return false;
1213 : }
1214 0 : JS::Rooted<JSObject*> proto(aCx);
1215 0 : if (aGivenProto) {
1216 0 : proto = aGivenProto;
1217 : // Unfortunately, while aGivenProto was in the compartment of aCx
1218 : // coming in, we changed compartments to that of "parent" so may need
1219 : // to wrap the proto here.
1220 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1221 0 : if (!JS_WrapObject(aCx, &proto)) {
1222 0 : return false;
1223 : }
1224 : }
1225 : } else {
1226 0 : proto = canonicalProto;
1227 : }
1228 :
1229 0 : BindingJSObjectCreator<mozilla::dom::workers::ExtendableMessageEvent> creator(aCx);
1230 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1231 0 : if (!aReflector) {
1232 0 : return false;
1233 : }
1234 :
1235 0 : aCache->SetWrapper(aReflector);
1236 :
1237 : // Important: do unforgeable property setup after we have handed
1238 : // over ownership of the C++ object to obj as needed, so that if
1239 : // we fail and it ends up GCed it won't have problems in the
1240 : // finalizer trying to drop its ownership of the C++ object.
1241 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
1242 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
1243 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
1244 0 : aCache->ReleaseWrapper(aObject);
1245 0 : aCache->ClearWrapper();
1246 0 : return false;
1247 : }
1248 0 : creator.InitializationSucceeded();
1249 :
1250 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1251 : aCache->GetWrapperPreserveColor() == aReflector);
1252 : // If proto != canonicalProto, we have to preserve our wrapper;
1253 : // otherwise we won't be able to properly recreate it later, since
1254 : // we won't know what proto to use. Note that we don't check
1255 : // aGivenProto here, since it's entirely possible (and even
1256 : // somewhat common) to have a non-null aGivenProto which is the
1257 : // same as canonicalProto.
1258 0 : if (proto != canonicalProto) {
1259 0 : PreserveWrapper(aObject);
1260 : }
1261 :
1262 0 : return true;
1263 : }
1264 :
1265 : void
1266 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1267 : {
1268 0 : JS::Handle<JSObject*> parentProto(ExtendableEventBinding::GetProtoObjectHandle(aCx));
1269 0 : if (!parentProto) {
1270 0 : return;
1271 : }
1272 :
1273 0 : JS::Handle<JSObject*> constructorProto(ExtendableEventBinding::GetConstructorObjectHandle(aCx));
1274 0 : if (!constructorProto) {
1275 0 : return;
1276 : }
1277 :
1278 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ExtendableMessageEvent);
1279 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ExtendableMessageEvent);
1280 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1281 : &sPrototypeClass.mBase, protoCache,
1282 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1283 : interfaceCache,
1284 : sNativeProperties.Upcast(),
1285 : nullptr,
1286 : "ExtendableMessageEvent", aDefineOnGlobal,
1287 : nullptr,
1288 0 : false);
1289 :
1290 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
1291 : {
1292 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1293 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1294 0 : if (!unforgeableHolder) {
1295 0 : *protoCache = nullptr;
1296 0 : if (interfaceCache) {
1297 0 : *interfaceCache = nullptr;
1298 : }
1299 0 : return;
1300 : }
1301 : }
1302 :
1303 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1304 0 : *protoCache = nullptr;
1305 0 : if (interfaceCache) {
1306 0 : *interfaceCache = nullptr;
1307 : }
1308 0 : return;
1309 : }
1310 :
1311 0 : if (*protoCache) {
1312 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1313 0 : JS::ObjectValue(*unforgeableHolder));
1314 : }
1315 : }
1316 :
1317 : JS::Handle<JSObject*>
1318 0 : GetProtoObjectHandle(JSContext* aCx)
1319 : {
1320 : /* Get the interface prototype object for this class. This will create the
1321 : object as needed. */
1322 0 : bool aDefineOnGlobal = true;
1323 :
1324 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1325 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1326 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1327 0 : return nullptr;
1328 : }
1329 :
1330 : /* Check to see whether the interface objects are already installed */
1331 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1332 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ExtendableMessageEvent)) {
1333 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1334 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1335 : }
1336 :
1337 : /*
1338 : * The object might _still_ be null, but that's OK.
1339 : *
1340 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1341 : * traced by TraceProtoAndIfaceCache() and its contents are never
1342 : * changed after they have been set.
1343 : *
1344 : * Calling address() avoids the read read barrier that does gray
1345 : * unmarking, but it's not possible for the object to be gray here.
1346 : */
1347 :
1348 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ExtendableMessageEvent);
1349 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1350 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1351 : }
1352 :
1353 : JS::Handle<JSObject*>
1354 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1355 : {
1356 : /* Get the interface object for this class. This will create the object as
1357 : needed. */
1358 :
1359 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1360 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1361 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1362 0 : return nullptr;
1363 : }
1364 :
1365 : /* Check to see whether the interface objects are already installed */
1366 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1367 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ExtendableMessageEvent)) {
1368 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1369 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1370 : }
1371 :
1372 : /*
1373 : * The object might _still_ be null, but that's OK.
1374 : *
1375 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1376 : * traced by TraceProtoAndIfaceCache() and its contents are never
1377 : * changed after they have been set.
1378 : *
1379 : * Calling address() avoids the read read barrier that does gray
1380 : * unmarking, but it's not possible for the object to be gray here.
1381 : */
1382 :
1383 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ExtendableMessageEvent);
1384 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1385 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1386 : }
1387 :
1388 : JSObject*
1389 0 : GetConstructorObject(JSContext* aCx)
1390 : {
1391 0 : return GetConstructorObjectHandle(aCx);
1392 : }
1393 :
1394 : } // namespace ExtendableMessageEventBinding
1395 :
1396 :
1397 :
1398 : } // namespace dom
1399 : } // namespace mozilla
|