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