/work/obj-fuzz/dom/bindings/LocalMediaStreamBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM LocalMediaStream.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "DOMMediaStream.h" |
4 | | #include "LocalMediaStreamBinding.h" |
5 | | #include "MediaStreamBinding.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/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/XrayExpandoClass.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace dom { |
15 | | |
16 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
17 | | using namespace mozilla::dom::binding_detail; |
18 | | |
19 | | |
20 | | namespace LocalMediaStream_Binding { |
21 | | |
22 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MediaStream_Binding::NativeType>::value, |
23 | | "Can't inherit from an interface with a different ownership model."); |
24 | | |
25 | | MOZ_CAN_RUN_SCRIPT static bool |
26 | | stop(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::DOMLocalMediaStream* self, const JSJitMethodCallArgs& args) |
27 | 0 | { |
28 | 0 | AUTO_PROFILER_LABEL_FAST("LocalMediaStream.stop", DOM, cx); |
29 | 0 |
|
30 | 0 | self->Stop(); |
31 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
32 | 0 | args.rval().setUndefined(); |
33 | 0 | return true; |
34 | 0 | } |
35 | | |
36 | | static const JSJitInfo stop_methodinfo = { |
37 | | { (JSJitGetterOp)stop }, |
38 | | { prototypes::id::LocalMediaStream }, |
39 | | { PrototypeTraits<prototypes::id::LocalMediaStream>::Depth }, |
40 | | JSJitInfo::Method, |
41 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
42 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
43 | | true, /* isInfallible. False in setters. */ |
44 | | false, /* isMovable. Not relevant for setters. */ |
45 | | false, /* isEliminatable. Not relevant for setters. */ |
46 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
47 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
48 | | false, /* isTypedMethod. Only relevant for methods. */ |
49 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
50 | | }; |
51 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
52 | | static_assert(0 < 1, "There is no slot for us"); |
53 | | |
54 | | static bool |
55 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
56 | 0 | { |
57 | 0 | mozilla::DOMLocalMediaStream* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::DOMLocalMediaStream>(obj); |
58 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
59 | 0 | // obviously can't preserve if we're not initialized. |
60 | 0 | if (self && self->GetWrapperPreserveColor()) { |
61 | 0 | PreserveWrapper(self); |
62 | 0 | } |
63 | 0 | return true; |
64 | 0 | } |
65 | | |
66 | | static void |
67 | | _finalize(js::FreeOp* fop, JSObject* obj) |
68 | 0 | { |
69 | 0 | mozilla::DOMLocalMediaStream* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::DOMLocalMediaStream>(obj); |
70 | 0 | if (self) { |
71 | 0 | ClearWrapper(self, self, obj); |
72 | 0 | AddForDeferredFinalization<mozilla::DOMLocalMediaStream>(self); |
73 | 0 | } |
74 | 0 | } |
75 | | |
76 | | static size_t |
77 | | _objectMoved(JSObject* obj, JSObject* old) |
78 | 0 | { |
79 | 0 | mozilla::DOMLocalMediaStream* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::DOMLocalMediaStream>(obj); |
80 | 0 | if (self) { |
81 | 0 | UpdateWrapper(self, self, obj, old); |
82 | 0 | } |
83 | 0 |
|
84 | 0 | return 0; |
85 | 0 | } |
86 | | |
87 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
88 | | #if defined(__clang__) |
89 | | #pragma clang diagnostic push |
90 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
91 | | #endif |
92 | | static const JSFunctionSpec sMethods_specs[] = { |
93 | | JS_FNSPEC("stop", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&stop_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
94 | | JS_FS_END |
95 | | }; |
96 | | #if defined(__clang__) |
97 | | #pragma clang diagnostic pop |
98 | | #endif |
99 | | |
100 | | |
101 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
102 | | { nullptr, &sMethods_specs[0] }, |
103 | | { nullptr, nullptr } |
104 | | }; |
105 | | |
106 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
107 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
108 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
109 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
110 | | |
111 | | |
112 | | static uint16_t sNativeProperties_sortedPropertyIndices[1]; |
113 | | static PropertyInfo sNativeProperties_propertyInfos[1]; |
114 | | |
115 | | static const NativePropertiesN<1> sNativeProperties = { |
116 | | false, 0, |
117 | | false, 0, |
118 | | true, 0 /* sMethods */, |
119 | | false, 0, |
120 | | false, 0, |
121 | | false, 0, |
122 | | false, 0, |
123 | | -1, |
124 | | 1, |
125 | | sNativeProperties_sortedPropertyIndices, |
126 | | { |
127 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
128 | | } |
129 | | }; |
130 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
131 | | "We have a property info count that is oversized"); |
132 | | |
133 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
134 | | { |
135 | | "Function", |
136 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
137 | | &sBoringInterfaceObjectClassClassOps, |
138 | | JS_NULL_CLASS_SPEC, |
139 | | JS_NULL_CLASS_EXT, |
140 | | &sInterfaceObjectClassObjectOps |
141 | | }, |
142 | | eInterface, |
143 | | true, |
144 | | prototypes::id::LocalMediaStream, |
145 | | PrototypeTraits<prototypes::id::LocalMediaStream>::Depth, |
146 | | sNativePropertyHooks, |
147 | | "function LocalMediaStream() {\n [native code]\n}", |
148 | | MediaStream_Binding::GetConstructorObject |
149 | | }; |
150 | | |
151 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
152 | | { |
153 | | "LocalMediaStreamPrototype", |
154 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
155 | | JS_NULL_CLASS_OPS, |
156 | | JS_NULL_CLASS_SPEC, |
157 | | JS_NULL_CLASS_EXT, |
158 | | JS_NULL_OBJECT_OPS |
159 | | }, |
160 | | eInterfacePrototype, |
161 | | false, |
162 | | prototypes::id::LocalMediaStream, |
163 | | PrototypeTraits<prototypes::id::LocalMediaStream>::Depth, |
164 | | sNativePropertyHooks, |
165 | | "[object LocalMediaStreamPrototype]", |
166 | | MediaStream_Binding::GetProtoObject |
167 | | }; |
168 | | |
169 | | static const js::ClassOps sClassOps = { |
170 | | _addProperty, /* addProperty */ |
171 | | nullptr, /* delProperty */ |
172 | | nullptr, /* enumerate */ |
173 | | nullptr, /* newEnumerate */ |
174 | | nullptr, /* resolve */ |
175 | | nullptr, /* mayResolve */ |
176 | | _finalize, /* finalize */ |
177 | | nullptr, /* call */ |
178 | | nullptr, /* hasInstance */ |
179 | | nullptr, /* construct */ |
180 | | nullptr, /* trace */ |
181 | | }; |
182 | | |
183 | | static const js::ClassExtension sClassExtension = { |
184 | | nullptr, /* weakmapKeyDelegateOp */ |
185 | | _objectMoved /* objectMovedOp */ |
186 | | }; |
187 | | |
188 | | static const DOMJSClass sClass = { |
189 | | { "LocalMediaStream", |
190 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
191 | | &sClassOps, |
192 | | JS_NULL_CLASS_SPEC, |
193 | | &sClassExtension, |
194 | | JS_NULL_OBJECT_OPS |
195 | | }, |
196 | | { prototypes::id::EventTarget, prototypes::id::MediaStream, prototypes::id::LocalMediaStream, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
197 | | IsBaseOf<nsISupports, mozilla::DOMLocalMediaStream >::value, |
198 | | sNativePropertyHooks, |
199 | | FindAssociatedGlobalForNative<mozilla::DOMLocalMediaStream>::Get, |
200 | | GetProtoObjectHandle, |
201 | | GetCCParticipant<mozilla::DOMLocalMediaStream>::Get() |
202 | | }; |
203 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
204 | | "Must have the right minimal number of reserved slots."); |
205 | | static_assert(1 >= 1, |
206 | | "Must have enough reserved slots."); |
207 | | |
208 | | const JSClass* |
209 | | GetJSClass() |
210 | 0 | { |
211 | 0 | return sClass.ToJSClass(); |
212 | 0 | } |
213 | | |
214 | | bool |
215 | | Wrap(JSContext* aCx, mozilla::DOMLocalMediaStream* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
216 | 0 | { |
217 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::DOMLocalMediaStream>::value, |
218 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
219 | 0 | MOZ_ASSERT(static_cast<mozilla::DOMLocalMediaStream*>(aObject) == |
220 | 0 | reinterpret_cast<mozilla::DOMLocalMediaStream*>(aObject), |
221 | 0 | "Multiple inheritance for mozilla::DOMLocalMediaStream is broken."); |
222 | 0 | MOZ_ASSERT(static_cast<mozilla::DOMMediaStream*>(aObject) == |
223 | 0 | reinterpret_cast<mozilla::DOMMediaStream*>(aObject), |
224 | 0 | "Multiple inheritance for mozilla::DOMMediaStream is broken."); |
225 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
226 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
227 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
228 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
229 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
230 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
231 | 0 | "You should probably not be using Wrap() directly; use " |
232 | 0 | "GetOrCreateDOMReflector instead"); |
233 | 0 |
|
234 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
235 | 0 | "nsISupports must be on our primary inheritance chain"); |
236 | 0 |
|
237 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
238 | 0 | if (!global) { |
239 | 0 | return false; |
240 | 0 | } |
241 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
242 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
243 | 0 |
|
244 | 0 | // That might have ended up wrapping us already, due to the wonders |
245 | 0 | // of XBL. Check for that, and bail out as needed. |
246 | 0 | aReflector.set(aCache->GetWrapper()); |
247 | 0 | if (aReflector) { |
248 | | #ifdef DEBUG |
249 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
250 | | #endif // DEBUG |
251 | | return true; |
252 | 0 | } |
253 | 0 |
|
254 | 0 | JSAutoRealm ar(aCx, global); |
255 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
256 | 0 | if (!canonicalProto) { |
257 | 0 | return false; |
258 | 0 | } |
259 | 0 | JS::Rooted<JSObject*> proto(aCx); |
260 | 0 | if (aGivenProto) { |
261 | 0 | proto = aGivenProto; |
262 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
263 | 0 | // coming in, we changed compartments to that of "parent" so may need |
264 | 0 | // to wrap the proto here. |
265 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
266 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
267 | 0 | return false; |
268 | 0 | } |
269 | 0 | } |
270 | 0 | } else { |
271 | 0 | proto = canonicalProto; |
272 | 0 | } |
273 | 0 |
|
274 | 0 | BindingJSObjectCreator<mozilla::DOMLocalMediaStream> creator(aCx); |
275 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
276 | 0 | if (!aReflector) { |
277 | 0 | return false; |
278 | 0 | } |
279 | 0 | |
280 | 0 | aCache->SetWrapper(aReflector); |
281 | 0 | creator.InitializationSucceeded(); |
282 | 0 |
|
283 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
284 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
285 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
286 | 0 | // otherwise we won't be able to properly recreate it later, since |
287 | 0 | // we won't know what proto to use. Note that we don't check |
288 | 0 | // aGivenProto here, since it's entirely possible (and even |
289 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
290 | 0 | // same as canonicalProto. |
291 | 0 | if (proto != canonicalProto) { |
292 | 0 | PreserveWrapper(aObject); |
293 | 0 | } |
294 | 0 |
|
295 | 0 | return true; |
296 | 0 | } |
297 | | |
298 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
299 | | nullptr, |
300 | | nullptr, |
301 | | nullptr, |
302 | | { sNativeProperties.Upcast(), nullptr }, |
303 | | prototypes::id::LocalMediaStream, |
304 | | constructors::id::LocalMediaStream, |
305 | | MediaStream_Binding::sNativePropertyHooks, |
306 | | &DefaultXrayExpandoObjectClass |
307 | | } }; |
308 | | |
309 | | void |
310 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
311 | 0 | { |
312 | 0 | JS::Handle<JSObject*> parentProto(MediaStream_Binding::GetProtoObjectHandle(aCx)); |
313 | 0 | if (!parentProto) { |
314 | 0 | return; |
315 | 0 | } |
316 | 0 | |
317 | 0 | JS::Handle<JSObject*> constructorProto(MediaStream_Binding::GetConstructorObjectHandle(aCx)); |
318 | 0 | if (!constructorProto) { |
319 | 0 | return; |
320 | 0 | } |
321 | 0 | |
322 | 0 | static bool sIdsInited = false; |
323 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
324 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
325 | 0 | return; |
326 | 0 | } |
327 | 0 | sIdsInited = true; |
328 | 0 | } |
329 | 0 |
|
330 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::LocalMediaStream); |
331 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::LocalMediaStream); |
332 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
333 | 0 | &sPrototypeClass.mBase, protoCache, |
334 | 0 | nullptr, |
335 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
336 | 0 | interfaceCache, |
337 | 0 | sNativeProperties.Upcast(), |
338 | 0 | nullptr, |
339 | 0 | "LocalMediaStream", aDefineOnGlobal, |
340 | 0 | nullptr, |
341 | 0 | false); |
342 | 0 | } |
343 | | |
344 | | JSObject* |
345 | | GetConstructorObject(JSContext* aCx) |
346 | 0 | { |
347 | 0 | return GetConstructorObjectHandle(aCx); |
348 | 0 | } |
349 | | |
350 | | } // namespace LocalMediaStream_Binding |
351 | | |
352 | | |
353 | | |
354 | | } // namespace dom |
355 | | } // namespace mozilla |