/work/obj-fuzz/dom/bindings/RTCTrackEventBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM RTCTrackEvent.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "DOMMediaStream.h" |
5 | | #include "EventBinding.h" |
6 | | #include "RTCRtpReceiverBinding.h" |
7 | | #include "RTCRtpTransceiverBinding.h" |
8 | | #include "RTCTrackEventBinding.h" |
9 | | #include "WrapperFactory.h" |
10 | | #include "XrayWrapper.h" |
11 | | #include "mozilla/OwningNonNull.h" |
12 | | #include "mozilla/Preferences.h" |
13 | | #include "mozilla/dom/BindingUtils.h" |
14 | | #include "mozilla/dom/DOMJSClass.h" |
15 | | #include "mozilla/dom/MediaStreamTrack.h" |
16 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
17 | | #include "mozilla/dom/PrimitiveConversions.h" |
18 | | #include "mozilla/dom/RTCTrackEvent.h" |
19 | | #include "mozilla/dom/ScriptSettings.h" |
20 | | #include "mozilla/dom/XrayExpandoClass.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | |
30 | | RTCTrackEventInit::RTCTrackEventInit() |
31 | | : EventInit(FastDictionaryInitializer()) |
32 | 0 | { |
33 | 0 | // Safe to pass a null context if we pass a null value |
34 | 0 | Init(nullptr, JS::NullHandleValue); |
35 | 0 | } |
36 | | |
37 | | |
38 | | |
39 | | bool |
40 | | RTCTrackEventInit::InitIds(JSContext* cx, RTCTrackEventInitAtoms* atomsCache) |
41 | 0 | { |
42 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
43 | 0 |
|
44 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
45 | 0 | // uninitialized. |
46 | 0 | if (!atomsCache->transceiver_id.init(cx, "transceiver") || |
47 | 0 | !atomsCache->track_id.init(cx, "track") || |
48 | 0 | !atomsCache->streams_id.init(cx, "streams") || |
49 | 0 | !atomsCache->receiver_id.init(cx, "receiver")) { |
50 | 0 | return false; |
51 | 0 | } |
52 | 0 | return true; |
53 | 0 | } |
54 | | |
55 | | bool |
56 | | RTCTrackEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
57 | 0 | { |
58 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
59 | 0 | // Since in that case we will not have to do any property gets |
60 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
61 | 0 | // checkers by static analysis tools |
62 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
63 | 0 | RTCTrackEventInitAtoms* atomsCache = nullptr; |
64 | 0 | if (cx) { |
65 | 0 | atomsCache = GetAtomCache<RTCTrackEventInitAtoms>(cx); |
66 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 | } |
70 | 0 | |
71 | 0 | // Per spec, we init the parent's members first |
72 | 0 | if (!EventInit::Init(cx, val)) { |
73 | 0 | return false; |
74 | 0 | } |
75 | 0 | |
76 | 0 | bool isNull = val.isNullOrUndefined(); |
77 | 0 | // We only need these if !isNull, in which case we have |cx|. |
78 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
79 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
80 | 0 | if (!isNull) { |
81 | 0 | MOZ_ASSERT(cx); |
82 | 0 | object.emplace(cx, &val.toObject()); |
83 | 0 | temp.emplace(cx); |
84 | 0 | } |
85 | 0 | if (!isNull) { |
86 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->receiver_id, temp.ptr())) { |
87 | 0 | return false; |
88 | 0 | } |
89 | 0 | } |
90 | 0 | if (!isNull && !temp->isUndefined()) { |
91 | 0 | if (temp.ref().isObject()) { |
92 | 0 | static_assert(IsRefcounted<mozilla::dom::RTCRtpReceiver>::value, "We can only store refcounted classes.");{ |
93 | 0 | nsresult rv = UnwrapObject<prototypes::id::RTCRtpReceiver, mozilla::dom::RTCRtpReceiver>(temp.ptr(), mReceiver); |
94 | 0 | if (NS_FAILED(rv)) { |
95 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'receiver' member of RTCTrackEventInit", "RTCRtpReceiver"); |
96 | 0 | return false; |
97 | 0 | } |
98 | 0 | } |
99 | 0 | } else { |
100 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'receiver' member of RTCTrackEventInit"); |
101 | 0 | return false; |
102 | 0 | } |
103 | 0 | mIsAnyMemberPresent = true; |
104 | 0 | } else if (cx) { |
105 | 0 | // Don't error out if we have no cx. In that |
106 | 0 | // situation the caller is default-constructing us and we'll |
107 | 0 | // just assume they know what they're doing. |
108 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
109 | 0 | "'receiver' member of RTCTrackEventInit"); |
110 | 0 | } |
111 | 0 | |
112 | 0 | if (!isNull) { |
113 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->streams_id, temp.ptr())) { |
114 | 0 | return false; |
115 | 0 | } |
116 | 0 | } |
117 | 0 | if (!isNull && !temp->isUndefined()) { |
118 | 0 | if (temp.ref().isObject()) { |
119 | 0 | JS::ForOfIterator iter(cx); |
120 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
121 | 0 | return false; |
122 | 0 | } |
123 | 0 | if (!iter.valueIsIterable()) { |
124 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'streams' member of RTCTrackEventInit"); |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | Sequence<OwningNonNull<mozilla::DOMMediaStream>> &arr = mStreams; |
128 | 0 | JS::Rooted<JS::Value> temp(cx); |
129 | 0 | while (true) { |
130 | 0 | bool done; |
131 | 0 | if (!iter.next(&temp, &done)) { |
132 | 0 | return false; |
133 | 0 | } |
134 | 0 | if (done) { |
135 | 0 | break; |
136 | 0 | } |
137 | 0 | OwningNonNull<mozilla::DOMMediaStream>* slotPtr = arr.AppendElement(mozilla::fallible); |
138 | 0 | if (!slotPtr) { |
139 | 0 | JS_ReportOutOfMemory(cx); |
140 | 0 | return false; |
141 | 0 | } |
142 | 0 | OwningNonNull<mozilla::DOMMediaStream>& slot = *slotPtr; |
143 | 0 | if (temp.isObject()) { |
144 | 0 | static_assert(IsRefcounted<mozilla::DOMMediaStream>::value, "We can only store refcounted classes.");{ |
145 | 0 | nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(&temp, slot); |
146 | 0 | if (NS_FAILED(rv)) { |
147 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'streams' member of RTCTrackEventInit", "MediaStream"); |
148 | 0 | return false; |
149 | 0 | } |
150 | 0 | } |
151 | 0 | } else { |
152 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'streams' member of RTCTrackEventInit"); |
153 | 0 | return false; |
154 | 0 | } |
155 | 0 | } |
156 | 0 | } else { |
157 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'streams' member of RTCTrackEventInit"); |
158 | 0 | return false; |
159 | 0 | } |
160 | 0 | } else { |
161 | 0 | /* Array is already empty; nothing to do */ |
162 | 0 | } |
163 | 0 | mIsAnyMemberPresent = true; |
164 | 0 |
|
165 | 0 | if (!isNull) { |
166 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->track_id, temp.ptr())) { |
167 | 0 | return false; |
168 | 0 | } |
169 | 0 | } |
170 | 0 | if (!isNull && !temp->isUndefined()) { |
171 | 0 | if (temp.ref().isObject()) { |
172 | 0 | static_assert(IsRefcounted<mozilla::dom::MediaStreamTrack>::value, "We can only store refcounted classes.");{ |
173 | 0 | nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(temp.ptr(), mTrack); |
174 | 0 | if (NS_FAILED(rv)) { |
175 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'track' member of RTCTrackEventInit", "MediaStreamTrack"); |
176 | 0 | return false; |
177 | 0 | } |
178 | 0 | } |
179 | 0 | } else { |
180 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'track' member of RTCTrackEventInit"); |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | mIsAnyMemberPresent = true; |
184 | 0 | } else if (cx) { |
185 | 0 | // Don't error out if we have no cx. In that |
186 | 0 | // situation the caller is default-constructing us and we'll |
187 | 0 | // just assume they know what they're doing. |
188 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
189 | 0 | "'track' member of RTCTrackEventInit"); |
190 | 0 | } |
191 | 0 | |
192 | 0 | if (!isNull) { |
193 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->transceiver_id, temp.ptr())) { |
194 | 0 | return false; |
195 | 0 | } |
196 | 0 | } |
197 | 0 | if (!isNull && !temp->isUndefined()) { |
198 | 0 | if (temp.ref().isObject()) { |
199 | 0 | static_assert(IsRefcounted<mozilla::dom::RTCRtpTransceiver>::value, "We can only store refcounted classes.");{ |
200 | 0 | nsresult rv = UnwrapObject<prototypes::id::RTCRtpTransceiver, mozilla::dom::RTCRtpTransceiver>(temp.ptr(), mTransceiver); |
201 | 0 | if (NS_FAILED(rv)) { |
202 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'transceiver' member of RTCTrackEventInit", "RTCRtpTransceiver"); |
203 | 0 | return false; |
204 | 0 | } |
205 | 0 | } |
206 | 0 | } else { |
207 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'transceiver' member of RTCTrackEventInit"); |
208 | 0 | return false; |
209 | 0 | } |
210 | 0 | mIsAnyMemberPresent = true; |
211 | 0 | } else if (cx) { |
212 | 0 | // Don't error out if we have no cx. In that |
213 | 0 | // situation the caller is default-constructing us and we'll |
214 | 0 | // just assume they know what they're doing. |
215 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
216 | 0 | "'transceiver' member of RTCTrackEventInit"); |
217 | 0 | } |
218 | 0 | return true; |
219 | 0 | } |
220 | | |
221 | | bool |
222 | | RTCTrackEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
223 | 0 | { |
224 | 0 | RTCTrackEventInitAtoms* atomsCache = GetAtomCache<RTCTrackEventInitAtoms>(cx); |
225 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
226 | 0 | return false; |
227 | 0 | } |
228 | 0 | |
229 | 0 | // Per spec, we define the parent's members first |
230 | 0 | if (!EventInit::ToObjectInternal(cx, rval)) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
234 | 0 |
|
235 | 0 | do { |
236 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
237 | 0 | JS::Rooted<JS::Value> temp(cx); |
238 | 0 | OwningNonNull<mozilla::dom::RTCRtpReceiver> const & currentValue = mReceiver; |
239 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
240 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
241 | 0 | return false; |
242 | 0 | } |
243 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->receiver_id, temp, JSPROP_ENUMERATE)) { |
244 | 0 | return false; |
245 | 0 | } |
246 | 0 | break; |
247 | 0 | } while(false); |
248 | 0 |
|
249 | 0 | do { |
250 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
251 | 0 | JS::Rooted<JS::Value> temp(cx); |
252 | 0 | Sequence<OwningNonNull<mozilla::DOMMediaStream>> const & currentValue = mStreams; |
253 | 0 |
|
254 | 0 | uint32_t length = currentValue.Length(); |
255 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
256 | 0 | if (!returnArray) { |
257 | 0 | return false; |
258 | 0 | } |
259 | 0 | // Scope for 'tmp' |
260 | 0 | { |
261 | 0 | JS::Rooted<JS::Value> tmp(cx); |
262 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
263 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
264 | 0 | // are different ways to succeed at wrapping the object. |
265 | 0 | do { |
266 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) { |
267 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
268 | 0 | return false; |
269 | 0 | } |
270 | 0 | break; |
271 | 0 | } while (false); |
272 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
273 | 0 | JSPROP_ENUMERATE)) { |
274 | 0 | return false; |
275 | 0 | } |
276 | 0 | } |
277 | 0 | } |
278 | 0 | temp.setObject(*returnArray); |
279 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->streams_id, temp, JSPROP_ENUMERATE)) { |
280 | 0 | return false; |
281 | 0 | } |
282 | 0 | break; |
283 | 0 | } while(false); |
284 | 0 |
|
285 | 0 | do { |
286 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
287 | 0 | JS::Rooted<JS::Value> temp(cx); |
288 | 0 | OwningNonNull<mozilla::dom::MediaStreamTrack> const & currentValue = mTrack; |
289 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
290 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
291 | 0 | return false; |
292 | 0 | } |
293 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->track_id, temp, JSPROP_ENUMERATE)) { |
294 | 0 | return false; |
295 | 0 | } |
296 | 0 | break; |
297 | 0 | } while(false); |
298 | 0 |
|
299 | 0 | do { |
300 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
301 | 0 | JS::Rooted<JS::Value> temp(cx); |
302 | 0 | OwningNonNull<mozilla::dom::RTCRtpTransceiver> const & currentValue = mTransceiver; |
303 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
304 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
305 | 0 | return false; |
306 | 0 | } |
307 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->transceiver_id, temp, JSPROP_ENUMERATE)) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | break; |
311 | 0 | } while(false); |
312 | 0 |
|
313 | 0 | return true; |
314 | 0 | } |
315 | | |
316 | | void |
317 | | RTCTrackEventInit::TraceDictionary(JSTracer* trc) |
318 | 0 | { |
319 | 0 | EventInit::TraceDictionary(trc); |
320 | 0 | } |
321 | | |
322 | | |
323 | | |
324 | | RTCTrackEventInit& |
325 | | RTCTrackEventInit::operator=(const RTCTrackEventInit& aOther) |
326 | 0 | { |
327 | 0 | EventInit::operator=(aOther); |
328 | 0 | mReceiver = aOther.mReceiver; |
329 | 0 | mStreams = aOther.mStreams; |
330 | 0 | mTrack = aOther.mTrack; |
331 | 0 | mTransceiver = aOther.mTransceiver; |
332 | 0 | return *this; |
333 | 0 | } |
334 | | |
335 | | namespace binding_detail { |
336 | | } // namespace binding_detail |
337 | | |
338 | | |
339 | | namespace RTCTrackEvent_Binding { |
340 | | |
341 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value, |
342 | | "Can't inherit from an interface with a different ownership model."); |
343 | | |
344 | | MOZ_CAN_RUN_SCRIPT static bool |
345 | | get_receiver(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCTrackEvent* self, JSJitGetterCallArgs args) |
346 | 0 | { |
347 | 0 | AUTO_PROFILER_LABEL_FAST("get RTCTrackEvent.receiver", DOM, cx); |
348 | 0 |
|
349 | 0 | auto result(StrongOrRawPtr<mozilla::dom::RTCRtpReceiver>(self->Receiver())); |
350 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
351 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
352 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
353 | 0 | return false; |
354 | 0 | } |
355 | 0 | return true; |
356 | 0 | } |
357 | | |
358 | | static const JSJitInfo receiver_getterinfo = { |
359 | | { (JSJitGetterOp)get_receiver }, |
360 | | { prototypes::id::RTCTrackEvent }, |
361 | | { PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth }, |
362 | | JSJitInfo::Getter, |
363 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
364 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
365 | | false, /* isInfallible. False in setters. */ |
366 | | false, /* isMovable. Not relevant for setters. */ |
367 | | false, /* isEliminatable. Not relevant for setters. */ |
368 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
369 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
370 | | false, /* isTypedMethod. Only relevant for methods. */ |
371 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
372 | | }; |
373 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
374 | | static_assert(0 < 2, "There is no slot for us"); |
375 | | |
376 | | MOZ_CAN_RUN_SCRIPT static bool |
377 | | get_track(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCTrackEvent* self, JSJitGetterCallArgs args) |
378 | 0 | { |
379 | 0 | AUTO_PROFILER_LABEL_FAST("get RTCTrackEvent.track", DOM, cx); |
380 | 0 |
|
381 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MediaStreamTrack>(self->Track())); |
382 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
383 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
384 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
385 | 0 | return false; |
386 | 0 | } |
387 | 0 | return true; |
388 | 0 | } |
389 | | |
390 | | static const JSJitInfo track_getterinfo = { |
391 | | { (JSJitGetterOp)get_track }, |
392 | | { prototypes::id::RTCTrackEvent }, |
393 | | { PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth }, |
394 | | JSJitInfo::Getter, |
395 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
396 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
397 | | false, /* isInfallible. False in setters. */ |
398 | | false, /* isMovable. Not relevant for setters. */ |
399 | | false, /* isEliminatable. Not relevant for setters. */ |
400 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
401 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
402 | | false, /* isTypedMethod. Only relevant for methods. */ |
403 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
404 | | }; |
405 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
406 | | static_assert(0 < 2, "There is no slot for us"); |
407 | | |
408 | | MOZ_CAN_RUN_SCRIPT static bool |
409 | | get_streams(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCTrackEvent* self, JSJitGetterCallArgs args) |
410 | 0 | { |
411 | 0 | AUTO_PROFILER_LABEL_FAST("get RTCTrackEvent.streams", DOM, cx); |
412 | 0 |
|
413 | 0 | // Have to either root across the getter call or reget after. |
414 | 0 | bool isXray; |
415 | 0 | JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray)); |
416 | 0 | if (!slotStorage) { |
417 | 0 | return false; |
418 | 0 | } |
419 | 0 | const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0); |
420 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
421 | 0 | { |
422 | 0 | // Scope for cachedVal |
423 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
424 | 0 | if (!cachedVal.isUndefined()) { |
425 | 0 | args.rval().set(cachedVal); |
426 | 0 | // The cached value is in the compartment of slotStorage, |
427 | 0 | // so wrap into the caller compartment as needed. |
428 | 0 | if (MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
429 | 0 | return true; |
430 | 0 | } |
431 | 0 | return false; |
432 | 0 | } |
433 | 0 | } |
434 | 0 | |
435 | 0 | nsTArray<StrongPtrForMember<mozilla::DOMMediaStream>::Type> result; |
436 | 0 | self->GetStreams(result); |
437 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
438 | 0 | { |
439 | 0 | JS::Rooted<JSObject*> conversionScope(cx, isXray ? JS::CurrentGlobalOrNull(cx) : slotStorage); |
440 | 0 | JSAutoRealm ar(cx, conversionScope); |
441 | 0 | do { // block we break out of when done wrapping |
442 | 0 |
|
443 | 0 | uint32_t length = result.Length(); |
444 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
445 | 0 | if (!returnArray) { |
446 | 0 | return false; |
447 | 0 | } |
448 | 0 | // Scope for 'tmp' |
449 | 0 | { |
450 | 0 | JS::Rooted<JS::Value> tmp(cx); |
451 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
452 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
453 | 0 | // are different ways to succeed at wrapping the object. |
454 | 0 | do { |
455 | 0 | if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) { |
456 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
457 | 0 | return false; |
458 | 0 | } |
459 | 0 | break; |
460 | 0 | } while (false); |
461 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
462 | 0 | JSPROP_ENUMERATE)) { |
463 | 0 | return false; |
464 | 0 | } |
465 | 0 | } |
466 | 0 | } |
467 | 0 | args.rval().setObject(*returnArray); |
468 | 0 | break; |
469 | 0 | } while (false); |
470 | 0 | JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject()); |
471 | 0 | if (!JS_FreezeObject(cx, rvalObj)) { |
472 | 0 | return false; |
473 | 0 | } |
474 | 0 | } |
475 | 0 | { // And now store things in the realm of our slotStorage. |
476 | 0 | JSAutoRealm ar(cx, slotStorage); |
477 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
478 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
479 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) { |
480 | 0 | return false; |
481 | 0 | } |
482 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
483 | 0 | if (!isXray) { |
484 | 0 | // In the Xray case we don't need to do this, because getting the |
485 | 0 | // expando object already preserved our wrapper. |
486 | 0 | PreserveWrapper(self); |
487 | 0 | } |
488 | 0 | } |
489 | 0 | // And now make sure args.rval() is in the caller realm. |
490 | 0 | if (MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
491 | 0 | return true; |
492 | 0 | } |
493 | 0 | return false; |
494 | 0 | } |
495 | | |
496 | | static const JSJitInfo streams_getterinfo = { |
497 | | { (JSJitGetterOp)get_streams }, |
498 | | { prototypes::id::RTCTrackEvent }, |
499 | | { PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth }, |
500 | | JSJitInfo::Getter, |
501 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
502 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
503 | | false, /* isInfallible. False in setters. */ |
504 | | true, /* isMovable. Not relevant for setters. */ |
505 | | true, /* isEliminatable. Not relevant for setters. */ |
506 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
507 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
508 | | false, /* isTypedMethod. Only relevant for methods. */ |
509 | | (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */ |
510 | | }; |
511 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
512 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us"); |
513 | | |
514 | | MOZ_CAN_RUN_SCRIPT static bool |
515 | | get_transceiver(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCTrackEvent* self, JSJitGetterCallArgs args) |
516 | 0 | { |
517 | 0 | AUTO_PROFILER_LABEL_FAST("get RTCTrackEvent.transceiver", DOM, cx); |
518 | 0 |
|
519 | 0 | auto result(StrongOrRawPtr<mozilla::dom::RTCRtpTransceiver>(self->Transceiver())); |
520 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
521 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
522 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
523 | 0 | return false; |
524 | 0 | } |
525 | 0 | return true; |
526 | 0 | } |
527 | | |
528 | | static const JSJitInfo transceiver_getterinfo = { |
529 | | { (JSJitGetterOp)get_transceiver }, |
530 | | { prototypes::id::RTCTrackEvent }, |
531 | | { PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth }, |
532 | | JSJitInfo::Getter, |
533 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
534 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
535 | | false, /* isInfallible. False in setters. */ |
536 | | false, /* isMovable. Not relevant for setters. */ |
537 | | false, /* isEliminatable. Not relevant for setters. */ |
538 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
539 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
540 | | false, /* isTypedMethod. Only relevant for methods. */ |
541 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
542 | | }; |
543 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
544 | | static_assert(0 < 2, "There is no slot for us"); |
545 | | |
546 | | MOZ_CAN_RUN_SCRIPT static bool |
547 | | get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::RTCTrackEvent* self, JSJitGetterCallArgs args) |
548 | 0 | { |
549 | 0 | AUTO_PROFILER_LABEL_FAST("get RTCTrackEvent.isTrusted", DOM, cx); |
550 | 0 |
|
551 | 0 | bool result(self->IsTrusted()); |
552 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
553 | 0 | args.rval().setBoolean(result); |
554 | 0 | return true; |
555 | 0 | } |
556 | | |
557 | | static const JSJitInfo isTrusted_getterinfo = { |
558 | | { (JSJitGetterOp)get_isTrusted }, |
559 | | { prototypes::id::RTCTrackEvent }, |
560 | | { PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth }, |
561 | | JSJitInfo::Getter, |
562 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
563 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
564 | | true, /* isInfallible. False in setters. */ |
565 | | true, /* isMovable. Not relevant for setters. */ |
566 | | true, /* isEliminatable. Not relevant for setters. */ |
567 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
568 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
569 | | false, /* isTypedMethod. Only relevant for methods. */ |
570 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
571 | | }; |
572 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
573 | | static_assert(0 < 2, "There is no slot for us"); |
574 | | |
575 | | static bool |
576 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
577 | 0 | { |
578 | 0 | mozilla::dom::RTCTrackEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCTrackEvent>(obj); |
579 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
580 | 0 | // obviously can't preserve if we're not initialized. |
581 | 0 | if (self && self->GetWrapperPreserveColor()) { |
582 | 0 | PreserveWrapper(self); |
583 | 0 | } |
584 | 0 | return true; |
585 | 0 | } |
586 | | |
587 | | static void |
588 | | _finalize(js::FreeOp* fop, JSObject* obj) |
589 | 0 | { |
590 | 0 | mozilla::dom::RTCTrackEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCTrackEvent>(obj); |
591 | 0 | if (self) { |
592 | 0 | ClearWrapper(self, self, obj); |
593 | 0 | AddForDeferredFinalization<mozilla::dom::RTCTrackEvent>(self); |
594 | 0 | } |
595 | 0 | } |
596 | | |
597 | | static size_t |
598 | | _objectMoved(JSObject* obj, JSObject* old) |
599 | 0 | { |
600 | 0 | mozilla::dom::RTCTrackEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::RTCTrackEvent>(obj); |
601 | 0 | if (self) { |
602 | 0 | UpdateWrapper(self, self, obj, old); |
603 | 0 | } |
604 | 0 |
|
605 | 0 | return 0; |
606 | 0 | } |
607 | | |
608 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
609 | | #if defined(__clang__) |
610 | | #pragma clang diagnostic push |
611 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
612 | | #endif |
613 | | static const JSPropertySpec sAttributes_specs[] = { |
614 | | { "receiver", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &receiver_getterinfo, nullptr, nullptr }, |
615 | | { "track", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &track_getterinfo, nullptr, nullptr }, |
616 | | { "streams", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &streams_getterinfo, nullptr, nullptr }, |
617 | | { "transceiver", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &transceiver_getterinfo, nullptr, nullptr }, |
618 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
619 | | }; |
620 | | #if defined(__clang__) |
621 | | #pragma clang diagnostic pop |
622 | | #endif |
623 | | |
624 | | |
625 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
626 | | { nullptr, &sAttributes_specs[0] }, |
627 | | { nullptr, nullptr } |
628 | | }; |
629 | | |
630 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
631 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
632 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
633 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
634 | | |
635 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
636 | | #if defined(__clang__) |
637 | | #pragma clang diagnostic push |
638 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
639 | | #endif |
640 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
641 | | { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr }, |
642 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
643 | | }; |
644 | | #if defined(__clang__) |
645 | | #pragma clang diagnostic pop |
646 | | #endif |
647 | | |
648 | | |
649 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
650 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
651 | | { nullptr, nullptr } |
652 | | }; |
653 | | |
654 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
655 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
656 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
657 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
658 | | |
659 | | |
660 | | static uint16_t sNativeProperties_sortedPropertyIndices[5]; |
661 | | static PropertyInfo sNativeProperties_propertyInfos[5]; |
662 | | |
663 | | static const NativePropertiesN<2> sNativeProperties = { |
664 | | false, 0, |
665 | | false, 0, |
666 | | false, 0, |
667 | | true, 0 /* sAttributes */, |
668 | | false, 0, |
669 | | true, 1 /* sUnforgeableAttributes */, |
670 | | false, 0, |
671 | | -1, |
672 | | 5, |
673 | | sNativeProperties_sortedPropertyIndices, |
674 | | { |
675 | | { sAttributes, &sNativeProperties_propertyInfos[0] }, |
676 | | { sUnforgeableAttributes, &sNativeProperties_propertyInfos[4] } |
677 | | } |
678 | | }; |
679 | | static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
680 | | "We have a property info count that is oversized"); |
681 | | |
682 | | static bool |
683 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
684 | 0 | { |
685 | 0 | AUTO_PROFILER_LABEL_FAST("RTCTrackEvent constructor", DOM, cx); |
686 | 0 |
|
687 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
688 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
689 | 0 | if (!args.isConstructing()) { |
690 | 0 | // XXXbz wish I could get the name from the callee instead of |
691 | 0 | // Adding more relocations |
692 | 0 | return ThrowConstructorWithoutNew(cx, "RTCTrackEvent"); |
693 | 0 | } |
694 | 0 | |
695 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
696 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
697 | 0 | return false; |
698 | 0 | } |
699 | 0 | |
700 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
701 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "RTCTrackEvent"); |
702 | 0 | } |
703 | 0 | GlobalObject global(cx, obj); |
704 | 0 | if (global.Failed()) { |
705 | 0 | return false; |
706 | 0 | } |
707 | 0 | |
708 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
709 | 0 | binding_detail::FakeString arg0; |
710 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
711 | 0 | return false; |
712 | 0 | } |
713 | 0 | binding_detail::FastRTCTrackEventInit arg1; |
714 | 0 | if (!arg1.Init(cx, args[1], "Argument 2 of RTCTrackEvent.constructor", false)) { |
715 | 0 | return false; |
716 | 0 | } |
717 | 0 | Maybe<JSAutoRealm> ar; |
718 | 0 | if (objIsXray) { |
719 | 0 | obj = js::CheckedUnwrap(obj); |
720 | 0 | if (!obj) { |
721 | 0 | return false; |
722 | 0 | } |
723 | 0 | ar.emplace(cx, obj); |
724 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
725 | 0 | return false; |
726 | 0 | } |
727 | 0 | } |
728 | 0 | FastErrorResult rv; |
729 | 0 | auto result(StrongOrRawPtr<mozilla::dom::RTCTrackEvent>(mozilla::dom::RTCTrackEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
730 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
731 | 0 | return false; |
732 | 0 | } |
733 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
734 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
735 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
736 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
737 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
738 | 0 | return false; |
739 | 0 | } |
740 | 0 | return true; |
741 | 0 | } |
742 | | |
743 | | static const js::ClassOps sInterfaceObjectClassOps = { |
744 | | nullptr, /* addProperty */ |
745 | | nullptr, /* delProperty */ |
746 | | nullptr, /* enumerate */ |
747 | | nullptr, /* newEnumerate */ |
748 | | nullptr, /* resolve */ |
749 | | nullptr, /* mayResolve */ |
750 | | nullptr, /* finalize */ |
751 | | _constructor, /* call */ |
752 | | nullptr, /* hasInstance */ |
753 | | _constructor, /* construct */ |
754 | | nullptr, /* trace */ |
755 | | }; |
756 | | |
757 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
758 | | { |
759 | | "Function", |
760 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
761 | | &sInterfaceObjectClassOps, |
762 | | JS_NULL_CLASS_SPEC, |
763 | | JS_NULL_CLASS_EXT, |
764 | | &sInterfaceObjectClassObjectOps |
765 | | }, |
766 | | eInterface, |
767 | | true, |
768 | | prototypes::id::RTCTrackEvent, |
769 | | PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth, |
770 | | sNativePropertyHooks, |
771 | | "function RTCTrackEvent() {\n [native code]\n}", |
772 | | Event_Binding::GetConstructorObject |
773 | | }; |
774 | | |
775 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
776 | | { |
777 | | "RTCTrackEventPrototype", |
778 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
779 | | JS_NULL_CLASS_OPS, |
780 | | JS_NULL_CLASS_SPEC, |
781 | | JS_NULL_CLASS_EXT, |
782 | | JS_NULL_OBJECT_OPS |
783 | | }, |
784 | | eInterfacePrototype, |
785 | | false, |
786 | | prototypes::id::RTCTrackEvent, |
787 | | PrototypeTraits<prototypes::id::RTCTrackEvent>::Depth, |
788 | | sNativePropertyHooks, |
789 | | "[object RTCTrackEventPrototype]", |
790 | | Event_Binding::GetProtoObject |
791 | | }; |
792 | | |
793 | | bool |
794 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
795 | 0 | { |
796 | 0 | static bool sPrefValue; |
797 | 0 | static bool sPrefCacheSetUp = false; |
798 | 0 | if (!sPrefCacheSetUp) { |
799 | 0 | sPrefCacheSetUp = true; |
800 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "media.peerconnection.enabled"); |
801 | 0 | } |
802 | 0 |
|
803 | 0 | return sPrefValue; |
804 | 0 | } |
805 | | |
806 | | static const js::ClassOps sClassOps = { |
807 | | _addProperty, /* addProperty */ |
808 | | nullptr, /* delProperty */ |
809 | | nullptr, /* enumerate */ |
810 | | nullptr, /* newEnumerate */ |
811 | | nullptr, /* resolve */ |
812 | | nullptr, /* mayResolve */ |
813 | | _finalize, /* finalize */ |
814 | | nullptr, /* call */ |
815 | | nullptr, /* hasInstance */ |
816 | | nullptr, /* construct */ |
817 | | nullptr, /* trace */ |
818 | | }; |
819 | | |
820 | | static const js::ClassExtension sClassExtension = { |
821 | | nullptr, /* weakmapKeyDelegateOp */ |
822 | | _objectMoved /* objectMovedOp */ |
823 | | }; |
824 | | |
825 | | static const DOMJSClass sClass = { |
826 | | { "RTCTrackEvent", |
827 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2) | JSCLASS_SKIP_NURSERY_FINALIZE, |
828 | | &sClassOps, |
829 | | JS_NULL_CLASS_SPEC, |
830 | | &sClassExtension, |
831 | | JS_NULL_OBJECT_OPS |
832 | | }, |
833 | | { prototypes::id::Event, prototypes::id::RTCTrackEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
834 | | IsBaseOf<nsISupports, mozilla::dom::RTCTrackEvent >::value, |
835 | | sNativePropertyHooks, |
836 | | FindAssociatedGlobalForNative<mozilla::dom::RTCTrackEvent>::Get, |
837 | | GetProtoObjectHandle, |
838 | | GetCCParticipant<mozilla::dom::RTCTrackEvent>::Get() |
839 | | }; |
840 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
841 | | "Must have the right minimal number of reserved slots."); |
842 | | static_assert(2 >= 2, |
843 | | "Must have enough reserved slots."); |
844 | | |
845 | | const JSClass* |
846 | | GetJSClass() |
847 | 0 | { |
848 | 0 | return sClass.ToJSClass(); |
849 | 0 | } |
850 | | |
851 | | bool |
852 | | Wrap(JSContext* aCx, mozilla::dom::RTCTrackEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
853 | 0 | { |
854 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::RTCTrackEvent>::value, |
855 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
856 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::RTCTrackEvent*>(aObject) == |
857 | 0 | reinterpret_cast<mozilla::dom::RTCTrackEvent*>(aObject), |
858 | 0 | "Multiple inheritance for mozilla::dom::RTCTrackEvent is broken."); |
859 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) == |
860 | 0 | reinterpret_cast<mozilla::dom::Event*>(aObject), |
861 | 0 | "Multiple inheritance for mozilla::dom::Event is broken."); |
862 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
863 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
864 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
865 | 0 | "You should probably not be using Wrap() directly; use " |
866 | 0 | "GetOrCreateDOMReflector instead"); |
867 | 0 |
|
868 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
869 | 0 | "nsISupports must be on our primary inheritance chain"); |
870 | 0 |
|
871 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
872 | 0 | if (!global) { |
873 | 0 | return false; |
874 | 0 | } |
875 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
876 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
877 | 0 |
|
878 | 0 | // That might have ended up wrapping us already, due to the wonders |
879 | 0 | // of XBL. Check for that, and bail out as needed. |
880 | 0 | aReflector.set(aCache->GetWrapper()); |
881 | 0 | if (aReflector) { |
882 | | #ifdef DEBUG |
883 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
884 | | #endif // DEBUG |
885 | | return true; |
886 | 0 | } |
887 | 0 |
|
888 | 0 | JSAutoRealm ar(aCx, global); |
889 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
890 | 0 | if (!canonicalProto) { |
891 | 0 | return false; |
892 | 0 | } |
893 | 0 | JS::Rooted<JSObject*> proto(aCx); |
894 | 0 | if (aGivenProto) { |
895 | 0 | proto = aGivenProto; |
896 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
897 | 0 | // coming in, we changed compartments to that of "parent" so may need |
898 | 0 | // to wrap the proto here. |
899 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
900 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
901 | 0 | return false; |
902 | 0 | } |
903 | 0 | } |
904 | 0 | } else { |
905 | 0 | proto = canonicalProto; |
906 | 0 | } |
907 | 0 |
|
908 | 0 | BindingJSObjectCreator<mozilla::dom::RTCTrackEvent> creator(aCx); |
909 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
910 | 0 | if (!aReflector) { |
911 | 0 | return false; |
912 | 0 | } |
913 | 0 | |
914 | 0 | aCache->SetWrapper(aReflector); |
915 | 0 |
|
916 | 0 | // Important: do unforgeable property setup after we have handed |
917 | 0 | // over ownership of the C++ object to obj as needed, so that if |
918 | 0 | // we fail and it ends up GCed it won't have problems in the |
919 | 0 | // finalizer trying to drop its ownership of the C++ object. |
920 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
921 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
922 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
923 | 0 | aCache->ReleaseWrapper(aObject); |
924 | 0 | aCache->ClearWrapper(); |
925 | 0 | return false; |
926 | 0 | } |
927 | 0 | creator.InitializationSucceeded(); |
928 | 0 |
|
929 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
930 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
931 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
932 | 0 | // otherwise we won't be able to properly recreate it later, since |
933 | 0 | // we won't know what proto to use. Note that we don't check |
934 | 0 | // aGivenProto here, since it's entirely possible (and even |
935 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
936 | 0 | // same as canonicalProto. |
937 | 0 | if (proto != canonicalProto) { |
938 | 0 | PreserveWrapper(aObject); |
939 | 0 | } |
940 | 0 |
|
941 | 0 | return true; |
942 | 0 | } |
943 | | |
944 | | // This may allocate too many slots, because we only really need |
945 | | // slots for our non-interface-typed members that we cache. But |
946 | | // allocating slots only for those would make the slot index |
947 | | // computations much more complicated, so let's do this the simple |
948 | | // way for now. |
949 | | DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1); |
950 | | |
951 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
952 | | nullptr, |
953 | | nullptr, |
954 | | nullptr, |
955 | | { sNativeProperties.Upcast(), nullptr }, |
956 | | prototypes::id::RTCTrackEvent, |
957 | | constructors::id::RTCTrackEvent, |
958 | | Event_Binding::sNativePropertyHooks, |
959 | | &sXrayExpandoObjectClass |
960 | | } }; |
961 | | |
962 | | void |
963 | | ClearCachedStreamsValue(mozilla::dom::RTCTrackEvent* aObject) |
964 | 0 | { |
965 | 0 | JSObject* obj; |
966 | 0 | obj = aObject->GetWrapper(); |
967 | 0 | if (!obj) { |
968 | 0 | return; |
969 | 0 | } |
970 | 0 | js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0), JS::UndefinedValue()); |
971 | 0 | xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 0)); |
972 | 0 | } |
973 | | |
974 | | void |
975 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
976 | 0 | { |
977 | 0 | JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx)); |
978 | 0 | if (!parentProto) { |
979 | 0 | return; |
980 | 0 | } |
981 | 0 | |
982 | 0 | JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx)); |
983 | 0 | if (!constructorProto) { |
984 | 0 | return; |
985 | 0 | } |
986 | 0 | |
987 | 0 | static bool sIdsInited = false; |
988 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
989 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
990 | 0 | return; |
991 | 0 | } |
992 | 0 | sIdsInited = true; |
993 | 0 | } |
994 | 0 |
|
995 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::RTCTrackEvent); |
996 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::RTCTrackEvent); |
997 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
998 | 0 | &sPrototypeClass.mBase, protoCache, |
999 | 0 | nullptr, |
1000 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr, |
1001 | 0 | interfaceCache, |
1002 | 0 | sNativeProperties.Upcast(), |
1003 | 0 | nullptr, |
1004 | 0 | "RTCTrackEvent", aDefineOnGlobal, |
1005 | 0 | nullptr, |
1006 | 0 | false); |
1007 | 0 |
|
1008 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
1009 | 0 | { |
1010 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
1011 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
1012 | 0 | if (!unforgeableHolder) { |
1013 | 0 | *protoCache = nullptr; |
1014 | 0 | if (interfaceCache) { |
1015 | 0 | *interfaceCache = nullptr; |
1016 | 0 | } |
1017 | 0 | return; |
1018 | 0 | } |
1019 | 0 | } |
1020 | 0 |
|
1021 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
1022 | 0 | *protoCache = nullptr; |
1023 | 0 | if (interfaceCache) { |
1024 | 0 | *interfaceCache = nullptr; |
1025 | 0 | } |
1026 | 0 | return; |
1027 | 0 | } |
1028 | 0 |
|
1029 | 0 | if (*protoCache) { |
1030 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
1031 | 0 | JS::ObjectValue(*unforgeableHolder)); |
1032 | 0 | } |
1033 | 0 | } |
1034 | | |
1035 | | JSObject* |
1036 | | GetConstructorObject(JSContext* aCx) |
1037 | 0 | { |
1038 | 0 | return GetConstructorObjectHandle(aCx); |
1039 | 0 | } |
1040 | | |
1041 | | } // namespace RTCTrackEvent_Binding |
1042 | | |
1043 | | |
1044 | | |
1045 | | } // namespace dom |
1046 | | } // namespace mozilla |