Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MessagePort.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "EventHandlerBinding.h"
4 : #include "EventTargetBinding.h"
5 : #include "MessagePortBinding.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/XrayExpandoClass.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : namespace MessagePortBinding {
19 :
20 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
21 : "Can't inherit from an interface with a different ownership model.");
22 :
23 : static bool
24 0 : postMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessagePort* self, const JSJitMethodCallArgs& args)
25 : {
26 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
27 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessagePort.postMessage");
28 : }
29 0 : JS::Rooted<JS::Value> arg0(cx);
30 0 : arg0 = args[0];
31 0 : binding_detail::AutoSequence<JSObject*> arg1;
32 0 : SequenceRooter<JSObject*> arg1_holder(cx, &arg1);
33 0 : if (args.hasDefined(1)) {
34 0 : if (args[1].isObject()) {
35 0 : JS::ForOfIterator iter(cx);
36 0 : if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) {
37 0 : return false;
38 : }
39 0 : if (!iter.valueIsIterable()) {
40 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of MessagePort.postMessage");
41 0 : return false;
42 : }
43 0 : binding_detail::AutoSequence<JSObject*> &arr = arg1;
44 0 : JS::Rooted<JS::Value> temp(cx);
45 : while (true) {
46 : bool done;
47 0 : if (!iter.next(&temp, &done)) {
48 0 : return false;
49 : }
50 0 : if (done) {
51 0 : break;
52 : }
53 0 : JSObject** slotPtr = arr.AppendElement(mozilla::fallible);
54 0 : if (!slotPtr) {
55 0 : JS_ReportOutOfMemory(cx);
56 0 : return false;
57 : }
58 0 : JSObject*& slot = *slotPtr;
59 0 : if (temp.isObject()) {
60 0 : slot = &temp.toObject();
61 : } else {
62 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 2 of MessagePort.postMessage");
63 0 : return false;
64 : }
65 0 : }
66 : } else {
67 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of MessagePort.postMessage");
68 0 : return false;
69 : }
70 : } else {
71 : /* Array is already empty; nothing to do */
72 : }
73 0 : binding_detail::FastErrorResult rv;
74 0 : self->PostMessage(cx, arg0, Constify(arg1), rv);
75 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
76 0 : return false;
77 : }
78 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
79 0 : args.rval().setUndefined();
80 0 : return true;
81 : }
82 :
83 : static const JSJitInfo postMessage_methodinfo = {
84 : { (JSJitGetterOp)postMessage },
85 : { prototypes::id::MessagePort },
86 : { PrototypeTraits<prototypes::id::MessagePort>::Depth },
87 : JSJitInfo::Method,
88 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
89 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
90 : false, /* isInfallible. False in setters. */
91 : false, /* isMovable. Not relevant for setters. */
92 : false, /* isEliminatable. Not relevant for setters. */
93 : false, /* isAlwaysInSlot. Only relevant for getters. */
94 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
95 : false, /* isTypedMethod. Only relevant for methods. */
96 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
97 : };
98 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
99 : static_assert(0 < 1, "There is no slot for us");
100 :
101 : static bool
102 0 : start(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessagePort* self, const JSJitMethodCallArgs& args)
103 : {
104 0 : self->Start();
105 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
106 0 : args.rval().setUndefined();
107 0 : return true;
108 : }
109 :
110 : static const JSJitInfo start_methodinfo = {
111 : { (JSJitGetterOp)start },
112 : { prototypes::id::MessagePort },
113 : { PrototypeTraits<prototypes::id::MessagePort>::Depth },
114 : JSJitInfo::Method,
115 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
116 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
117 : true, /* isInfallible. False in setters. */
118 : false, /* isMovable. Not relevant for setters. */
119 : false, /* isEliminatable. Not relevant for setters. */
120 : false, /* isAlwaysInSlot. Only relevant for getters. */
121 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
122 : false, /* isTypedMethod. Only relevant for methods. */
123 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
124 : };
125 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
126 : static_assert(0 < 1, "There is no slot for us");
127 :
128 : static bool
129 0 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessagePort* self, const JSJitMethodCallArgs& args)
130 : {
131 0 : self->Close();
132 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
133 0 : args.rval().setUndefined();
134 0 : return true;
135 : }
136 :
137 : static const JSJitInfo close_methodinfo = {
138 : { (JSJitGetterOp)close },
139 : { prototypes::id::MessagePort },
140 : { PrototypeTraits<prototypes::id::MessagePort>::Depth },
141 : JSJitInfo::Method,
142 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
143 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
144 : true, /* isInfallible. False in setters. */
145 : false, /* isMovable. Not relevant for setters. */
146 : false, /* isEliminatable. Not relevant for setters. */
147 : false, /* isAlwaysInSlot. Only relevant for getters. */
148 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
149 : false, /* isTypedMethod. Only relevant for methods. */
150 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
151 : };
152 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
153 : static_assert(0 < 1, "There is no slot for us");
154 :
155 : static bool
156 0 : get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessagePort* self, JSJitGetterCallArgs args)
157 : {
158 0 : RefPtr<EventHandlerNonNull> result(self->GetOnmessage());
159 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
160 0 : if (result) {
161 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
162 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
163 0 : return false;
164 : }
165 0 : return true;
166 : } else {
167 0 : args.rval().setNull();
168 0 : return true;
169 : }
170 : }
171 :
172 : static bool
173 0 : set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessagePort* self, JSJitSetterCallArgs args)
174 : {
175 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
176 0 : if (args[0].isObject()) {
177 : { // scope for tempRoot
178 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
179 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
180 : }
181 : } else {
182 0 : arg0 = nullptr;
183 : }
184 0 : self->SetOnmessage(Constify(arg0));
185 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
186 :
187 0 : return true;
188 : }
189 :
190 : static const JSJitInfo onmessage_getterinfo = {
191 : { (JSJitGetterOp)get_onmessage },
192 : { prototypes::id::MessagePort },
193 : { PrototypeTraits<prototypes::id::MessagePort>::Depth },
194 : JSJitInfo::Getter,
195 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
196 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
197 : false, /* isInfallible. False in setters. */
198 : false, /* isMovable. Not relevant for setters. */
199 : false, /* isEliminatable. Not relevant for setters. */
200 : false, /* isAlwaysInSlot. Only relevant for getters. */
201 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
202 : false, /* isTypedMethod. Only relevant for methods. */
203 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
204 : };
205 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
206 : static_assert(0 < 1, "There is no slot for us");
207 : static const JSJitInfo onmessage_setterinfo = {
208 : { (JSJitGetterOp)set_onmessage },
209 : { prototypes::id::MessagePort },
210 : { PrototypeTraits<prototypes::id::MessagePort>::Depth },
211 : JSJitInfo::Setter,
212 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
213 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
214 : false, /* isInfallible. False in setters. */
215 : false, /* isMovable. Not relevant for setters. */
216 : false, /* isEliminatable. Not relevant for setters. */
217 : false, /* isAlwaysInSlot. Only relevant for getters. */
218 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
219 : false, /* isTypedMethod. Only relevant for methods. */
220 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
221 : };
222 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
223 : static_assert(0 < 1, "There is no slot for us");
224 :
225 : static bool
226 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
227 : {
228 0 : mozilla::dom::MessagePort* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessagePort>(obj);
229 : // We don't want to preserve if we don't have a wrapper, and we
230 : // obviously can't preserve if we're not initialized.
231 0 : if (self && self->GetWrapperPreserveColor()) {
232 0 : PreserveWrapper(self);
233 : }
234 0 : return true;
235 : }
236 :
237 : static void
238 0 : _finalize(js::FreeOp* fop, JSObject* obj)
239 : {
240 0 : mozilla::dom::MessagePort* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessagePort>(obj);
241 0 : if (self) {
242 0 : ClearWrapper(self, self, obj);
243 0 : AddForDeferredFinalization<mozilla::dom::MessagePort>(self);
244 : }
245 0 : }
246 :
247 : static void
248 0 : _objectMoved(JSObject* obj, const JSObject* old)
249 : {
250 0 : mozilla::dom::MessagePort* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessagePort>(obj);
251 0 : if (self) {
252 0 : UpdateWrapper(self, self, obj, old);
253 : }
254 0 : }
255 :
256 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
257 : #if defined(__clang__)
258 : #pragma clang diagnostic push
259 : #pragma clang diagnostic ignored "-Wmissing-braces"
260 : #endif
261 : static const JSFunctionSpec sMethods_specs[] = {
262 : JS_FNSPEC("postMessage", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&postMessage_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
263 : JS_FNSPEC("start", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&start_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
264 : JS_FNSPEC("close", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
265 : JS_FS_END
266 : };
267 : #if defined(__clang__)
268 : #pragma clang diagnostic pop
269 : #endif
270 :
271 :
272 : // Can't be const because the pref-enabled boolean needs to be writable
273 : static Prefable<const JSFunctionSpec> sMethods[] = {
274 : { nullptr, &sMethods_specs[0] },
275 : { nullptr, nullptr }
276 : };
277 :
278 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
279 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
280 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
281 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
282 :
283 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
284 : #if defined(__clang__)
285 : #pragma clang diagnostic push
286 : #pragma clang diagnostic ignored "-Wmissing-braces"
287 : #endif
288 : static const JSPropertySpec sAttributes_specs[] = {
289 : { "onmessage", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onmessage_getterinfo, GenericBindingSetter, &onmessage_setterinfo },
290 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
291 : };
292 : #if defined(__clang__)
293 : #pragma clang diagnostic pop
294 : #endif
295 :
296 :
297 : // Can't be const because the pref-enabled boolean needs to be writable
298 : static Prefable<const JSPropertySpec> sAttributes[] = {
299 : { nullptr, &sAttributes_specs[0] },
300 : { nullptr, nullptr }
301 : };
302 :
303 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
304 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
305 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
306 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
307 :
308 :
309 : static uint16_t sNativeProperties_sortedPropertyIndices[4];
310 : static PropertyInfo sNativeProperties_propertyInfos[4];
311 :
312 : static const NativePropertiesN<2> sNativeProperties = {
313 : false, 0,
314 : false, 0,
315 : true, 0 /* sMethods */,
316 : true, 1 /* sAttributes */,
317 : false, 0,
318 : false, 0,
319 : false, 0,
320 : -1,
321 : 4,
322 : sNativeProperties_sortedPropertyIndices,
323 : {
324 : { sMethods, &sNativeProperties_propertyInfos[0] },
325 : { sAttributes, &sNativeProperties_propertyInfos[3] }
326 : }
327 : };
328 : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
329 : "We have a property info count that is oversized");
330 :
331 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
332 : {
333 : "Function",
334 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
335 : &sBoringInterfaceObjectClassClassOps,
336 : JS_NULL_CLASS_SPEC,
337 : JS_NULL_CLASS_EXT,
338 : &sInterfaceObjectClassObjectOps
339 : },
340 : eInterface,
341 : true,
342 : prototypes::id::MessagePort,
343 : PrototypeTraits<prototypes::id::MessagePort>::Depth,
344 : sNativePropertyHooks,
345 : "function MessagePort() {\n [native code]\n}",
346 : EventTargetBinding::GetConstructorObject
347 : };
348 :
349 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
350 : {
351 : "MessagePortPrototype",
352 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
353 : JS_NULL_CLASS_OPS,
354 : JS_NULL_CLASS_SPEC,
355 : JS_NULL_CLASS_EXT,
356 : JS_NULL_OBJECT_OPS
357 : },
358 : eInterfacePrototype,
359 : false,
360 : prototypes::id::MessagePort,
361 : PrototypeTraits<prototypes::id::MessagePort>::Depth,
362 : sNativePropertyHooks,
363 : "[object MessagePortPrototype]",
364 : EventTargetBinding::GetProtoObject
365 : };
366 :
367 : JSObject*
368 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
369 : {
370 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
371 : }
372 :
373 : static const js::ClassOps sClassOps = {
374 : _addProperty, /* addProperty */
375 : nullptr, /* delProperty */
376 : nullptr, /* getProperty */
377 : nullptr, /* setProperty */
378 : nullptr, /* enumerate */
379 : nullptr, /* newEnumerate */
380 : nullptr, /* resolve */
381 : nullptr, /* mayResolve */
382 : _finalize, /* finalize */
383 : nullptr, /* call */
384 : nullptr, /* hasInstance */
385 : nullptr, /* construct */
386 : nullptr, /* trace */
387 : };
388 :
389 : static const js::ClassExtension sClassExtension = {
390 : nullptr, /* weakmapKeyDelegateOp */
391 : _objectMoved /* objectMovedOp */
392 : };
393 :
394 : static const DOMJSClass sClass = {
395 : { "MessagePort",
396 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
397 : &sClassOps,
398 : JS_NULL_CLASS_SPEC,
399 : &sClassExtension,
400 : JS_NULL_OBJECT_OPS
401 : },
402 : { prototypes::id::EventTarget, prototypes::id::MessagePort, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
403 : IsBaseOf<nsISupports, mozilla::dom::MessagePort >::value,
404 : sNativePropertyHooks,
405 : FindAssociatedGlobalForNative<mozilla::dom::MessagePort>::Get,
406 : GetProtoObjectHandle,
407 : GetCCParticipant<mozilla::dom::MessagePort>::Get()
408 : };
409 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
410 : "Must have the right minimal number of reserved slots.");
411 : static_assert(1 >= 1,
412 : "Must have enough reserved slots.");
413 :
414 : const JSClass*
415 0 : GetJSClass()
416 : {
417 0 : return sClass.ToJSClass();
418 : }
419 :
420 : bool
421 0 : Wrap(JSContext* aCx, mozilla::dom::MessagePort* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
422 : {
423 : MOZ_ASSERT(static_cast<mozilla::dom::MessagePort*>(aObject) ==
424 : reinterpret_cast<mozilla::dom::MessagePort*>(aObject),
425 : "Multiple inheritance for mozilla::dom::MessagePort is broken.");
426 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
427 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
428 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
429 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
430 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
431 0 : MOZ_ASSERT(!aCache->GetWrapper(),
432 : "You should probably not be using Wrap() directly; use "
433 : "GetOrCreateDOMReflector instead");
434 :
435 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
436 : "nsISupports must be on our primary inheritance chain");
437 :
438 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
439 0 : if (!global) {
440 0 : return false;
441 : }
442 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
443 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
444 :
445 : // That might have ended up wrapping us already, due to the wonders
446 : // of XBL. Check for that, and bail out as needed.
447 0 : aReflector.set(aCache->GetWrapper());
448 0 : if (aReflector) {
449 : #ifdef DEBUG
450 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
451 : #endif // DEBUG
452 0 : return true;
453 : }
454 :
455 0 : JSAutoCompartment ac(aCx, global);
456 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
457 0 : if (!canonicalProto) {
458 0 : return false;
459 : }
460 0 : JS::Rooted<JSObject*> proto(aCx);
461 0 : if (aGivenProto) {
462 0 : proto = aGivenProto;
463 : // Unfortunately, while aGivenProto was in the compartment of aCx
464 : // coming in, we changed compartments to that of "parent" so may need
465 : // to wrap the proto here.
466 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
467 0 : if (!JS_WrapObject(aCx, &proto)) {
468 0 : return false;
469 : }
470 : }
471 : } else {
472 0 : proto = canonicalProto;
473 : }
474 :
475 0 : BindingJSObjectCreator<mozilla::dom::MessagePort> creator(aCx);
476 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
477 0 : if (!aReflector) {
478 0 : return false;
479 : }
480 :
481 0 : aCache->SetWrapper(aReflector);
482 0 : creator.InitializationSucceeded();
483 :
484 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
485 : aCache->GetWrapperPreserveColor() == aReflector);
486 : // If proto != canonicalProto, we have to preserve our wrapper;
487 : // otherwise we won't be able to properly recreate it later, since
488 : // we won't know what proto to use. Note that we don't check
489 : // aGivenProto here, since it's entirely possible (and even
490 : // somewhat common) to have a non-null aGivenProto which is the
491 : // same as canonicalProto.
492 0 : if (proto != canonicalProto) {
493 0 : PreserveWrapper(aObject);
494 : }
495 :
496 0 : return true;
497 : }
498 :
499 : const NativePropertyHooks sNativePropertyHooks[] = { {
500 : nullptr,
501 : nullptr,
502 : nullptr,
503 : { sNativeProperties.Upcast(), nullptr },
504 : prototypes::id::MessagePort,
505 : constructors::id::MessagePort,
506 : EventTargetBinding::sNativePropertyHooks,
507 : &DefaultXrayExpandoObjectClass
508 : } };
509 :
510 : void
511 4 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
512 : {
513 4 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
514 4 : if (!parentProto) {
515 0 : return;
516 : }
517 :
518 4 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
519 4 : if (!constructorProto) {
520 0 : return;
521 : }
522 :
523 : static bool sIdsInited = false;
524 4 : if (!sIdsInited && NS_IsMainThread()) {
525 3 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
526 0 : return;
527 : }
528 3 : sIdsInited = true;
529 : }
530 :
531 4 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessagePort);
532 4 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessagePort);
533 4 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
534 : &sPrototypeClass.mBase, protoCache,
535 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
536 : interfaceCache,
537 : sNativeProperties.Upcast(),
538 : nullptr,
539 : "MessagePort", aDefineOnGlobal,
540 : nullptr,
541 4 : false);
542 : }
543 :
544 : JS::Handle<JSObject*>
545 0 : GetProtoObjectHandle(JSContext* aCx)
546 : {
547 : /* Get the interface prototype object for this class. This will create the
548 : object as needed. */
549 0 : bool aDefineOnGlobal = true;
550 :
551 : /* Make sure our global is sane. Hopefully we can remove this sometime */
552 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
553 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
554 0 : return nullptr;
555 : }
556 :
557 : /* Check to see whether the interface objects are already installed */
558 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
559 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MessagePort)) {
560 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
561 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
562 : }
563 :
564 : /*
565 : * The object might _still_ be null, but that's OK.
566 : *
567 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
568 : * traced by TraceProtoAndIfaceCache() and its contents are never
569 : * changed after they have been set.
570 : *
571 : * Calling address() avoids the read read barrier that does gray
572 : * unmarking, but it's not possible for the object to be gray here.
573 : */
574 :
575 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MessagePort);
576 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
577 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
578 : }
579 :
580 : JS::Handle<JSObject*>
581 4 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
582 : {
583 : /* Get the interface object for this class. This will create the object as
584 : needed. */
585 :
586 : /* Make sure our global is sane. Hopefully we can remove this sometime */
587 4 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
588 4 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
589 0 : return nullptr;
590 : }
591 :
592 : /* Check to see whether the interface objects are already installed */
593 4 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
594 4 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MessagePort)) {
595 8 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
596 4 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
597 : }
598 :
599 : /*
600 : * The object might _still_ be null, but that's OK.
601 : *
602 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
603 : * traced by TraceProtoAndIfaceCache() and its contents are never
604 : * changed after they have been set.
605 : *
606 : * Calling address() avoids the read read barrier that does gray
607 : * unmarking, but it's not possible for the object to be gray here.
608 : */
609 :
610 4 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MessagePort);
611 4 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
612 4 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
613 : }
614 :
615 : JSObject*
616 4 : GetConstructorObject(JSContext* aCx)
617 : {
618 4 : return GetConstructorObjectHandle(aCx);
619 : }
620 :
621 : } // namespace MessagePortBinding
622 :
623 :
624 :
625 : } // namespace dom
626 : } // namespace mozilla
|