/work/obj-fuzz/dom/bindings/WebrtcGlobalInformationBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM WebrtcGlobalInformation.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "WebrtcGlobalInformation.h" |
5 | | #include "WebrtcGlobalInformationBinding.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/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/ScriptSettings.h" |
13 | | #include "mozilla/dom/SimpleGlobalObject.h" |
14 | | #include "mozilla/dom/XrayExpandoClass.h" |
15 | | #include "nsContentUtils.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
21 | | using namespace mozilla::dom::binding_detail; |
22 | | |
23 | | |
24 | | |
25 | | WebrtcGlobalStatisticsReport::WebrtcGlobalStatisticsReport() |
26 | 0 | { |
27 | 0 | // Safe to pass a null context if we pass a null value |
28 | 0 | Init(nullptr, JS::NullHandleValue); |
29 | 0 | } |
30 | | |
31 | | |
32 | | |
33 | | bool |
34 | | WebrtcGlobalStatisticsReport::InitIds(JSContext* cx, WebrtcGlobalStatisticsReportAtoms* atomsCache) |
35 | 0 | { |
36 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
37 | 0 |
|
38 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
39 | 0 | // uninitialized. |
40 | 0 | if (!atomsCache->reports_id.init(cx, "reports")) { |
41 | 0 | return false; |
42 | 0 | } |
43 | 0 | return true; |
44 | 0 | } |
45 | | |
46 | | bool |
47 | | WebrtcGlobalStatisticsReport::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
48 | 0 | { |
49 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
50 | 0 | // Since in that case we will not have to do any property gets |
51 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
52 | 0 | // checkers by static analysis tools |
53 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
54 | 0 | WebrtcGlobalStatisticsReportAtoms* atomsCache = nullptr; |
55 | 0 | if (cx) { |
56 | 0 | atomsCache = GetAtomCache<WebrtcGlobalStatisticsReportAtoms>(cx); |
57 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
58 | 0 | return false; |
59 | 0 | } |
60 | 0 | } |
61 | 0 | |
62 | 0 | if (!IsConvertibleToDictionary(val)) { |
63 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
64 | 0 | } |
65 | 0 | |
66 | 0 | bool isNull = val.isNullOrUndefined(); |
67 | 0 | // We only need these if !isNull, in which case we have |cx|. |
68 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
69 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
70 | 0 | if (!isNull) { |
71 | 0 | MOZ_ASSERT(cx); |
72 | 0 | object.emplace(cx, &val.toObject()); |
73 | 0 | temp.emplace(cx); |
74 | 0 | } |
75 | 0 | if (!isNull) { |
76 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->reports_id, temp.ptr())) { |
77 | 0 | return false; |
78 | 0 | } |
79 | 0 | } |
80 | 0 | if (!isNull && !temp->isUndefined()) { |
81 | 0 | mReports.Construct(); |
82 | 0 | if (temp.ref().isObject()) { |
83 | 0 | JS::ForOfIterator iter(cx); |
84 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | if (!iter.valueIsIterable()) { |
88 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'reports' member of WebrtcGlobalStatisticsReport"); |
89 | 0 | return false; |
90 | 0 | } |
91 | 0 | Sequence<RTCStatsReportInternal> &arr = (mReports.Value()); |
92 | 0 | JS::Rooted<JS::Value> temp(cx); |
93 | 0 | while (true) { |
94 | 0 | bool done; |
95 | 0 | if (!iter.next(&temp, &done)) { |
96 | 0 | return false; |
97 | 0 | } |
98 | 0 | if (done) { |
99 | 0 | break; |
100 | 0 | } |
101 | 0 | RTCStatsReportInternal* slotPtr = arr.AppendElement(mozilla::fallible); |
102 | 0 | if (!slotPtr) { |
103 | 0 | JS_ReportOutOfMemory(cx); |
104 | 0 | return false; |
105 | 0 | } |
106 | 0 | RTCStatsReportInternal& slot = *slotPtr; |
107 | 0 | if (!slot.Init(cx, temp, "Element of 'reports' member of WebrtcGlobalStatisticsReport", passedToJSImpl)) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } else { |
112 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'reports' member of WebrtcGlobalStatisticsReport"); |
113 | 0 | return false; |
114 | 0 | } |
115 | 0 | mIsAnyMemberPresent = true; |
116 | 0 | } |
117 | 0 | return true; |
118 | 0 | } |
119 | | |
120 | | bool |
121 | | WebrtcGlobalStatisticsReport::Init(const nsAString& aJSON) |
122 | 0 | { |
123 | 0 | AutoJSAPI jsapi; |
124 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
125 | 0 | if (!cleanGlobal) { |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | if (!jsapi.Init(cleanGlobal)) { |
129 | 0 | return false; |
130 | 0 | } |
131 | 0 | JSContext* cx = jsapi.cx(); |
132 | 0 | JS::Rooted<JS::Value> json(cx); |
133 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
134 | 0 | NS_ENSURE_TRUE(ok, false); |
135 | 0 | return Init(cx, json); |
136 | 0 | } |
137 | | |
138 | | bool |
139 | | WebrtcGlobalStatisticsReport::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
140 | 0 | { |
141 | 0 | WebrtcGlobalStatisticsReportAtoms* atomsCache = GetAtomCache<WebrtcGlobalStatisticsReportAtoms>(cx); |
142 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
143 | 0 | return false; |
144 | 0 | } |
145 | 0 | |
146 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
147 | 0 | if (!obj) { |
148 | 0 | return false; |
149 | 0 | } |
150 | 0 | rval.set(JS::ObjectValue(*obj)); |
151 | 0 |
|
152 | 0 | if (mReports.WasPassed()) { |
153 | 0 | do { |
154 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
155 | 0 | JS::Rooted<JS::Value> temp(cx); |
156 | 0 | Sequence<RTCStatsReportInternal> const & currentValue = mReports.InternalValue(); |
157 | 0 |
|
158 | 0 | uint32_t length = currentValue.Length(); |
159 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
160 | 0 | if (!returnArray) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | // Scope for 'tmp' |
164 | 0 | { |
165 | 0 | JS::Rooted<JS::Value> tmp(cx); |
166 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
167 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
168 | 0 | // are different ways to succeed at wrapping the object. |
169 | 0 | do { |
170 | 0 | if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { |
171 | 0 | return false; |
172 | 0 | } |
173 | 0 | break; |
174 | 0 | } while (false); |
175 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
176 | 0 | JSPROP_ENUMERATE)) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | } |
180 | 0 | } |
181 | 0 | temp.setObject(*returnArray); |
182 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->reports_id, temp, JSPROP_ENUMERATE)) { |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | break; |
186 | 0 | } while(false); |
187 | 0 | } |
188 | 0 |
|
189 | 0 | return true; |
190 | 0 | } |
191 | | |
192 | | bool |
193 | | WebrtcGlobalStatisticsReport::ToJSON(nsAString& aJSON) const |
194 | 0 | { |
195 | 0 | AutoJSAPI jsapi; |
196 | 0 | jsapi.Init(); |
197 | 0 | JSContext *cx = jsapi.cx(); |
198 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
199 | 0 | // because we'll only be creating objects, in ways that have no |
200 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
201 | 0 | // which likewise guarantees no side-effects for the sorts of |
202 | 0 | // things we will pass it. |
203 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
204 | 0 | JS::Rooted<JS::Value> val(cx); |
205 | 0 | if (!ToObjectInternal(cx, &val)) { |
206 | 0 | return false; |
207 | 0 | } |
208 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
209 | 0 | return StringifyToJSON(cx, obj, aJSON); |
210 | 0 | } |
211 | | |
212 | | void |
213 | | WebrtcGlobalStatisticsReport::TraceDictionary(JSTracer* trc) |
214 | 0 | { |
215 | 0 | } |
216 | | |
217 | | WebrtcGlobalStatisticsReport& |
218 | | WebrtcGlobalStatisticsReport::operator=(const WebrtcGlobalStatisticsReport& aOther) |
219 | 0 | { |
220 | 0 | DictionaryBase::operator=(aOther); |
221 | 0 | mReports.Reset(); |
222 | 0 | if (aOther.mReports.WasPassed()) { |
223 | 0 | mReports.Construct(aOther.mReports.Value()); |
224 | 0 | } |
225 | 0 | return *this; |
226 | 0 | } |
227 | | |
228 | | namespace binding_detail { |
229 | | } // namespace binding_detail |
230 | | |
231 | | |
232 | | void |
233 | | WebrtcGlobalStatisticsCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const WebrtcGlobalStatisticsReport& reports, ErrorResult& aRv) |
234 | 0 | { |
235 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
236 | 0 | JS::AutoValueVector argv(cx); |
237 | 0 | if (!argv.resize(1)) { |
238 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
239 | 0 | return; |
240 | 0 | } |
241 | 0 | unsigned argc = 1; |
242 | 0 |
|
243 | 0 | do { |
244 | 0 | if (!reports.ToObjectInternal(cx, argv[0])) { |
245 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
246 | 0 | return; |
247 | 0 | } |
248 | 0 | break; |
249 | 0 | } while (false); |
250 | 0 |
|
251 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
252 | 0 | if (!JS::Call(cx, aThisVal, callable, |
253 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
254 | 0 | aRv.NoteJSContextException(cx); |
255 | 0 | return; |
256 | 0 | } |
257 | 0 | } |
258 | | |
259 | | |
260 | | |
261 | | void |
262 | | WebrtcGlobalLoggingCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const Sequence<nsString>& logMessages, ErrorResult& aRv) |
263 | 0 | { |
264 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
265 | 0 | JS::AutoValueVector argv(cx); |
266 | 0 | if (!argv.resize(1)) { |
267 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
268 | 0 | return; |
269 | 0 | } |
270 | 0 | unsigned argc = 1; |
271 | 0 |
|
272 | 0 | do { |
273 | 0 |
|
274 | 0 | uint32_t length = logMessages.Length(); |
275 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
276 | 0 | if (!returnArray) { |
277 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
278 | 0 | return; |
279 | 0 | } |
280 | 0 | // Scope for 'tmp' |
281 | 0 | { |
282 | 0 | JS::Rooted<JS::Value> tmp(cx); |
283 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
284 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
285 | 0 | // are different ways to succeed at wrapping the object. |
286 | 0 | do { |
287 | 0 | if (!xpc::NonVoidStringToJsval(cx, logMessages[sequenceIdx0], &tmp)) { |
288 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
289 | 0 | return; |
290 | 0 | } |
291 | 0 | break; |
292 | 0 | } while (false); |
293 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
294 | 0 | JSPROP_ENUMERATE)) { |
295 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
296 | 0 | return; |
297 | 0 | } |
298 | 0 | } |
299 | 0 | } |
300 | 0 | argv[0].setObject(*returnArray); |
301 | 0 | break; |
302 | 0 | } while (false); |
303 | 0 |
|
304 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
305 | 0 | if (!JS::Call(cx, aThisVal, callable, |
306 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
307 | 0 | aRv.NoteJSContextException(cx); |
308 | 0 | return; |
309 | 0 | } |
310 | 0 | } |
311 | | |
312 | | |
313 | | |
314 | | namespace binding_detail { |
315 | | } // namespace binding_detail |
316 | | |
317 | | |
318 | | namespace binding_detail { |
319 | | } // namespace binding_detail |
320 | | |
321 | | |
322 | | namespace WebrtcGlobalInformation_Binding { |
323 | | |
324 | | static bool |
325 | | getAllStats(JSContext* cx, unsigned argc, JS::Value* vp) |
326 | 0 | { |
327 | 0 | AUTO_PROFILER_LABEL_FAST("WebrtcGlobalInformation.getAllStats", DOM, cx); |
328 | 0 |
|
329 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
330 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
331 | 0 |
|
332 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
333 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebrtcGlobalInformation.getAllStats"); |
334 | 0 | } |
335 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
336 | 0 | if (global.Failed()) { |
337 | 0 | return false; |
338 | 0 | } |
339 | 0 | |
340 | 0 | RootedCallback<OwningNonNull<binding_detail::FastWebrtcGlobalStatisticsCallback>> arg0(cx); |
341 | 0 | if (args[0].isObject()) { |
342 | 0 | if (JS::IsCallable(&args[0].toObject())) { |
343 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
344 | 0 | arg0 = new binding_detail::FastWebrtcGlobalStatisticsCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
345 | 0 | } |
346 | 0 | } else { |
347 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of WebrtcGlobalInformation.getAllStats"); |
348 | 0 | return false; |
349 | 0 | } |
350 | 0 | } else { |
351 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WebrtcGlobalInformation.getAllStats"); |
352 | 0 | return false; |
353 | 0 | } |
354 | 0 | Optional<nsAString> arg1; |
355 | 0 | binding_detail::FakeString arg1_holder; |
356 | 0 | if (args.hasDefined(1)) { |
357 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) { |
358 | 0 | return false; |
359 | 0 | } |
360 | 0 | arg1 = &arg1_holder; |
361 | 0 | } |
362 | 0 | FastErrorResult rv; |
363 | 0 | mozilla::dom::WebrtcGlobalInformation::GetAllStats(global, NonNullHelper(arg0), NonNullHelper(Constify(arg1)), rv); |
364 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
365 | 0 | return false; |
366 | 0 | } |
367 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
368 | 0 | args.rval().setUndefined(); |
369 | 0 | return true; |
370 | 0 | } |
371 | | |
372 | | static bool |
373 | | clearAllStats(JSContext* cx, unsigned argc, JS::Value* vp) |
374 | 0 | { |
375 | 0 | AUTO_PROFILER_LABEL_FAST("WebrtcGlobalInformation.clearAllStats", DOM, cx); |
376 | 0 |
|
377 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
378 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
379 | 0 |
|
380 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
381 | 0 | if (global.Failed()) { |
382 | 0 | return false; |
383 | 0 | } |
384 | 0 | |
385 | 0 | mozilla::dom::WebrtcGlobalInformation::ClearAllStats(global); |
386 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
387 | 0 | args.rval().setUndefined(); |
388 | 0 | return true; |
389 | 0 | } |
390 | | |
391 | | static bool |
392 | | getLogging(JSContext* cx, unsigned argc, JS::Value* vp) |
393 | 0 | { |
394 | 0 | AUTO_PROFILER_LABEL_FAST("WebrtcGlobalInformation.getLogging", DOM, cx); |
395 | 0 |
|
396 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
397 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
398 | 0 |
|
399 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
400 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebrtcGlobalInformation.getLogging"); |
401 | 0 | } |
402 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
403 | 0 | if (global.Failed()) { |
404 | 0 | return false; |
405 | 0 | } |
406 | 0 | |
407 | 0 | binding_detail::FakeString arg0; |
408 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
409 | 0 | return false; |
410 | 0 | } |
411 | 0 | RootedCallback<OwningNonNull<binding_detail::FastWebrtcGlobalLoggingCallback>> arg1(cx); |
412 | 0 | if (args[1].isObject()) { |
413 | 0 | if (JS::IsCallable(&args[1].toObject())) { |
414 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
415 | 0 | arg1 = new binding_detail::FastWebrtcGlobalLoggingCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
416 | 0 | } |
417 | 0 | } else { |
418 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of WebrtcGlobalInformation.getLogging"); |
419 | 0 | return false; |
420 | 0 | } |
421 | 0 | } else { |
422 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of WebrtcGlobalInformation.getLogging"); |
423 | 0 | return false; |
424 | 0 | } |
425 | 0 | FastErrorResult rv; |
426 | 0 | mozilla::dom::WebrtcGlobalInformation::GetLogging(global, NonNullHelper(Constify(arg0)), NonNullHelper(arg1), rv); |
427 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
428 | 0 | return false; |
429 | 0 | } |
430 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
431 | 0 | args.rval().setUndefined(); |
432 | 0 | return true; |
433 | 0 | } |
434 | | |
435 | | static bool |
436 | | clearLogging(JSContext* cx, unsigned argc, JS::Value* vp) |
437 | 0 | { |
438 | 0 | AUTO_PROFILER_LABEL_FAST("WebrtcGlobalInformation.clearLogging", DOM, cx); |
439 | 0 |
|
440 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
441 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
442 | 0 |
|
443 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
444 | 0 | if (global.Failed()) { |
445 | 0 | return false; |
446 | 0 | } |
447 | 0 | |
448 | 0 | mozilla::dom::WebrtcGlobalInformation::ClearLogging(global); |
449 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
450 | 0 | args.rval().setUndefined(); |
451 | 0 | return true; |
452 | 0 | } |
453 | | |
454 | | static bool |
455 | | get_debugLevel(JSContext* cx, unsigned argc, JS::Value* vp) |
456 | 0 | { |
457 | 0 | AUTO_PROFILER_LABEL_FAST("get WebrtcGlobalInformation.debugLevel", DOM, cx); |
458 | 0 |
|
459 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
460 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
461 | 0 |
|
462 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
463 | 0 | if (global.Failed()) { |
464 | 0 | return false; |
465 | 0 | } |
466 | 0 | |
467 | 0 | int32_t result(mozilla::dom::WebrtcGlobalInformation::DebugLevel(global)); |
468 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
469 | 0 | args.rval().setInt32(int32_t(result)); |
470 | 0 | return true; |
471 | 0 | } |
472 | | |
473 | | static bool |
474 | | set_debugLevel(JSContext* cx, unsigned argc, JS::Value* vp) |
475 | 0 | { |
476 | 0 | AUTO_PROFILER_LABEL_FAST("set WebrtcGlobalInformation.debugLevel", DOM, cx); |
477 | 0 |
|
478 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
479 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
480 | 0 |
|
481 | 0 | if (args.length() == 0) { |
482 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "debugLevel setter"); |
483 | 0 | } |
484 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
485 | 0 | if (global.Failed()) { |
486 | 0 | return false; |
487 | 0 | } |
488 | 0 | |
489 | 0 | int32_t arg0; |
490 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, args[0], &arg0)) { |
491 | 0 | return false; |
492 | 0 | } |
493 | 0 | mozilla::dom::WebrtcGlobalInformation::SetDebugLevel(global, arg0); |
494 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
495 | 0 |
|
496 | 0 | return true; |
497 | 0 | } |
498 | | |
499 | | static bool |
500 | | get_aecDebug(JSContext* cx, unsigned argc, JS::Value* vp) |
501 | 0 | { |
502 | 0 | AUTO_PROFILER_LABEL_FAST("get WebrtcGlobalInformation.aecDebug", DOM, cx); |
503 | 0 |
|
504 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
505 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
506 | 0 |
|
507 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
508 | 0 | if (global.Failed()) { |
509 | 0 | return false; |
510 | 0 | } |
511 | 0 | |
512 | 0 | bool result(mozilla::dom::WebrtcGlobalInformation::AecDebug(global)); |
513 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
514 | 0 | args.rval().setBoolean(result); |
515 | 0 | return true; |
516 | 0 | } |
517 | | |
518 | | static bool |
519 | | set_aecDebug(JSContext* cx, unsigned argc, JS::Value* vp) |
520 | 0 | { |
521 | 0 | AUTO_PROFILER_LABEL_FAST("set WebrtcGlobalInformation.aecDebug", DOM, cx); |
522 | 0 |
|
523 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
524 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
525 | 0 |
|
526 | 0 | if (args.length() == 0) { |
527 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "aecDebug setter"); |
528 | 0 | } |
529 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
530 | 0 | if (global.Failed()) { |
531 | 0 | return false; |
532 | 0 | } |
533 | 0 | |
534 | 0 | bool arg0; |
535 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) { |
536 | 0 | return false; |
537 | 0 | } |
538 | 0 | mozilla::dom::WebrtcGlobalInformation::SetAecDebug(global, arg0); |
539 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
540 | 0 |
|
541 | 0 | return true; |
542 | 0 | } |
543 | | |
544 | | static bool |
545 | | get_aecDebugLogDir(JSContext* cx, unsigned argc, JS::Value* vp) |
546 | 0 | { |
547 | 0 | AUTO_PROFILER_LABEL_FAST("get WebrtcGlobalInformation.aecDebugLogDir", DOM, cx); |
548 | 0 |
|
549 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
550 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
551 | 0 |
|
552 | 0 | GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj)); |
553 | 0 | if (global.Failed()) { |
554 | 0 | return false; |
555 | 0 | } |
556 | 0 | |
557 | 0 | DOMString result; |
558 | 0 | mozilla::dom::WebrtcGlobalInformation::GetAecDebugLogDir(global, result); |
559 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
560 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
561 | 0 | return false; |
562 | 0 | } |
563 | 0 | return true; |
564 | 0 | } |
565 | | |
566 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
567 | | #if defined(__clang__) |
568 | | #pragma clang diagnostic push |
569 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
570 | | #endif |
571 | | static const JSFunctionSpec sStaticMethods_specs[] = { |
572 | | JS_FNSPEC("getAllStats", getAllStats, nullptr, 1, JSPROP_ENUMERATE, nullptr), |
573 | | JS_FNSPEC("clearAllStats", clearAllStats, nullptr, 0, JSPROP_ENUMERATE, nullptr), |
574 | | JS_FNSPEC("getLogging", getLogging, nullptr, 2, JSPROP_ENUMERATE, nullptr), |
575 | | JS_FNSPEC("clearLogging", clearLogging, nullptr, 0, JSPROP_ENUMERATE, nullptr), |
576 | | JS_FS_END |
577 | | }; |
578 | | #if defined(__clang__) |
579 | | #pragma clang diagnostic pop |
580 | | #endif |
581 | | |
582 | | |
583 | | static const Prefable<const JSFunctionSpec> sStaticMethods[] = { |
584 | | { nullptr, &sStaticMethods_specs[0] }, |
585 | | { nullptr, nullptr } |
586 | | }; |
587 | | |
588 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
589 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
590 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
591 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
592 | | |
593 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
594 | | #if defined(__clang__) |
595 | | #pragma clang diagnostic push |
596 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
597 | | #endif |
598 | | static const JSPropertySpec sStaticAttributes_specs[] = { |
599 | | { "debugLevel", JSPROP_ENUMERATE, get_debugLevel, nullptr, set_debugLevel, nullptr }, |
600 | | { "aecDebug", JSPROP_ENUMERATE, get_aecDebug, nullptr, set_aecDebug, nullptr }, |
601 | | { "aecDebugLogDir", JSPROP_ENUMERATE, get_aecDebugLogDir, nullptr, nullptr, nullptr }, |
602 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
603 | | }; |
604 | | #if defined(__clang__) |
605 | | #pragma clang diagnostic pop |
606 | | #endif |
607 | | |
608 | | |
609 | | static const Prefable<const JSPropertySpec> sStaticAttributes[] = { |
610 | | { nullptr, &sStaticAttributes_specs[0] }, |
611 | | { nullptr, nullptr } |
612 | | }; |
613 | | |
614 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
615 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
616 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
617 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
618 | | |
619 | | |
620 | | static uint16_t sNativeProperties_sortedPropertyIndices[7]; |
621 | | static PropertyInfo sNativeProperties_propertyInfos[7]; |
622 | | |
623 | | static const NativePropertiesN<2> sNativeProperties = { |
624 | | true, 0 /* sStaticMethods */, |
625 | | true, 1 /* sStaticAttributes */, |
626 | | false, 0, |
627 | | false, 0, |
628 | | false, 0, |
629 | | false, 0, |
630 | | false, 0, |
631 | | -1, |
632 | | 7, |
633 | | sNativeProperties_sortedPropertyIndices, |
634 | | { |
635 | | { sStaticMethods, &sNativeProperties_propertyInfos[0] }, |
636 | | { sStaticAttributes, &sNativeProperties_propertyInfos[4] } |
637 | | } |
638 | | }; |
639 | | static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
640 | | "We have a property info count that is oversized"); |
641 | | |
642 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
643 | | { |
644 | | "Function", |
645 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
646 | | &sBoringInterfaceObjectClassClassOps, |
647 | | JS_NULL_CLASS_SPEC, |
648 | | JS_NULL_CLASS_EXT, |
649 | | &sInterfaceObjectClassObjectOps |
650 | | }, |
651 | | eInterface, |
652 | | false, |
653 | | prototypes::id::_ID_Count, |
654 | | 0, |
655 | | sNativePropertyHooks, |
656 | | "function WebrtcGlobalInformation() {\n [native code]\n}", |
657 | | JS::GetRealmFunctionPrototype |
658 | | }; |
659 | | |
660 | | bool |
661 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
662 | 0 | { |
663 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
664 | 0 | } |
665 | | |
666 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
667 | | nullptr, |
668 | | nullptr, |
669 | | nullptr, |
670 | | { sNativeProperties.Upcast(), nullptr }, |
671 | | prototypes::id::_ID_Count, |
672 | | constructors::id::WebrtcGlobalInformation, |
673 | | nullptr, |
674 | | &DefaultXrayExpandoObjectClass |
675 | | } }; |
676 | | |
677 | | void |
678 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
679 | 0 | { |
680 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
681 | 0 | if (!constructorProto) { |
682 | 0 | return; |
683 | 0 | } |
684 | 0 | |
685 | 0 | static bool sIdsInited = false; |
686 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
687 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
688 | 0 | return; |
689 | 0 | } |
690 | 0 | sIdsInited = true; |
691 | 0 | } |
692 | 0 |
|
693 | 0 | JS::Heap<JSObject*>* protoCache = nullptr; |
694 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebrtcGlobalInformation); |
695 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, nullptr, |
696 | 0 | nullptr, protoCache, |
697 | 0 | nullptr, |
698 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
699 | 0 | interfaceCache, |
700 | 0 | sNativeProperties.Upcast(), |
701 | 0 | nullptr, |
702 | 0 | "WebrtcGlobalInformation", aDefineOnGlobal, |
703 | 0 | nullptr, |
704 | 0 | false); |
705 | 0 | } |
706 | | |
707 | | JSObject* |
708 | | GetConstructorObject(JSContext* aCx) |
709 | 0 | { |
710 | 0 | return GetConstructorObjectHandle(aCx); |
711 | 0 | } |
712 | | |
713 | | } // namespace WebrtcGlobalInformation_Binding |
714 | | |
715 | | |
716 | | |
717 | | } // namespace dom |
718 | | } // namespace mozilla |