Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM Console.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "ConsoleBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/FloatingPoint.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/Console.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ScriptSettings.h"
14 : #include "mozilla/dom/SimpleGlobalObject.h"
15 : #include "mozilla/dom/UnionConversions.h"
16 : #include "mozilla/dom/XrayExpandoClass.h"
17 : #include "nsContentUtils.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 :
23 0 : ConsoleCounter::ConsoleCounter()
24 : {
25 : // Safe to pass a null context if we pass a null value
26 0 : Init(nullptr, JS::NullHandleValue);
27 0 : }
28 :
29 :
30 :
31 : bool
32 0 : ConsoleCounter::InitIds(JSContext* cx, ConsoleCounterAtoms* atomsCache)
33 : {
34 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
35 :
36 : // Initialize these in reverse order so that any failure leaves the first one
37 : // uninitialized.
38 0 : if (!atomsCache->label_id.init(cx, "label") ||
39 0 : !atomsCache->count_id.init(cx, "count")) {
40 0 : return false;
41 : }
42 0 : return true;
43 : }
44 :
45 : bool
46 0 : ConsoleCounter::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
47 : {
48 : // Passing a null JSContext is OK only if we're initing from null,
49 : // Since in that case we will not have to do any property gets
50 : // Also evaluate isNullOrUndefined in order to avoid false-positive
51 : // checkers by static analysis tools
52 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
53 0 : ConsoleCounterAtoms* atomsCache = nullptr;
54 0 : if (cx) {
55 0 : atomsCache = GetAtomCache<ConsoleCounterAtoms>(cx);
56 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
57 0 : return false;
58 : }
59 : }
60 :
61 0 : if (!IsConvertibleToDictionary(val)) {
62 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
63 : }
64 :
65 0 : bool isNull = val.isNullOrUndefined();
66 : // We only need these if !isNull, in which case we have |cx|.
67 0 : Maybe<JS::Rooted<JSObject *> > object;
68 0 : Maybe<JS::Rooted<JS::Value> > temp;
69 0 : if (!isNull) {
70 0 : MOZ_ASSERT(cx);
71 0 : object.emplace(cx, &val.toObject());
72 0 : temp.emplace(cx);
73 : }
74 0 : if (!isNull) {
75 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->count_id, temp.ptr())) {
76 0 : return false;
77 : }
78 : }
79 0 : if (!isNull && !temp->isUndefined()) {
80 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mCount)) {
81 0 : return false;
82 : }
83 : } else {
84 0 : mCount = 0U;
85 : }
86 0 : mIsAnyMemberPresent = true;
87 :
88 0 : if (!isNull) {
89 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->label_id, temp.ptr())) {
90 0 : return false;
91 : }
92 : }
93 0 : if (!isNull && !temp->isUndefined()) {
94 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLabel)) {
95 0 : return false;
96 : }
97 : } else {
98 : static const char16_t data[] = { 0 };
99 0 : mLabel.Rebind(data, ArrayLength(data) - 1);
100 : }
101 0 : mIsAnyMemberPresent = true;
102 0 : return true;
103 : }
104 :
105 : bool
106 0 : ConsoleCounter::Init(const nsAString& aJSON)
107 : {
108 0 : AutoJSAPI jsapi;
109 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
110 0 : if (!cleanGlobal) {
111 0 : return false;
112 : }
113 0 : if (!jsapi.Init(cleanGlobal)) {
114 0 : return false;
115 : }
116 0 : JSContext* cx = jsapi.cx();
117 0 : JS::Rooted<JS::Value> json(cx);
118 0 : bool ok = ParseJSON(cx, aJSON, &json);
119 0 : NS_ENSURE_TRUE(ok, false);
120 0 : return Init(cx, json);
121 : }
122 :
123 : bool
124 0 : ConsoleCounter::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
125 : {
126 0 : ConsoleCounterAtoms* atomsCache = GetAtomCache<ConsoleCounterAtoms>(cx);
127 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
128 0 : return false;
129 : }
130 :
131 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
132 0 : if (!obj) {
133 0 : return false;
134 : }
135 0 : rval.set(JS::ObjectValue(*obj));
136 :
137 : do {
138 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
139 0 : JS::Rooted<JS::Value> temp(cx);
140 0 : uint32_t const & currentValue = mCount;
141 0 : temp.setNumber(currentValue);
142 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->count_id, temp, JSPROP_ENUMERATE)) {
143 0 : return false;
144 : }
145 0 : break;
146 : } while(0);
147 :
148 : do {
149 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
150 0 : JS::Rooted<JS::Value> temp(cx);
151 0 : nsString const & currentValue = mLabel;
152 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
153 0 : return false;
154 : }
155 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->label_id, temp, JSPROP_ENUMERATE)) {
156 0 : return false;
157 : }
158 0 : break;
159 : } while(0);
160 :
161 0 : return true;
162 : }
163 :
164 : bool
165 0 : ConsoleCounter::ToJSON(nsAString& aJSON) const
166 : {
167 0 : AutoJSAPI jsapi;
168 0 : jsapi.Init();
169 0 : JSContext *cx = jsapi.cx();
170 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
171 : // because we'll only be creating objects, in ways that have no
172 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
173 : // which likewise guarantees no side-effects for the sorts of
174 : // things we will pass it.
175 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
176 0 : JS::Rooted<JS::Value> val(cx);
177 0 : if (!ToObjectInternal(cx, &val)) {
178 0 : return false;
179 : }
180 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
181 0 : return StringifyToJSON(cx, obj, aJSON);
182 : }
183 :
184 : void
185 0 : ConsoleCounter::TraceDictionary(JSTracer* trc)
186 : {
187 0 : }
188 :
189 : ConsoleCounter&
190 0 : ConsoleCounter::operator=(const ConsoleCounter& aOther)
191 : {
192 0 : mCount = aOther.mCount;
193 0 : mLabel = aOther.mLabel;
194 0 : return *this;
195 : }
196 :
197 : namespace binding_detail {
198 : } // namespace binding_detail
199 :
200 :
201 :
202 0 : ConsoleCounterError::ConsoleCounterError()
203 : {
204 : // Safe to pass a null context if we pass a null value
205 0 : Init(nullptr, JS::NullHandleValue);
206 0 : }
207 :
208 :
209 :
210 : bool
211 0 : ConsoleCounterError::InitIds(JSContext* cx, ConsoleCounterErrorAtoms* atomsCache)
212 : {
213 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
214 :
215 : // Initialize these in reverse order so that any failure leaves the first one
216 : // uninitialized.
217 0 : if (!atomsCache->error_id.init(cx, "error")) {
218 0 : return false;
219 : }
220 0 : return true;
221 : }
222 :
223 : bool
224 0 : ConsoleCounterError::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
225 : {
226 : // Passing a null JSContext is OK only if we're initing from null,
227 : // Since in that case we will not have to do any property gets
228 : // Also evaluate isNullOrUndefined in order to avoid false-positive
229 : // checkers by static analysis tools
230 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
231 0 : ConsoleCounterErrorAtoms* atomsCache = nullptr;
232 0 : if (cx) {
233 0 : atomsCache = GetAtomCache<ConsoleCounterErrorAtoms>(cx);
234 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
235 0 : return false;
236 : }
237 : }
238 :
239 0 : if (!IsConvertibleToDictionary(val)) {
240 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
241 : }
242 :
243 0 : bool isNull = val.isNullOrUndefined();
244 : // We only need these if !isNull, in which case we have |cx|.
245 0 : Maybe<JS::Rooted<JSObject *> > object;
246 0 : Maybe<JS::Rooted<JS::Value> > temp;
247 0 : if (!isNull) {
248 0 : MOZ_ASSERT(cx);
249 0 : object.emplace(cx, &val.toObject());
250 0 : temp.emplace(cx);
251 : }
252 0 : if (!isNull) {
253 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->error_id, temp.ptr())) {
254 0 : return false;
255 : }
256 : }
257 0 : if (!isNull && !temp->isUndefined()) {
258 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mError)) {
259 0 : return false;
260 : }
261 : } else {
262 : static const char16_t data[] = { 'm', 'a', 'x', 'C', 'o', 'u', 'n', 't', 'e', 'r', 's', 'E', 'x', 'c', 'e', 'e', 'd', 'e', 'd', 0 };
263 0 : mError.Rebind(data, ArrayLength(data) - 1);
264 : }
265 0 : mIsAnyMemberPresent = true;
266 0 : return true;
267 : }
268 :
269 : bool
270 0 : ConsoleCounterError::Init(const nsAString& aJSON)
271 : {
272 0 : AutoJSAPI jsapi;
273 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
274 0 : if (!cleanGlobal) {
275 0 : return false;
276 : }
277 0 : if (!jsapi.Init(cleanGlobal)) {
278 0 : return false;
279 : }
280 0 : JSContext* cx = jsapi.cx();
281 0 : JS::Rooted<JS::Value> json(cx);
282 0 : bool ok = ParseJSON(cx, aJSON, &json);
283 0 : NS_ENSURE_TRUE(ok, false);
284 0 : return Init(cx, json);
285 : }
286 :
287 : bool
288 0 : ConsoleCounterError::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
289 : {
290 0 : ConsoleCounterErrorAtoms* atomsCache = GetAtomCache<ConsoleCounterErrorAtoms>(cx);
291 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
292 0 : return false;
293 : }
294 :
295 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
296 0 : if (!obj) {
297 0 : return false;
298 : }
299 0 : rval.set(JS::ObjectValue(*obj));
300 :
301 : do {
302 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
303 0 : JS::Rooted<JS::Value> temp(cx);
304 0 : nsString const & currentValue = mError;
305 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
306 0 : return false;
307 : }
308 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->error_id, temp, JSPROP_ENUMERATE)) {
309 0 : return false;
310 : }
311 0 : break;
312 : } while(0);
313 :
314 0 : return true;
315 : }
316 :
317 : bool
318 0 : ConsoleCounterError::ToJSON(nsAString& aJSON) const
319 : {
320 0 : AutoJSAPI jsapi;
321 0 : jsapi.Init();
322 0 : JSContext *cx = jsapi.cx();
323 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
324 : // because we'll only be creating objects, in ways that have no
325 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
326 : // which likewise guarantees no side-effects for the sorts of
327 : // things we will pass it.
328 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
329 0 : JS::Rooted<JS::Value> val(cx);
330 0 : if (!ToObjectInternal(cx, &val)) {
331 0 : return false;
332 : }
333 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
334 0 : return StringifyToJSON(cx, obj, aJSON);
335 : }
336 :
337 : void
338 0 : ConsoleCounterError::TraceDictionary(JSTracer* trc)
339 : {
340 0 : }
341 :
342 : ConsoleCounterError&
343 0 : ConsoleCounterError::operator=(const ConsoleCounterError& aOther)
344 : {
345 0 : mError = aOther.mError;
346 0 : return *this;
347 : }
348 :
349 : namespace binding_detail {
350 : } // namespace binding_detail
351 :
352 :
353 :
354 0 : ConsoleProfileEvent::ConsoleProfileEvent()
355 : {
356 : // Safe to pass a null context if we pass a null value
357 0 : Init(nullptr, JS::NullHandleValue);
358 0 : }
359 :
360 :
361 : bool
362 0 : ConsoleProfileEvent::InitIds(JSContext* cx, ConsoleProfileEventAtoms* atomsCache)
363 : {
364 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
365 :
366 : // Initialize these in reverse order so that any failure leaves the first one
367 : // uninitialized.
368 0 : if (!atomsCache->arguments_id.init(cx, "arguments") ||
369 0 : !atomsCache->action_id.init(cx, "action")) {
370 0 : return false;
371 : }
372 0 : return true;
373 : }
374 :
375 : bool
376 0 : ConsoleProfileEvent::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
377 : {
378 : // Passing a null JSContext is OK only if we're initing from null,
379 : // Since in that case we will not have to do any property gets
380 : // Also evaluate isNullOrUndefined in order to avoid false-positive
381 : // checkers by static analysis tools
382 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
383 0 : ConsoleProfileEventAtoms* atomsCache = nullptr;
384 0 : if (cx) {
385 0 : atomsCache = GetAtomCache<ConsoleProfileEventAtoms>(cx);
386 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
387 0 : return false;
388 : }
389 : }
390 :
391 0 : if (!IsConvertibleToDictionary(val)) {
392 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
393 : }
394 :
395 0 : bool isNull = val.isNullOrUndefined();
396 : // We only need these if !isNull, in which case we have |cx|.
397 0 : Maybe<JS::Rooted<JSObject *> > object;
398 0 : Maybe<JS::Rooted<JS::Value> > temp;
399 0 : if (!isNull) {
400 0 : MOZ_ASSERT(cx);
401 0 : object.emplace(cx, &val.toObject());
402 0 : temp.emplace(cx);
403 : }
404 0 : if (!isNull) {
405 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->action_id, temp.ptr())) {
406 0 : return false;
407 : }
408 : }
409 0 : if (!isNull && !temp->isUndefined()) {
410 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAction)) {
411 0 : return false;
412 : }
413 : } else {
414 : static const char16_t data[] = { 0 };
415 0 : mAction.Rebind(data, ArrayLength(data) - 1);
416 : }
417 0 : mIsAnyMemberPresent = true;
418 :
419 0 : if (!isNull) {
420 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->arguments_id, temp.ptr())) {
421 0 : return false;
422 : }
423 : }
424 0 : if (!isNull && !temp->isUndefined()) {
425 0 : mArguments.Construct();
426 0 : if (temp.ref().isObject()) {
427 0 : JS::ForOfIterator iter(cx);
428 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
429 0 : return false;
430 : }
431 0 : if (!iter.valueIsIterable()) {
432 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'arguments' member of ConsoleProfileEvent");
433 0 : return false;
434 : }
435 0 : Sequence<JS::Value> &arr = (mArguments.Value());
436 0 : JS::Rooted<JS::Value> temp(cx);
437 : while (true) {
438 : bool done;
439 0 : if (!iter.next(&temp, &done)) {
440 0 : return false;
441 : }
442 0 : if (done) {
443 0 : break;
444 : }
445 0 : JS::Value* slotPtr = arr.AppendElement(mozilla::fallible);
446 0 : if (!slotPtr) {
447 0 : JS_ReportOutOfMemory(cx);
448 0 : return false;
449 : }
450 0 : JS::Value& slot = *slotPtr;
451 : #ifdef __clang__
452 : #pragma clang diagnostic push
453 : #pragma clang diagnostic ignored "-Wunreachable-code"
454 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
455 : #endif // __clang__
456 0 : if ((passedToJSImpl) && !CallerSubsumes(temp)) {
457 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "element of 'arguments' member of ConsoleProfileEvent");
458 0 : return false;
459 : }
460 : #ifdef __clang__
461 : #pragma clang diagnostic pop
462 : #endif // __clang__
463 0 : slot = temp;
464 0 : }
465 : } else {
466 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'arguments' member of ConsoleProfileEvent");
467 0 : return false;
468 : }
469 0 : mIsAnyMemberPresent = true;
470 : }
471 0 : return true;
472 : }
473 :
474 : bool
475 0 : ConsoleProfileEvent::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
476 : {
477 0 : ConsoleProfileEventAtoms* atomsCache = GetAtomCache<ConsoleProfileEventAtoms>(cx);
478 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
479 0 : return false;
480 : }
481 :
482 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
483 0 : if (!obj) {
484 0 : return false;
485 : }
486 0 : rval.set(JS::ObjectValue(*obj));
487 :
488 : do {
489 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
490 0 : JS::Rooted<JS::Value> temp(cx);
491 0 : nsString const & currentValue = mAction;
492 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
493 0 : return false;
494 : }
495 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->action_id, temp, JSPROP_ENUMERATE)) {
496 0 : return false;
497 : }
498 0 : break;
499 : } while(0);
500 :
501 0 : if (mArguments.WasPassed()) {
502 : do {
503 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
504 0 : JS::Rooted<JS::Value> temp(cx);
505 0 : Sequence<JS::Value> const & currentValue = mArguments.InternalValue();
506 :
507 0 : uint32_t length = currentValue.Length();
508 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
509 0 : if (!returnArray) {
510 0 : return false;
511 : }
512 : // Scope for 'tmp'
513 : {
514 0 : JS::Rooted<JS::Value> tmp(cx);
515 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
516 : // Control block to let us common up the JS_DefineElement calls when there
517 : // are different ways to succeed at wrapping the object.
518 : do {
519 0 : JS::ExposeValueToActiveJS(currentValue[sequenceIdx0]);
520 0 : tmp.set(currentValue[sequenceIdx0]);
521 0 : if (!MaybeWrapValue(cx, &tmp)) {
522 0 : return false;
523 : }
524 0 : break;
525 : } while (0);
526 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
527 : JSPROP_ENUMERATE)) {
528 0 : return false;
529 : }
530 : }
531 : }
532 0 : temp.setObject(*returnArray);
533 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->arguments_id, temp, JSPROP_ENUMERATE)) {
534 0 : return false;
535 : }
536 0 : break;
537 : } while(0);
538 : }
539 :
540 0 : return true;
541 : }
542 :
543 : void
544 0 : ConsoleProfileEvent::TraceDictionary(JSTracer* trc)
545 : {
546 0 : if (mArguments.WasPassed()) {
547 0 : DoTraceSequence(trc, mArguments.Value());
548 : }
549 0 : }
550 :
551 : namespace binding_detail {
552 : } // namespace binding_detail
553 :
554 :
555 :
556 2 : ConsoleStackEntry::ConsoleStackEntry()
557 : {
558 : // Safe to pass a null context if we pass a null value
559 2 : Init(nullptr, JS::NullHandleValue);
560 2 : }
561 :
562 :
563 :
564 : bool
565 0 : ConsoleStackEntry::InitIds(JSContext* cx, ConsoleStackEntryAtoms* atomsCache)
566 : {
567 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
568 :
569 : // Initialize these in reverse order so that any failure leaves the first one
570 : // uninitialized.
571 0 : if (!atomsCache->lineNumber_id.init(cx, "lineNumber") ||
572 0 : !atomsCache->language_id.init(cx, "language") ||
573 0 : !atomsCache->functionName_id.init(cx, "functionName") ||
574 0 : !atomsCache->filename_id.init(cx, "filename") ||
575 0 : !atomsCache->columnNumber_id.init(cx, "columnNumber") ||
576 0 : !atomsCache->asyncCause_id.init(cx, "asyncCause")) {
577 0 : return false;
578 : }
579 0 : return true;
580 : }
581 :
582 : bool
583 2 : ConsoleStackEntry::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
584 : {
585 : // Passing a null JSContext is OK only if we're initing from null,
586 : // Since in that case we will not have to do any property gets
587 : // Also evaluate isNullOrUndefined in order to avoid false-positive
588 : // checkers by static analysis tools
589 2 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
590 2 : ConsoleStackEntryAtoms* atomsCache = nullptr;
591 2 : if (cx) {
592 0 : atomsCache = GetAtomCache<ConsoleStackEntryAtoms>(cx);
593 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
594 0 : return false;
595 : }
596 : }
597 :
598 2 : if (!IsConvertibleToDictionary(val)) {
599 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
600 : }
601 :
602 2 : bool isNull = val.isNullOrUndefined();
603 : // We only need these if !isNull, in which case we have |cx|.
604 4 : Maybe<JS::Rooted<JSObject *> > object;
605 4 : Maybe<JS::Rooted<JS::Value> > temp;
606 2 : if (!isNull) {
607 0 : MOZ_ASSERT(cx);
608 0 : object.emplace(cx, &val.toObject());
609 0 : temp.emplace(cx);
610 : }
611 2 : if (!isNull) {
612 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->asyncCause_id, temp.ptr())) {
613 0 : return false;
614 : }
615 : }
616 2 : if (!isNull && !temp->isUndefined()) {
617 0 : mAsyncCause.Construct();
618 0 : if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mAsyncCause.Value()))) {
619 0 : return false;
620 : }
621 0 : mIsAnyMemberPresent = true;
622 : }
623 :
624 2 : if (!isNull) {
625 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->columnNumber_id, temp.ptr())) {
626 0 : return false;
627 : }
628 : }
629 2 : if (!isNull && !temp->isUndefined()) {
630 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mColumnNumber)) {
631 0 : return false;
632 : }
633 : } else {
634 2 : mColumnNumber = 0U;
635 : }
636 2 : mIsAnyMemberPresent = true;
637 :
638 2 : if (!isNull) {
639 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->filename_id, temp.ptr())) {
640 0 : return false;
641 : }
642 : }
643 2 : if (!isNull && !temp->isUndefined()) {
644 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFilename)) {
645 0 : return false;
646 : }
647 : } else {
648 : static const char16_t data[] = { 0 };
649 2 : mFilename.Rebind(data, ArrayLength(data) - 1);
650 : }
651 2 : mIsAnyMemberPresent = true;
652 :
653 2 : if (!isNull) {
654 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->functionName_id, temp.ptr())) {
655 0 : return false;
656 : }
657 : }
658 2 : if (!isNull && !temp->isUndefined()) {
659 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFunctionName)) {
660 0 : return false;
661 : }
662 : } else {
663 : static const char16_t data[] = { 0 };
664 2 : mFunctionName.Rebind(data, ArrayLength(data) - 1);
665 : }
666 2 : mIsAnyMemberPresent = true;
667 :
668 2 : if (!isNull) {
669 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->language_id, temp.ptr())) {
670 0 : return false;
671 : }
672 : }
673 2 : if (!isNull && !temp->isUndefined()) {
674 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mLanguage)) {
675 0 : return false;
676 : }
677 : } else {
678 2 : mLanguage = 0U;
679 : }
680 2 : mIsAnyMemberPresent = true;
681 :
682 2 : if (!isNull) {
683 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->lineNumber_id, temp.ptr())) {
684 0 : return false;
685 : }
686 : }
687 2 : if (!isNull && !temp->isUndefined()) {
688 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mLineNumber)) {
689 0 : return false;
690 : }
691 : } else {
692 2 : mLineNumber = 0U;
693 : }
694 2 : mIsAnyMemberPresent = true;
695 2 : return true;
696 : }
697 :
698 : bool
699 0 : ConsoleStackEntry::Init(const nsAString& aJSON)
700 : {
701 0 : AutoJSAPI jsapi;
702 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
703 0 : if (!cleanGlobal) {
704 0 : return false;
705 : }
706 0 : if (!jsapi.Init(cleanGlobal)) {
707 0 : return false;
708 : }
709 0 : JSContext* cx = jsapi.cx();
710 0 : JS::Rooted<JS::Value> json(cx);
711 0 : bool ok = ParseJSON(cx, aJSON, &json);
712 0 : NS_ENSURE_TRUE(ok, false);
713 0 : return Init(cx, json);
714 : }
715 :
716 : bool
717 0 : ConsoleStackEntry::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
718 : {
719 0 : ConsoleStackEntryAtoms* atomsCache = GetAtomCache<ConsoleStackEntryAtoms>(cx);
720 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
721 0 : return false;
722 : }
723 :
724 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
725 0 : if (!obj) {
726 0 : return false;
727 : }
728 0 : rval.set(JS::ObjectValue(*obj));
729 :
730 0 : if (mAsyncCause.WasPassed()) {
731 : do {
732 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
733 0 : JS::Rooted<JS::Value> temp(cx);
734 0 : nsString const & currentValue = mAsyncCause.InternalValue();
735 0 : if (!xpc::StringToJsval(cx, currentValue, &temp)) {
736 0 : return false;
737 : }
738 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->asyncCause_id, temp, JSPROP_ENUMERATE)) {
739 0 : return false;
740 : }
741 0 : break;
742 : } while(0);
743 : }
744 :
745 : do {
746 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
747 0 : JS::Rooted<JS::Value> temp(cx);
748 0 : uint32_t const & currentValue = mColumnNumber;
749 0 : temp.setNumber(currentValue);
750 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->columnNumber_id, temp, JSPROP_ENUMERATE)) {
751 0 : return false;
752 : }
753 0 : break;
754 : } while(0);
755 :
756 : do {
757 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
758 0 : JS::Rooted<JS::Value> temp(cx);
759 0 : nsString const & currentValue = mFilename;
760 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
761 0 : return false;
762 : }
763 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->filename_id, temp, JSPROP_ENUMERATE)) {
764 0 : return false;
765 : }
766 0 : break;
767 : } while(0);
768 :
769 : do {
770 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
771 0 : JS::Rooted<JS::Value> temp(cx);
772 0 : nsString const & currentValue = mFunctionName;
773 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
774 0 : return false;
775 : }
776 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->functionName_id, temp, JSPROP_ENUMERATE)) {
777 0 : return false;
778 : }
779 0 : break;
780 : } while(0);
781 :
782 : do {
783 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
784 0 : JS::Rooted<JS::Value> temp(cx);
785 0 : uint32_t const & currentValue = mLanguage;
786 0 : temp.setNumber(currentValue);
787 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->language_id, temp, JSPROP_ENUMERATE)) {
788 0 : return false;
789 : }
790 0 : break;
791 : } while(0);
792 :
793 : do {
794 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
795 0 : JS::Rooted<JS::Value> temp(cx);
796 0 : uint32_t const & currentValue = mLineNumber;
797 0 : temp.setNumber(currentValue);
798 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->lineNumber_id, temp, JSPROP_ENUMERATE)) {
799 0 : return false;
800 : }
801 0 : break;
802 : } while(0);
803 :
804 0 : return true;
805 : }
806 :
807 : bool
808 0 : ConsoleStackEntry::ToJSON(nsAString& aJSON) const
809 : {
810 0 : AutoJSAPI jsapi;
811 0 : jsapi.Init();
812 0 : JSContext *cx = jsapi.cx();
813 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
814 : // because we'll only be creating objects, in ways that have no
815 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
816 : // which likewise guarantees no side-effects for the sorts of
817 : // things we will pass it.
818 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
819 0 : JS::Rooted<JS::Value> val(cx);
820 0 : if (!ToObjectInternal(cx, &val)) {
821 0 : return false;
822 : }
823 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
824 0 : return StringifyToJSON(cx, obj, aJSON);
825 : }
826 :
827 : void
828 0 : ConsoleStackEntry::TraceDictionary(JSTracer* trc)
829 : {
830 0 : }
831 :
832 : ConsoleStackEntry&
833 1 : ConsoleStackEntry::operator=(const ConsoleStackEntry& aOther)
834 : {
835 1 : mAsyncCause.Reset();
836 1 : if (aOther.mAsyncCause.WasPassed()) {
837 0 : mAsyncCause.Construct(aOther.mAsyncCause.Value());
838 : }
839 1 : mColumnNumber = aOther.mColumnNumber;
840 1 : mFilename = aOther.mFilename;
841 1 : mFunctionName = aOther.mFunctionName;
842 1 : mLanguage = aOther.mLanguage;
843 1 : mLineNumber = aOther.mLineNumber;
844 1 : return *this;
845 : }
846 :
847 : namespace binding_detail {
848 : } // namespace binding_detail
849 :
850 :
851 :
852 0 : ConsoleTimerEnd::ConsoleTimerEnd()
853 : {
854 : // Safe to pass a null context if we pass a null value
855 0 : Init(nullptr, JS::NullHandleValue);
856 0 : }
857 :
858 :
859 :
860 : bool
861 0 : ConsoleTimerEnd::InitIds(JSContext* cx, ConsoleTimerEndAtoms* atomsCache)
862 : {
863 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
864 :
865 : // Initialize these in reverse order so that any failure leaves the first one
866 : // uninitialized.
867 0 : if (!atomsCache->name_id.init(cx, "name") ||
868 0 : !atomsCache->duration_id.init(cx, "duration")) {
869 0 : return false;
870 : }
871 0 : return true;
872 : }
873 :
874 : bool
875 0 : ConsoleTimerEnd::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
876 : {
877 : // Passing a null JSContext is OK only if we're initing from null,
878 : // Since in that case we will not have to do any property gets
879 : // Also evaluate isNullOrUndefined in order to avoid false-positive
880 : // checkers by static analysis tools
881 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
882 0 : ConsoleTimerEndAtoms* atomsCache = nullptr;
883 0 : if (cx) {
884 0 : atomsCache = GetAtomCache<ConsoleTimerEndAtoms>(cx);
885 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
886 0 : return false;
887 : }
888 : }
889 :
890 0 : if (!IsConvertibleToDictionary(val)) {
891 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
892 : }
893 :
894 0 : bool isNull = val.isNullOrUndefined();
895 : // We only need these if !isNull, in which case we have |cx|.
896 0 : Maybe<JS::Rooted<JSObject *> > object;
897 0 : Maybe<JS::Rooted<JS::Value> > temp;
898 0 : if (!isNull) {
899 0 : MOZ_ASSERT(cx);
900 0 : object.emplace(cx, &val.toObject());
901 0 : temp.emplace(cx);
902 : }
903 0 : if (!isNull) {
904 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->duration_id, temp.ptr())) {
905 0 : return false;
906 : }
907 : }
908 0 : if (!isNull && !temp->isUndefined()) {
909 0 : if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mDuration)) {
910 0 : return false;
911 0 : } else if (!mozilla::IsFinite(mDuration)) {
912 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'duration' member of ConsoleTimerEnd");
913 0 : return false;
914 : }
915 : } else {
916 0 : mDuration = 0.0;
917 : }
918 0 : mIsAnyMemberPresent = true;
919 :
920 0 : if (!isNull) {
921 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
922 0 : return false;
923 : }
924 : }
925 0 : if (!isNull && !temp->isUndefined()) {
926 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
927 0 : return false;
928 : }
929 : } else {
930 : static const char16_t data[] = { 0 };
931 0 : mName.Rebind(data, ArrayLength(data) - 1);
932 : }
933 0 : mIsAnyMemberPresent = true;
934 0 : return true;
935 : }
936 :
937 : bool
938 0 : ConsoleTimerEnd::Init(const nsAString& aJSON)
939 : {
940 0 : AutoJSAPI jsapi;
941 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
942 0 : if (!cleanGlobal) {
943 0 : return false;
944 : }
945 0 : if (!jsapi.Init(cleanGlobal)) {
946 0 : return false;
947 : }
948 0 : JSContext* cx = jsapi.cx();
949 0 : JS::Rooted<JS::Value> json(cx);
950 0 : bool ok = ParseJSON(cx, aJSON, &json);
951 0 : NS_ENSURE_TRUE(ok, false);
952 0 : return Init(cx, json);
953 : }
954 :
955 : bool
956 0 : ConsoleTimerEnd::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
957 : {
958 0 : ConsoleTimerEndAtoms* atomsCache = GetAtomCache<ConsoleTimerEndAtoms>(cx);
959 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
960 0 : return false;
961 : }
962 :
963 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
964 0 : if (!obj) {
965 0 : return false;
966 : }
967 0 : rval.set(JS::ObjectValue(*obj));
968 :
969 : do {
970 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
971 0 : JS::Rooted<JS::Value> temp(cx);
972 0 : double const & currentValue = mDuration;
973 0 : temp.set(JS_NumberValue(double(currentValue)));
974 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->duration_id, temp, JSPROP_ENUMERATE)) {
975 0 : return false;
976 : }
977 0 : break;
978 : } while(0);
979 :
980 : do {
981 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
982 0 : JS::Rooted<JS::Value> temp(cx);
983 0 : nsString const & currentValue = mName;
984 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
985 0 : return false;
986 : }
987 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
988 0 : return false;
989 : }
990 0 : break;
991 : } while(0);
992 :
993 0 : return true;
994 : }
995 :
996 : bool
997 0 : ConsoleTimerEnd::ToJSON(nsAString& aJSON) const
998 : {
999 0 : AutoJSAPI jsapi;
1000 0 : jsapi.Init();
1001 0 : JSContext *cx = jsapi.cx();
1002 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1003 : // because we'll only be creating objects, in ways that have no
1004 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1005 : // which likewise guarantees no side-effects for the sorts of
1006 : // things we will pass it.
1007 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
1008 0 : JS::Rooted<JS::Value> val(cx);
1009 0 : if (!ToObjectInternal(cx, &val)) {
1010 0 : return false;
1011 : }
1012 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
1013 0 : return StringifyToJSON(cx, obj, aJSON);
1014 : }
1015 :
1016 : void
1017 0 : ConsoleTimerEnd::TraceDictionary(JSTracer* trc)
1018 : {
1019 0 : }
1020 :
1021 : ConsoleTimerEnd&
1022 0 : ConsoleTimerEnd::operator=(const ConsoleTimerEnd& aOther)
1023 : {
1024 0 : mDuration = aOther.mDuration;
1025 0 : mName = aOther.mName;
1026 0 : return *this;
1027 : }
1028 :
1029 : namespace binding_detail {
1030 : } // namespace binding_detail
1031 :
1032 :
1033 :
1034 0 : ConsoleTimerError::ConsoleTimerError()
1035 : {
1036 : // Safe to pass a null context if we pass a null value
1037 0 : Init(nullptr, JS::NullHandleValue);
1038 0 : }
1039 :
1040 :
1041 :
1042 : bool
1043 0 : ConsoleTimerError::InitIds(JSContext* cx, ConsoleTimerErrorAtoms* atomsCache)
1044 : {
1045 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1046 :
1047 : // Initialize these in reverse order so that any failure leaves the first one
1048 : // uninitialized.
1049 0 : if (!atomsCache->name_id.init(cx, "name") ||
1050 0 : !atomsCache->error_id.init(cx, "error")) {
1051 0 : return false;
1052 : }
1053 0 : return true;
1054 : }
1055 :
1056 : bool
1057 0 : ConsoleTimerError::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1058 : {
1059 : // Passing a null JSContext is OK only if we're initing from null,
1060 : // Since in that case we will not have to do any property gets
1061 : // Also evaluate isNullOrUndefined in order to avoid false-positive
1062 : // checkers by static analysis tools
1063 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1064 0 : ConsoleTimerErrorAtoms* atomsCache = nullptr;
1065 0 : if (cx) {
1066 0 : atomsCache = GetAtomCache<ConsoleTimerErrorAtoms>(cx);
1067 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1068 0 : return false;
1069 : }
1070 : }
1071 :
1072 0 : if (!IsConvertibleToDictionary(val)) {
1073 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
1074 : }
1075 :
1076 0 : bool isNull = val.isNullOrUndefined();
1077 : // We only need these if !isNull, in which case we have |cx|.
1078 0 : Maybe<JS::Rooted<JSObject *> > object;
1079 0 : Maybe<JS::Rooted<JS::Value> > temp;
1080 0 : if (!isNull) {
1081 0 : MOZ_ASSERT(cx);
1082 0 : object.emplace(cx, &val.toObject());
1083 0 : temp.emplace(cx);
1084 : }
1085 0 : if (!isNull) {
1086 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->error_id, temp.ptr())) {
1087 0 : return false;
1088 : }
1089 : }
1090 0 : if (!isNull && !temp->isUndefined()) {
1091 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mError)) {
1092 0 : return false;
1093 : }
1094 : } else {
1095 : static const char16_t data[] = { 0 };
1096 0 : mError.Rebind(data, ArrayLength(data) - 1);
1097 : }
1098 0 : mIsAnyMemberPresent = true;
1099 :
1100 0 : if (!isNull) {
1101 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
1102 0 : return false;
1103 : }
1104 : }
1105 0 : if (!isNull && !temp->isUndefined()) {
1106 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
1107 0 : return false;
1108 : }
1109 : } else {
1110 : static const char16_t data[] = { 0 };
1111 0 : mName.Rebind(data, ArrayLength(data) - 1);
1112 : }
1113 0 : mIsAnyMemberPresent = true;
1114 0 : return true;
1115 : }
1116 :
1117 : bool
1118 0 : ConsoleTimerError::Init(const nsAString& aJSON)
1119 : {
1120 0 : AutoJSAPI jsapi;
1121 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1122 0 : if (!cleanGlobal) {
1123 0 : return false;
1124 : }
1125 0 : if (!jsapi.Init(cleanGlobal)) {
1126 0 : return false;
1127 : }
1128 0 : JSContext* cx = jsapi.cx();
1129 0 : JS::Rooted<JS::Value> json(cx);
1130 0 : bool ok = ParseJSON(cx, aJSON, &json);
1131 0 : NS_ENSURE_TRUE(ok, false);
1132 0 : return Init(cx, json);
1133 : }
1134 :
1135 : bool
1136 0 : ConsoleTimerError::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1137 : {
1138 0 : ConsoleTimerErrorAtoms* atomsCache = GetAtomCache<ConsoleTimerErrorAtoms>(cx);
1139 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1140 0 : return false;
1141 : }
1142 :
1143 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
1144 0 : if (!obj) {
1145 0 : return false;
1146 : }
1147 0 : rval.set(JS::ObjectValue(*obj));
1148 :
1149 : do {
1150 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1151 0 : JS::Rooted<JS::Value> temp(cx);
1152 0 : nsString const & currentValue = mError;
1153 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
1154 0 : return false;
1155 : }
1156 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->error_id, temp, JSPROP_ENUMERATE)) {
1157 0 : return false;
1158 : }
1159 0 : break;
1160 : } while(0);
1161 :
1162 : do {
1163 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1164 0 : JS::Rooted<JS::Value> temp(cx);
1165 0 : nsString const & currentValue = mName;
1166 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
1167 0 : return false;
1168 : }
1169 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
1170 0 : return false;
1171 : }
1172 0 : break;
1173 : } while(0);
1174 :
1175 0 : return true;
1176 : }
1177 :
1178 : bool
1179 0 : ConsoleTimerError::ToJSON(nsAString& aJSON) const
1180 : {
1181 0 : AutoJSAPI jsapi;
1182 0 : jsapi.Init();
1183 0 : JSContext *cx = jsapi.cx();
1184 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1185 : // because we'll only be creating objects, in ways that have no
1186 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1187 : // which likewise guarantees no side-effects for the sorts of
1188 : // things we will pass it.
1189 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
1190 0 : JS::Rooted<JS::Value> val(cx);
1191 0 : if (!ToObjectInternal(cx, &val)) {
1192 0 : return false;
1193 : }
1194 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
1195 0 : return StringifyToJSON(cx, obj, aJSON);
1196 : }
1197 :
1198 : void
1199 0 : ConsoleTimerError::TraceDictionary(JSTracer* trc)
1200 : {
1201 0 : }
1202 :
1203 : ConsoleTimerError&
1204 0 : ConsoleTimerError::operator=(const ConsoleTimerError& aOther)
1205 : {
1206 0 : mError = aOther.mError;
1207 0 : mName = aOther.mName;
1208 0 : return *this;
1209 : }
1210 :
1211 : namespace binding_detail {
1212 : } // namespace binding_detail
1213 :
1214 :
1215 :
1216 0 : ConsoleTimerStart::ConsoleTimerStart()
1217 : {
1218 : // Safe to pass a null context if we pass a null value
1219 0 : Init(nullptr, JS::NullHandleValue);
1220 0 : }
1221 :
1222 :
1223 :
1224 : bool
1225 0 : ConsoleTimerStart::InitIds(JSContext* cx, ConsoleTimerStartAtoms* atomsCache)
1226 : {
1227 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1228 :
1229 : // Initialize these in reverse order so that any failure leaves the first one
1230 : // uninitialized.
1231 0 : if (!atomsCache->name_id.init(cx, "name")) {
1232 0 : return false;
1233 : }
1234 0 : return true;
1235 : }
1236 :
1237 : bool
1238 0 : ConsoleTimerStart::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1239 : {
1240 : // Passing a null JSContext is OK only if we're initing from null,
1241 : // Since in that case we will not have to do any property gets
1242 : // Also evaluate isNullOrUndefined in order to avoid false-positive
1243 : // checkers by static analysis tools
1244 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1245 0 : ConsoleTimerStartAtoms* atomsCache = nullptr;
1246 0 : if (cx) {
1247 0 : atomsCache = GetAtomCache<ConsoleTimerStartAtoms>(cx);
1248 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1249 0 : return false;
1250 : }
1251 : }
1252 :
1253 0 : if (!IsConvertibleToDictionary(val)) {
1254 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
1255 : }
1256 :
1257 0 : bool isNull = val.isNullOrUndefined();
1258 : // We only need these if !isNull, in which case we have |cx|.
1259 0 : Maybe<JS::Rooted<JSObject *> > object;
1260 0 : Maybe<JS::Rooted<JS::Value> > temp;
1261 0 : if (!isNull) {
1262 0 : MOZ_ASSERT(cx);
1263 0 : object.emplace(cx, &val.toObject());
1264 0 : temp.emplace(cx);
1265 : }
1266 0 : if (!isNull) {
1267 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
1268 0 : return false;
1269 : }
1270 : }
1271 0 : if (!isNull && !temp->isUndefined()) {
1272 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
1273 0 : return false;
1274 : }
1275 : } else {
1276 : static const char16_t data[] = { 0 };
1277 0 : mName.Rebind(data, ArrayLength(data) - 1);
1278 : }
1279 0 : mIsAnyMemberPresent = true;
1280 0 : return true;
1281 : }
1282 :
1283 : bool
1284 0 : ConsoleTimerStart::Init(const nsAString& aJSON)
1285 : {
1286 0 : AutoJSAPI jsapi;
1287 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
1288 0 : if (!cleanGlobal) {
1289 0 : return false;
1290 : }
1291 0 : if (!jsapi.Init(cleanGlobal)) {
1292 0 : return false;
1293 : }
1294 0 : JSContext* cx = jsapi.cx();
1295 0 : JS::Rooted<JS::Value> json(cx);
1296 0 : bool ok = ParseJSON(cx, aJSON, &json);
1297 0 : NS_ENSURE_TRUE(ok, false);
1298 0 : return Init(cx, json);
1299 : }
1300 :
1301 : bool
1302 0 : ConsoleTimerStart::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1303 : {
1304 0 : ConsoleTimerStartAtoms* atomsCache = GetAtomCache<ConsoleTimerStartAtoms>(cx);
1305 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1306 0 : return false;
1307 : }
1308 :
1309 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
1310 0 : if (!obj) {
1311 0 : return false;
1312 : }
1313 0 : rval.set(JS::ObjectValue(*obj));
1314 :
1315 : do {
1316 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
1317 0 : JS::Rooted<JS::Value> temp(cx);
1318 0 : nsString const & currentValue = mName;
1319 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
1320 0 : return false;
1321 : }
1322 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
1323 0 : return false;
1324 : }
1325 0 : break;
1326 : } while(0);
1327 :
1328 0 : return true;
1329 : }
1330 :
1331 : bool
1332 0 : ConsoleTimerStart::ToJSON(nsAString& aJSON) const
1333 : {
1334 0 : AutoJSAPI jsapi;
1335 0 : jsapi.Init();
1336 0 : JSContext *cx = jsapi.cx();
1337 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
1338 : // because we'll only be creating objects, in ways that have no
1339 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
1340 : // which likewise guarantees no side-effects for the sorts of
1341 : // things we will pass it.
1342 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
1343 0 : JS::Rooted<JS::Value> val(cx);
1344 0 : if (!ToObjectInternal(cx, &val)) {
1345 0 : return false;
1346 : }
1347 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
1348 0 : return StringifyToJSON(cx, obj, aJSON);
1349 : }
1350 :
1351 : void
1352 0 : ConsoleTimerStart::TraceDictionary(JSTracer* trc)
1353 : {
1354 0 : }
1355 :
1356 : ConsoleTimerStart&
1357 0 : ConsoleTimerStart::operator=(const ConsoleTimerStart& aOther)
1358 : {
1359 0 : mName = aOther.mName;
1360 0 : return *this;
1361 : }
1362 :
1363 : namespace binding_detail {
1364 : } // namespace binding_detail
1365 :
1366 :
1367 : bool
1368 0 : UnsignedLongLongOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
1369 : {
1370 0 : switch (mType) {
1371 : case eUninitialized: {
1372 0 : return false;
1373 : break;
1374 : }
1375 : case eUnsignedLongLong: {
1376 0 : rval.set(JS_NumberValue(double(mValue.mUnsignedLongLong.Value())));
1377 0 : return true;
1378 : break;
1379 : }
1380 : case eString: {
1381 0 : if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
1382 0 : return false;
1383 : }
1384 0 : return true;
1385 : break;
1386 : }
1387 : default: {
1388 0 : return false;
1389 : break;
1390 : }
1391 : }
1392 :
1393 : return false;
1394 : }
1395 :
1396 :
1397 : uint64_t&
1398 0 : OwningUnsignedLongLongOrString::RawSetAsUnsignedLongLong()
1399 : {
1400 0 : if (mType == eUnsignedLongLong) {
1401 0 : return mValue.mUnsignedLongLong.Value();
1402 : }
1403 0 : MOZ_ASSERT(mType == eUninitialized);
1404 0 : mType = eUnsignedLongLong;
1405 0 : return mValue.mUnsignedLongLong.SetValue();
1406 : }
1407 :
1408 : uint64_t&
1409 2 : OwningUnsignedLongLongOrString::SetAsUnsignedLongLong()
1410 : {
1411 2 : if (mType == eUnsignedLongLong) {
1412 0 : return mValue.mUnsignedLongLong.Value();
1413 : }
1414 2 : Uninit();
1415 2 : mType = eUnsignedLongLong;
1416 2 : return mValue.mUnsignedLongLong.SetValue();
1417 : }
1418 :
1419 : bool
1420 0 : OwningUnsignedLongLongOrString::TrySetToUnsignedLongLong(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
1421 : {
1422 0 : tryNext = false;
1423 : { // scope for memberSlot
1424 0 : uint64_t& memberSlot = RawSetAsUnsignedLongLong();
1425 0 : if (!ValueToPrimitive<uint64_t, eDefault>(cx, value, &memberSlot)) {
1426 0 : return false;
1427 : }
1428 : }
1429 0 : return true;
1430 : }
1431 :
1432 : void
1433 2 : OwningUnsignedLongLongOrString::DestroyUnsignedLongLong()
1434 : {
1435 2 : MOZ_ASSERT(IsUnsignedLongLong(), "Wrong type!");
1436 2 : mValue.mUnsignedLongLong.Destroy();
1437 2 : mType = eUninitialized;
1438 2 : }
1439 :
1440 :
1441 :
1442 :
1443 : nsString&
1444 0 : OwningUnsignedLongLongOrString::RawSetAsString()
1445 : {
1446 0 : if (mType == eString) {
1447 0 : return mValue.mString.Value();
1448 : }
1449 0 : MOZ_ASSERT(mType == eUninitialized);
1450 0 : mType = eString;
1451 0 : return mValue.mString.SetValue();
1452 : }
1453 :
1454 : nsString&
1455 0 : OwningUnsignedLongLongOrString::SetAsString()
1456 : {
1457 0 : if (mType == eString) {
1458 0 : return mValue.mString.Value();
1459 : }
1460 0 : Uninit();
1461 0 : mType = eString;
1462 0 : return mValue.mString.SetValue();
1463 : }
1464 :
1465 : bool
1466 0 : OwningUnsignedLongLongOrString::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
1467 : {
1468 0 : tryNext = false;
1469 : { // scope for memberSlot
1470 0 : nsString& memberSlot = RawSetAsString();
1471 0 : if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) {
1472 0 : return false;
1473 : }
1474 : }
1475 0 : return true;
1476 : }
1477 :
1478 :
1479 : void
1480 0 : OwningUnsignedLongLongOrString::DestroyString()
1481 : {
1482 0 : MOZ_ASSERT(IsString(), "Wrong type!");
1483 0 : mValue.mString.Destroy();
1484 0 : mType = eUninitialized;
1485 0 : }
1486 :
1487 :
1488 :
1489 :
1490 : void
1491 4 : OwningUnsignedLongLongOrString::Uninit()
1492 : {
1493 4 : switch (mType) {
1494 : case eUninitialized: {
1495 2 : break;
1496 : }
1497 : case eUnsignedLongLong: {
1498 2 : DestroyUnsignedLongLong();
1499 2 : break;
1500 : }
1501 : case eString: {
1502 0 : DestroyString();
1503 0 : break;
1504 : }
1505 : }
1506 4 : }
1507 :
1508 : bool
1509 2 : OwningUnsignedLongLongOrString::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
1510 : {
1511 2 : switch (mType) {
1512 : case eUninitialized: {
1513 0 : return false;
1514 : break;
1515 : }
1516 : case eUnsignedLongLong: {
1517 2 : rval.set(JS_NumberValue(double(mValue.mUnsignedLongLong.Value())));
1518 2 : return true;
1519 : break;
1520 : }
1521 : case eString: {
1522 0 : if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) {
1523 0 : return false;
1524 : }
1525 0 : return true;
1526 : break;
1527 : }
1528 : default: {
1529 0 : return false;
1530 : break;
1531 : }
1532 : }
1533 :
1534 : return false;
1535 : }
1536 :
1537 : void
1538 0 : OwningUnsignedLongLongOrString::TraceUnion(JSTracer* trc)
1539 : {
1540 0 : }
1541 :
1542 : OwningUnsignedLongLongOrString&
1543 0 : OwningUnsignedLongLongOrString::operator=(const OwningUnsignedLongLongOrString& aOther)
1544 : {
1545 0 : switch (aOther.mType) {
1546 : case eUninitialized: {
1547 0 : MOZ_ASSERT(mType == eUninitialized,
1548 : "We need to destroy ourselves?");
1549 0 : break;
1550 : }
1551 : case eUnsignedLongLong: {
1552 0 : SetAsUnsignedLongLong() = aOther.GetAsUnsignedLongLong();
1553 0 : break;
1554 : }
1555 : case eString: {
1556 0 : SetAsString() = aOther.GetAsString();
1557 0 : break;
1558 : }
1559 : }
1560 0 : return *this;
1561 : }
1562 :
1563 :
1564 :
1565 1 : ConsoleEvent::ConsoleEvent()
1566 : : mCounter(JS::UndefinedValue()),
1567 : mOriginAttributes(JS::UndefinedValue()),
1568 1 : mTimer(JS::UndefinedValue())
1569 : {
1570 : // Safe to pass a null context if we pass a null value
1571 1 : Init(nullptr, JS::NullHandleValue);
1572 1 : }
1573 :
1574 :
1575 : bool
1576 1 : ConsoleEvent::InitIds(JSContext* cx, ConsoleEventAtoms* atomsCache)
1577 : {
1578 1 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
1579 :
1580 : // Initialize these in reverse order so that any failure leaves the first one
1581 : // uninitialized.
1582 3 : if (!atomsCache->timer_id.init(cx, "timer") ||
1583 2 : !atomsCache->timeStamp_id.init(cx, "timeStamp") ||
1584 2 : !atomsCache->styles_id.init(cx, "styles") ||
1585 2 : !atomsCache->private_id.init(cx, "private") ||
1586 2 : !atomsCache->originAttributes_id.init(cx, "originAttributes") ||
1587 2 : !atomsCache->lineNumber_id.init(cx, "lineNumber") ||
1588 2 : !atomsCache->level_id.init(cx, "level") ||
1589 2 : !atomsCache->innerID_id.init(cx, "innerID") ||
1590 2 : !atomsCache->groupName_id.init(cx, "groupName") ||
1591 2 : !atomsCache->functionName_id.init(cx, "functionName") ||
1592 2 : !atomsCache->filename_id.init(cx, "filename") ||
1593 2 : !atomsCache->counter_id.init(cx, "counter") ||
1594 2 : !atomsCache->columnNumber_id.init(cx, "columnNumber") ||
1595 2 : !atomsCache->arguments_id.init(cx, "arguments") ||
1596 3 : !atomsCache->addonId_id.init(cx, "addonId") ||
1597 1 : !atomsCache->ID_id.init(cx, "ID")) {
1598 0 : return false;
1599 : }
1600 1 : return true;
1601 : }
1602 :
1603 : bool
1604 1 : ConsoleEvent::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
1605 : {
1606 : // Passing a null JSContext is OK only if we're initing from null,
1607 : // Since in that case we will not have to do any property gets
1608 : // Also evaluate isNullOrUndefined in order to avoid false-positive
1609 : // checkers by static analysis tools
1610 1 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
1611 1 : ConsoleEventAtoms* atomsCache = nullptr;
1612 1 : if (cx) {
1613 0 : atomsCache = GetAtomCache<ConsoleEventAtoms>(cx);
1614 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1615 0 : return false;
1616 : }
1617 : }
1618 :
1619 1 : if (!IsConvertibleToDictionary(val)) {
1620 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
1621 : }
1622 :
1623 1 : bool isNull = val.isNullOrUndefined();
1624 : // We only need these if !isNull, in which case we have |cx|.
1625 2 : Maybe<JS::Rooted<JSObject *> > object;
1626 2 : Maybe<JS::Rooted<JS::Value> > temp;
1627 1 : if (!isNull) {
1628 0 : MOZ_ASSERT(cx);
1629 0 : object.emplace(cx, &val.toObject());
1630 0 : temp.emplace(cx);
1631 : }
1632 1 : if (!isNull) {
1633 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->ID_id, temp.ptr())) {
1634 0 : return false;
1635 : }
1636 : }
1637 1 : if (!isNull && !temp->isUndefined()) {
1638 0 : mID.Construct();
1639 : {
1640 0 : bool done = false, failed = false, tryNext;
1641 : do {
1642 0 : if (temp.ref().isNumber()) {
1643 0 : done = (failed = !(mID.Value()).TrySetToUnsignedLongLong(cx, temp.ref(), tryNext)) || !tryNext;
1644 0 : break;
1645 : }
1646 0 : done = (failed = !(mID.Value()).TrySetToString(cx, temp.ref(), tryNext)) || !tryNext;
1647 0 : break;
1648 : } while (0);
1649 0 : if (failed) {
1650 0 : return false;
1651 : }
1652 0 : if (!done) {
1653 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'ID' member of ConsoleEvent", "");
1654 0 : return false;
1655 : }
1656 : }
1657 0 : mIsAnyMemberPresent = true;
1658 : }
1659 :
1660 1 : if (!isNull) {
1661 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->addonId_id, temp.ptr())) {
1662 0 : return false;
1663 : }
1664 : }
1665 1 : if (!isNull && !temp->isUndefined()) {
1666 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mAddonId)) {
1667 0 : return false;
1668 : }
1669 : } else {
1670 : static const char16_t data[] = { 0 };
1671 1 : mAddonId.Rebind(data, ArrayLength(data) - 1);
1672 : }
1673 1 : mIsAnyMemberPresent = true;
1674 :
1675 1 : if (!isNull) {
1676 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->arguments_id, temp.ptr())) {
1677 0 : return false;
1678 : }
1679 : }
1680 1 : if (!isNull && !temp->isUndefined()) {
1681 0 : mArguments.Construct();
1682 0 : if (temp.ref().isObject()) {
1683 0 : JS::ForOfIterator iter(cx);
1684 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
1685 0 : return false;
1686 : }
1687 0 : if (!iter.valueIsIterable()) {
1688 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'arguments' member of ConsoleEvent");
1689 0 : return false;
1690 : }
1691 0 : Sequence<JS::Value> &arr = (mArguments.Value());
1692 0 : JS::Rooted<JS::Value> temp(cx);
1693 : while (true) {
1694 : bool done;
1695 0 : if (!iter.next(&temp, &done)) {
1696 0 : return false;
1697 : }
1698 0 : if (done) {
1699 0 : break;
1700 : }
1701 0 : JS::Value* slotPtr = arr.AppendElement(mozilla::fallible);
1702 0 : if (!slotPtr) {
1703 0 : JS_ReportOutOfMemory(cx);
1704 0 : return false;
1705 : }
1706 0 : JS::Value& slot = *slotPtr;
1707 : #ifdef __clang__
1708 : #pragma clang diagnostic push
1709 : #pragma clang diagnostic ignored "-Wunreachable-code"
1710 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
1711 : #endif // __clang__
1712 0 : if ((passedToJSImpl) && !CallerSubsumes(temp)) {
1713 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "element of 'arguments' member of ConsoleEvent");
1714 0 : return false;
1715 : }
1716 : #ifdef __clang__
1717 : #pragma clang diagnostic pop
1718 : #endif // __clang__
1719 0 : slot = temp;
1720 0 : }
1721 : } else {
1722 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'arguments' member of ConsoleEvent");
1723 0 : return false;
1724 : }
1725 0 : mIsAnyMemberPresent = true;
1726 : }
1727 :
1728 1 : if (!isNull) {
1729 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->columnNumber_id, temp.ptr())) {
1730 0 : return false;
1731 : }
1732 : }
1733 1 : if (!isNull && !temp->isUndefined()) {
1734 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mColumnNumber)) {
1735 0 : return false;
1736 : }
1737 : } else {
1738 1 : mColumnNumber = 0U;
1739 : }
1740 1 : mIsAnyMemberPresent = true;
1741 :
1742 1 : if (!isNull) {
1743 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->counter_id, temp.ptr())) {
1744 0 : return false;
1745 : }
1746 : }
1747 1 : if (!isNull && !temp->isUndefined()) {
1748 : #ifdef __clang__
1749 : #pragma clang diagnostic push
1750 : #pragma clang diagnostic ignored "-Wunreachable-code"
1751 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
1752 : #endif // __clang__
1753 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
1754 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'counter' member of ConsoleEvent");
1755 0 : return false;
1756 : }
1757 : #ifdef __clang__
1758 : #pragma clang diagnostic pop
1759 : #endif // __clang__
1760 0 : mCounter = temp.ref();
1761 : } else {
1762 1 : mCounter = JS::NullValue();
1763 : }
1764 1 : mIsAnyMemberPresent = true;
1765 :
1766 1 : if (!isNull) {
1767 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->filename_id, temp.ptr())) {
1768 0 : return false;
1769 : }
1770 : }
1771 1 : if (!isNull && !temp->isUndefined()) {
1772 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFilename)) {
1773 0 : return false;
1774 : }
1775 : } else {
1776 : static const char16_t data[] = { 0 };
1777 1 : mFilename.Rebind(data, ArrayLength(data) - 1);
1778 : }
1779 1 : mIsAnyMemberPresent = true;
1780 :
1781 1 : if (!isNull) {
1782 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->functionName_id, temp.ptr())) {
1783 0 : return false;
1784 : }
1785 : }
1786 1 : if (!isNull && !temp->isUndefined()) {
1787 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mFunctionName)) {
1788 0 : return false;
1789 : }
1790 : } else {
1791 : static const char16_t data[] = { 0 };
1792 1 : mFunctionName.Rebind(data, ArrayLength(data) - 1);
1793 : }
1794 1 : mIsAnyMemberPresent = true;
1795 :
1796 1 : if (!isNull) {
1797 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->groupName_id, temp.ptr())) {
1798 0 : return false;
1799 : }
1800 : }
1801 1 : if (!isNull && !temp->isUndefined()) {
1802 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mGroupName)) {
1803 0 : return false;
1804 : }
1805 : } else {
1806 : static const char16_t data[] = { 0 };
1807 1 : mGroupName.Rebind(data, ArrayLength(data) - 1);
1808 : }
1809 1 : mIsAnyMemberPresent = true;
1810 :
1811 1 : if (!isNull) {
1812 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->innerID_id, temp.ptr())) {
1813 0 : return false;
1814 : }
1815 : }
1816 1 : if (!isNull && !temp->isUndefined()) {
1817 0 : mInnerID.Construct();
1818 : {
1819 0 : bool done = false, failed = false, tryNext;
1820 : do {
1821 0 : if (temp.ref().isNumber()) {
1822 0 : done = (failed = !(mInnerID.Value()).TrySetToUnsignedLongLong(cx, temp.ref(), tryNext)) || !tryNext;
1823 0 : break;
1824 : }
1825 0 : done = (failed = !(mInnerID.Value()).TrySetToString(cx, temp.ref(), tryNext)) || !tryNext;
1826 0 : break;
1827 : } while (0);
1828 0 : if (failed) {
1829 0 : return false;
1830 : }
1831 0 : if (!done) {
1832 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'innerID' member of ConsoleEvent", "");
1833 0 : return false;
1834 : }
1835 : }
1836 0 : mIsAnyMemberPresent = true;
1837 : }
1838 :
1839 1 : if (!isNull) {
1840 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->level_id, temp.ptr())) {
1841 0 : return false;
1842 : }
1843 : }
1844 1 : if (!isNull && !temp->isUndefined()) {
1845 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLevel)) {
1846 0 : return false;
1847 : }
1848 : } else {
1849 : static const char16_t data[] = { 0 };
1850 1 : mLevel.Rebind(data, ArrayLength(data) - 1);
1851 : }
1852 1 : mIsAnyMemberPresent = true;
1853 :
1854 1 : if (!isNull) {
1855 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->lineNumber_id, temp.ptr())) {
1856 0 : return false;
1857 : }
1858 : }
1859 1 : if (!isNull && !temp->isUndefined()) {
1860 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mLineNumber)) {
1861 0 : return false;
1862 : }
1863 : } else {
1864 1 : mLineNumber = 0U;
1865 : }
1866 1 : mIsAnyMemberPresent = true;
1867 :
1868 1 : if (!isNull) {
1869 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->originAttributes_id, temp.ptr())) {
1870 0 : return false;
1871 : }
1872 : }
1873 1 : if (!isNull && !temp->isUndefined()) {
1874 : #ifdef __clang__
1875 : #pragma clang diagnostic push
1876 : #pragma clang diagnostic ignored "-Wunreachable-code"
1877 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
1878 : #endif // __clang__
1879 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
1880 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'originAttributes' member of ConsoleEvent");
1881 0 : return false;
1882 : }
1883 : #ifdef __clang__
1884 : #pragma clang diagnostic pop
1885 : #endif // __clang__
1886 0 : mOriginAttributes = temp.ref();
1887 : } else {
1888 1 : mOriginAttributes = JS::NullValue();
1889 : }
1890 1 : mIsAnyMemberPresent = true;
1891 :
1892 1 : if (!isNull) {
1893 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->private_id, temp.ptr())) {
1894 0 : return false;
1895 : }
1896 : }
1897 1 : if (!isNull && !temp->isUndefined()) {
1898 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mPrivate)) {
1899 0 : return false;
1900 : }
1901 : } else {
1902 1 : mPrivate = false;
1903 : }
1904 1 : mIsAnyMemberPresent = true;
1905 :
1906 1 : if (!isNull) {
1907 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->styles_id, temp.ptr())) {
1908 0 : return false;
1909 : }
1910 : }
1911 1 : if (!isNull && !temp->isUndefined()) {
1912 0 : mStyles.Construct();
1913 0 : if (temp.ref().isObject()) {
1914 0 : JS::ForOfIterator iter(cx);
1915 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
1916 0 : return false;
1917 : }
1918 0 : if (!iter.valueIsIterable()) {
1919 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'styles' member of ConsoleEvent");
1920 0 : return false;
1921 : }
1922 0 : Sequence<nsString> &arr = (mStyles.Value());
1923 0 : JS::Rooted<JS::Value> temp(cx);
1924 : while (true) {
1925 : bool done;
1926 0 : if (!iter.next(&temp, &done)) {
1927 0 : return false;
1928 : }
1929 0 : if (done) {
1930 0 : break;
1931 : }
1932 0 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
1933 0 : if (!slotPtr) {
1934 0 : JS_ReportOutOfMemory(cx);
1935 0 : return false;
1936 : }
1937 0 : nsString& slot = *slotPtr;
1938 0 : if (!ConvertJSValueToString(cx, temp, eNull, eNull, slot)) {
1939 0 : return false;
1940 : }
1941 0 : }
1942 : } else {
1943 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'styles' member of ConsoleEvent");
1944 0 : return false;
1945 : }
1946 0 : mIsAnyMemberPresent = true;
1947 : }
1948 :
1949 1 : if (!isNull) {
1950 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->timeStamp_id, temp.ptr())) {
1951 0 : return false;
1952 : }
1953 : }
1954 1 : if (!isNull && !temp->isUndefined()) {
1955 0 : if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mTimeStamp)) {
1956 0 : return false;
1957 0 : } else if (!mozilla::IsFinite(mTimeStamp)) {
1958 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'timeStamp' member of ConsoleEvent");
1959 0 : return false;
1960 : }
1961 : } else {
1962 1 : mTimeStamp = 0.0;
1963 : }
1964 1 : mIsAnyMemberPresent = true;
1965 :
1966 1 : if (!isNull) {
1967 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->timer_id, temp.ptr())) {
1968 0 : return false;
1969 : }
1970 : }
1971 1 : if (!isNull && !temp->isUndefined()) {
1972 : #ifdef __clang__
1973 : #pragma clang diagnostic push
1974 : #pragma clang diagnostic ignored "-Wunreachable-code"
1975 : #pragma clang diagnostic ignored "-Wunreachable-code-return"
1976 : #endif // __clang__
1977 0 : if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
1978 0 : ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'timer' member of ConsoleEvent");
1979 0 : return false;
1980 : }
1981 : #ifdef __clang__
1982 : #pragma clang diagnostic pop
1983 : #endif // __clang__
1984 0 : mTimer = temp.ref();
1985 : } else {
1986 1 : mTimer = JS::NullValue();
1987 : }
1988 1 : mIsAnyMemberPresent = true;
1989 1 : return true;
1990 : }
1991 :
1992 : bool
1993 1 : ConsoleEvent::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
1994 : {
1995 1 : ConsoleEventAtoms* atomsCache = GetAtomCache<ConsoleEventAtoms>(cx);
1996 1 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
1997 0 : return false;
1998 : }
1999 :
2000 2 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
2001 1 : if (!obj) {
2002 0 : return false;
2003 : }
2004 1 : rval.set(JS::ObjectValue(*obj));
2005 :
2006 1 : if (mID.WasPassed()) {
2007 : do {
2008 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2009 1 : JS::Rooted<JS::Value> temp(cx);
2010 1 : OwningUnsignedLongLongOrString const & currentValue = mID.InternalValue();
2011 1 : if (!currentValue.ToJSVal(cx, obj, &temp)) {
2012 0 : return false;
2013 : }
2014 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->ID_id, temp, JSPROP_ENUMERATE)) {
2015 0 : return false;
2016 : }
2017 1 : break;
2018 : } while(0);
2019 : }
2020 :
2021 : do {
2022 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2023 1 : JS::Rooted<JS::Value> temp(cx);
2024 1 : nsString const & currentValue = mAddonId;
2025 1 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
2026 0 : return false;
2027 : }
2028 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->addonId_id, temp, JSPROP_ENUMERATE)) {
2029 0 : return false;
2030 : }
2031 1 : break;
2032 : } while(0);
2033 :
2034 1 : if (mArguments.WasPassed()) {
2035 : do {
2036 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2037 1 : JS::Rooted<JS::Value> temp(cx);
2038 1 : Sequence<JS::Value> const & currentValue = mArguments.InternalValue();
2039 :
2040 1 : uint32_t length = currentValue.Length();
2041 1 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
2042 1 : if (!returnArray) {
2043 0 : return false;
2044 : }
2045 : // Scope for 'tmp'
2046 : {
2047 2 : JS::Rooted<JS::Value> tmp(cx);
2048 2 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
2049 : // Control block to let us common up the JS_DefineElement calls when there
2050 : // are different ways to succeed at wrapping the object.
2051 : do {
2052 1 : JS::ExposeValueToActiveJS(currentValue[sequenceIdx0]);
2053 1 : tmp.set(currentValue[sequenceIdx0]);
2054 1 : if (!MaybeWrapValue(cx, &tmp)) {
2055 0 : return false;
2056 : }
2057 1 : break;
2058 : } while (0);
2059 1 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
2060 : JSPROP_ENUMERATE)) {
2061 0 : return false;
2062 : }
2063 : }
2064 : }
2065 1 : temp.setObject(*returnArray);
2066 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->arguments_id, temp, JSPROP_ENUMERATE)) {
2067 0 : return false;
2068 : }
2069 1 : break;
2070 : } while(0);
2071 : }
2072 :
2073 : do {
2074 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2075 1 : JS::Rooted<JS::Value> temp(cx);
2076 1 : uint32_t const & currentValue = mColumnNumber;
2077 1 : temp.setNumber(currentValue);
2078 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->columnNumber_id, temp, JSPROP_ENUMERATE)) {
2079 0 : return false;
2080 : }
2081 1 : break;
2082 : } while(0);
2083 :
2084 : do {
2085 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2086 1 : JS::Rooted<JS::Value> temp(cx);
2087 1 : JS::Value const & currentValue = mCounter;
2088 1 : JS::ExposeValueToActiveJS(currentValue);
2089 1 : temp.set(currentValue);
2090 1 : if (!MaybeWrapValue(cx, &temp)) {
2091 0 : return false;
2092 : }
2093 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->counter_id, temp, JSPROP_ENUMERATE)) {
2094 0 : return false;
2095 : }
2096 1 : break;
2097 : } while(0);
2098 :
2099 : do {
2100 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2101 1 : JS::Rooted<JS::Value> temp(cx);
2102 1 : nsString const & currentValue = mFilename;
2103 1 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
2104 0 : return false;
2105 : }
2106 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->filename_id, temp, JSPROP_ENUMERATE)) {
2107 0 : return false;
2108 : }
2109 1 : break;
2110 : } while(0);
2111 :
2112 : do {
2113 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2114 1 : JS::Rooted<JS::Value> temp(cx);
2115 1 : nsString const & currentValue = mFunctionName;
2116 1 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
2117 0 : return false;
2118 : }
2119 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->functionName_id, temp, JSPROP_ENUMERATE)) {
2120 0 : return false;
2121 : }
2122 1 : break;
2123 : } while(0);
2124 :
2125 : do {
2126 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2127 1 : JS::Rooted<JS::Value> temp(cx);
2128 1 : nsString const & currentValue = mGroupName;
2129 1 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
2130 0 : return false;
2131 : }
2132 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->groupName_id, temp, JSPROP_ENUMERATE)) {
2133 0 : return false;
2134 : }
2135 1 : break;
2136 : } while(0);
2137 :
2138 1 : if (mInnerID.WasPassed()) {
2139 : do {
2140 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2141 1 : JS::Rooted<JS::Value> temp(cx);
2142 1 : OwningUnsignedLongLongOrString const & currentValue = mInnerID.InternalValue();
2143 1 : if (!currentValue.ToJSVal(cx, obj, &temp)) {
2144 0 : return false;
2145 : }
2146 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->innerID_id, temp, JSPROP_ENUMERATE)) {
2147 0 : return false;
2148 : }
2149 1 : break;
2150 : } while(0);
2151 : }
2152 :
2153 : do {
2154 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2155 1 : JS::Rooted<JS::Value> temp(cx);
2156 1 : nsString const & currentValue = mLevel;
2157 1 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
2158 0 : return false;
2159 : }
2160 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->level_id, temp, JSPROP_ENUMERATE)) {
2161 0 : return false;
2162 : }
2163 1 : break;
2164 : } while(0);
2165 :
2166 : do {
2167 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2168 1 : JS::Rooted<JS::Value> temp(cx);
2169 1 : uint32_t const & currentValue = mLineNumber;
2170 1 : temp.setNumber(currentValue);
2171 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->lineNumber_id, temp, JSPROP_ENUMERATE)) {
2172 0 : return false;
2173 : }
2174 1 : break;
2175 : } while(0);
2176 :
2177 : do {
2178 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2179 1 : JS::Rooted<JS::Value> temp(cx);
2180 1 : JS::Value const & currentValue = mOriginAttributes;
2181 1 : JS::ExposeValueToActiveJS(currentValue);
2182 1 : temp.set(currentValue);
2183 1 : if (!MaybeWrapValue(cx, &temp)) {
2184 0 : return false;
2185 : }
2186 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->originAttributes_id, temp, JSPROP_ENUMERATE)) {
2187 0 : return false;
2188 : }
2189 1 : break;
2190 : } while(0);
2191 :
2192 : do {
2193 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2194 1 : JS::Rooted<JS::Value> temp(cx);
2195 1 : bool const & currentValue = mPrivate;
2196 1 : temp.setBoolean(currentValue);
2197 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->private_id, temp, JSPROP_ENUMERATE)) {
2198 0 : return false;
2199 : }
2200 1 : break;
2201 : } while(0);
2202 :
2203 1 : if (mStyles.WasPassed()) {
2204 : do {
2205 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2206 1 : JS::Rooted<JS::Value> temp(cx);
2207 1 : Sequence<nsString> const & currentValue = mStyles.InternalValue();
2208 :
2209 1 : uint32_t length = currentValue.Length();
2210 1 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
2211 1 : if (!returnArray) {
2212 0 : return false;
2213 : }
2214 : // Scope for 'tmp'
2215 : {
2216 2 : JS::Rooted<JS::Value> tmp(cx);
2217 1 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
2218 : // Control block to let us common up the JS_DefineElement calls when there
2219 : // are different ways to succeed at wrapping the object.
2220 : do {
2221 0 : if (!xpc::StringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
2222 0 : return false;
2223 : }
2224 0 : break;
2225 : } while (0);
2226 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
2227 : JSPROP_ENUMERATE)) {
2228 0 : return false;
2229 : }
2230 : }
2231 : }
2232 1 : temp.setObject(*returnArray);
2233 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->styles_id, temp, JSPROP_ENUMERATE)) {
2234 0 : return false;
2235 : }
2236 1 : break;
2237 : } while(0);
2238 : }
2239 :
2240 : do {
2241 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2242 1 : JS::Rooted<JS::Value> temp(cx);
2243 1 : double const & currentValue = mTimeStamp;
2244 1 : temp.set(JS_NumberValue(double(currentValue)));
2245 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->timeStamp_id, temp, JSPROP_ENUMERATE)) {
2246 0 : return false;
2247 : }
2248 1 : break;
2249 : } while(0);
2250 :
2251 : do {
2252 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
2253 1 : JS::Rooted<JS::Value> temp(cx);
2254 1 : JS::Value const & currentValue = mTimer;
2255 1 : JS::ExposeValueToActiveJS(currentValue);
2256 1 : temp.set(currentValue);
2257 1 : if (!MaybeWrapValue(cx, &temp)) {
2258 0 : return false;
2259 : }
2260 1 : if (!JS_DefinePropertyById(cx, obj, atomsCache->timer_id, temp, JSPROP_ENUMERATE)) {
2261 0 : return false;
2262 : }
2263 1 : break;
2264 : } while(0);
2265 :
2266 1 : return true;
2267 : }
2268 :
2269 : void
2270 0 : ConsoleEvent::TraceDictionary(JSTracer* trc)
2271 : {
2272 0 : if (mArguments.WasPassed()) {
2273 0 : DoTraceSequence(trc, mArguments.Value());
2274 : }
2275 :
2276 0 : JS::UnsafeTraceRoot(trc, &mCounter, "ConsoleEvent.mCounter");
2277 :
2278 0 : JS::UnsafeTraceRoot(trc, &mOriginAttributes, "ConsoleEvent.mOriginAttributes");
2279 :
2280 0 : JS::UnsafeTraceRoot(trc, &mTimer, "ConsoleEvent.mTimer");
2281 0 : }
2282 :
2283 : namespace binding_detail {
2284 : } // namespace binding_detail
2285 :
2286 :
2287 : namespace consoleBinding {
2288 :
2289 : static bool
2290 0 : _assert_(JSContext* cx, unsigned argc, JS::Value* vp)
2291 : {
2292 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2293 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2294 :
2295 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2296 0 : if (global.Failed()) {
2297 0 : return false;
2298 : }
2299 :
2300 : bool arg0;
2301 0 : if (args.hasDefined(0)) {
2302 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
2303 0 : return false;
2304 : }
2305 : } else {
2306 0 : arg0 = false;
2307 : }
2308 0 : binding_detail::AutoSequence<JS::Value> arg1;
2309 0 : SequenceRooter<JS::Value> arg1_holder(cx, &arg1);
2310 0 : if (args.length() > 1) {
2311 0 : if (!arg1.SetCapacity(args.length() - 1, mozilla::fallible)) {
2312 0 : JS_ReportOutOfMemory(cx);
2313 0 : return false;
2314 : }
2315 0 : for (uint32_t variadicArg = 1; variadicArg < args.length(); ++variadicArg) {
2316 0 : JS::Value& slot = *arg1.AppendElement(mozilla::fallible);
2317 0 : slot = args[variadicArg];
2318 : }
2319 : }
2320 0 : mozilla::dom::Console::Assert(global, arg0, Constify(arg1));
2321 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2322 0 : args.rval().setUndefined();
2323 0 : return true;
2324 : }
2325 :
2326 : static bool
2327 0 : clear(JSContext* cx, unsigned argc, JS::Value* vp)
2328 : {
2329 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2330 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2331 :
2332 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2333 0 : if (global.Failed()) {
2334 0 : return false;
2335 : }
2336 :
2337 0 : mozilla::dom::Console::Clear(global);
2338 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2339 0 : args.rval().setUndefined();
2340 0 : return true;
2341 : }
2342 :
2343 : static bool
2344 0 : count(JSContext* cx, unsigned argc, JS::Value* vp)
2345 : {
2346 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2347 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2348 :
2349 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2350 0 : if (global.Failed()) {
2351 0 : return false;
2352 : }
2353 :
2354 0 : binding_detail::FakeString arg0;
2355 0 : if (args.hasDefined(0)) {
2356 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
2357 0 : return false;
2358 : }
2359 : } else {
2360 : static const char16_t data[] = { 'd', 'e', 'f', 'a', 'u', 'l', 't', 0 };
2361 0 : arg0.Rebind(data, ArrayLength(data) - 1);
2362 : }
2363 0 : mozilla::dom::Console::Count(global, NonNullHelper(Constify(arg0)));
2364 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2365 0 : args.rval().setUndefined();
2366 0 : return true;
2367 : }
2368 :
2369 : static bool
2370 0 : debug(JSContext* cx, unsigned argc, JS::Value* vp)
2371 : {
2372 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2373 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2374 :
2375 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2376 0 : if (global.Failed()) {
2377 0 : return false;
2378 : }
2379 :
2380 0 : binding_detail::AutoSequence<JS::Value> arg0;
2381 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2382 0 : if (args.length() > 0) {
2383 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2384 0 : JS_ReportOutOfMemory(cx);
2385 0 : return false;
2386 : }
2387 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2388 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2389 0 : slot = args[variadicArg];
2390 : }
2391 : }
2392 0 : mozilla::dom::Console::Debug(global, Constify(arg0));
2393 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2394 0 : args.rval().setUndefined();
2395 0 : return true;
2396 : }
2397 :
2398 : static bool
2399 1 : error(JSContext* cx, unsigned argc, JS::Value* vp)
2400 : {
2401 1 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2402 2 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2403 :
2404 2 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2405 1 : if (global.Failed()) {
2406 0 : return false;
2407 : }
2408 :
2409 2 : binding_detail::AutoSequence<JS::Value> arg0;
2410 2 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2411 1 : if (args.length() > 0) {
2412 1 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2413 0 : JS_ReportOutOfMemory(cx);
2414 0 : return false;
2415 : }
2416 2 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2417 1 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2418 1 : slot = args[variadicArg];
2419 : }
2420 : }
2421 1 : mozilla::dom::Console::Error(global, Constify(arg0));
2422 1 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2423 1 : args.rval().setUndefined();
2424 1 : return true;
2425 : }
2426 :
2427 : static bool
2428 0 : info(JSContext* cx, unsigned argc, JS::Value* vp)
2429 : {
2430 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2431 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2432 :
2433 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2434 0 : if (global.Failed()) {
2435 0 : return false;
2436 : }
2437 :
2438 0 : binding_detail::AutoSequence<JS::Value> arg0;
2439 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2440 0 : if (args.length() > 0) {
2441 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2442 0 : JS_ReportOutOfMemory(cx);
2443 0 : return false;
2444 : }
2445 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2446 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2447 0 : slot = args[variadicArg];
2448 : }
2449 : }
2450 0 : mozilla::dom::Console::Info(global, Constify(arg0));
2451 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2452 0 : args.rval().setUndefined();
2453 0 : return true;
2454 : }
2455 :
2456 : static bool
2457 0 : log(JSContext* cx, unsigned argc, JS::Value* vp)
2458 : {
2459 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2460 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2461 :
2462 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2463 0 : if (global.Failed()) {
2464 0 : return false;
2465 : }
2466 :
2467 0 : binding_detail::AutoSequence<JS::Value> arg0;
2468 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2469 0 : if (args.length() > 0) {
2470 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2471 0 : JS_ReportOutOfMemory(cx);
2472 0 : return false;
2473 : }
2474 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2475 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2476 0 : slot = args[variadicArg];
2477 : }
2478 : }
2479 0 : mozilla::dom::Console::Log(global, Constify(arg0));
2480 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2481 0 : args.rval().setUndefined();
2482 0 : return true;
2483 : }
2484 :
2485 : static bool
2486 0 : table(JSContext* cx, unsigned argc, JS::Value* vp)
2487 : {
2488 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2489 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2490 :
2491 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2492 0 : if (global.Failed()) {
2493 0 : return false;
2494 : }
2495 :
2496 0 : binding_detail::AutoSequence<JS::Value> arg0;
2497 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2498 0 : if (args.length() > 0) {
2499 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2500 0 : JS_ReportOutOfMemory(cx);
2501 0 : return false;
2502 : }
2503 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2504 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2505 0 : slot = args[variadicArg];
2506 : }
2507 : }
2508 0 : mozilla::dom::Console::Table(global, Constify(arg0));
2509 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2510 0 : args.rval().setUndefined();
2511 0 : return true;
2512 : }
2513 :
2514 : static bool
2515 0 : trace(JSContext* cx, unsigned argc, JS::Value* vp)
2516 : {
2517 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2518 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2519 :
2520 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2521 0 : if (global.Failed()) {
2522 0 : return false;
2523 : }
2524 :
2525 0 : binding_detail::AutoSequence<JS::Value> arg0;
2526 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2527 0 : if (args.length() > 0) {
2528 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2529 0 : JS_ReportOutOfMemory(cx);
2530 0 : return false;
2531 : }
2532 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2533 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2534 0 : slot = args[variadicArg];
2535 : }
2536 : }
2537 0 : mozilla::dom::Console::Trace(global, Constify(arg0));
2538 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2539 0 : args.rval().setUndefined();
2540 0 : return true;
2541 : }
2542 :
2543 : static bool
2544 0 : warn(JSContext* cx, unsigned argc, JS::Value* vp)
2545 : {
2546 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2547 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2548 :
2549 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2550 0 : if (global.Failed()) {
2551 0 : return false;
2552 : }
2553 :
2554 0 : binding_detail::AutoSequence<JS::Value> arg0;
2555 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2556 0 : if (args.length() > 0) {
2557 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2558 0 : JS_ReportOutOfMemory(cx);
2559 0 : return false;
2560 : }
2561 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2562 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2563 0 : slot = args[variadicArg];
2564 : }
2565 : }
2566 0 : mozilla::dom::Console::Warn(global, Constify(arg0));
2567 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2568 0 : args.rval().setUndefined();
2569 0 : return true;
2570 : }
2571 :
2572 : static bool
2573 0 : dir(JSContext* cx, unsigned argc, JS::Value* vp)
2574 : {
2575 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2576 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2577 :
2578 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2579 0 : if (global.Failed()) {
2580 0 : return false;
2581 : }
2582 :
2583 0 : binding_detail::AutoSequence<JS::Value> arg0;
2584 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2585 0 : if (args.length() > 0) {
2586 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2587 0 : JS_ReportOutOfMemory(cx);
2588 0 : return false;
2589 : }
2590 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2591 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2592 0 : slot = args[variadicArg];
2593 : }
2594 : }
2595 0 : mozilla::dom::Console::Dir(global, Constify(arg0));
2596 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2597 0 : args.rval().setUndefined();
2598 0 : return true;
2599 : }
2600 :
2601 : static bool
2602 0 : dirxml(JSContext* cx, unsigned argc, JS::Value* vp)
2603 : {
2604 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2605 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2606 :
2607 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2608 0 : if (global.Failed()) {
2609 0 : return false;
2610 : }
2611 :
2612 0 : binding_detail::AutoSequence<JS::Value> arg0;
2613 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2614 0 : if (args.length() > 0) {
2615 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2616 0 : JS_ReportOutOfMemory(cx);
2617 0 : return false;
2618 : }
2619 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2620 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2621 0 : slot = args[variadicArg];
2622 : }
2623 : }
2624 0 : mozilla::dom::Console::Dirxml(global, Constify(arg0));
2625 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2626 0 : args.rval().setUndefined();
2627 0 : return true;
2628 : }
2629 :
2630 : static bool
2631 0 : group(JSContext* cx, unsigned argc, JS::Value* vp)
2632 : {
2633 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2634 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2635 :
2636 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2637 0 : if (global.Failed()) {
2638 0 : return false;
2639 : }
2640 :
2641 0 : binding_detail::AutoSequence<JS::Value> arg0;
2642 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2643 0 : if (args.length() > 0) {
2644 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2645 0 : JS_ReportOutOfMemory(cx);
2646 0 : return false;
2647 : }
2648 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2649 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2650 0 : slot = args[variadicArg];
2651 : }
2652 : }
2653 0 : mozilla::dom::Console::Group(global, Constify(arg0));
2654 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2655 0 : args.rval().setUndefined();
2656 0 : return true;
2657 : }
2658 :
2659 : static bool
2660 0 : groupCollapsed(JSContext* cx, unsigned argc, JS::Value* vp)
2661 : {
2662 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2663 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2664 :
2665 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2666 0 : if (global.Failed()) {
2667 0 : return false;
2668 : }
2669 :
2670 0 : binding_detail::AutoSequence<JS::Value> arg0;
2671 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2672 0 : if (args.length() > 0) {
2673 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2674 0 : JS_ReportOutOfMemory(cx);
2675 0 : return false;
2676 : }
2677 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2678 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2679 0 : slot = args[variadicArg];
2680 : }
2681 : }
2682 0 : mozilla::dom::Console::GroupCollapsed(global, Constify(arg0));
2683 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2684 0 : args.rval().setUndefined();
2685 0 : return true;
2686 : }
2687 :
2688 : static bool
2689 0 : groupEnd(JSContext* cx, unsigned argc, JS::Value* vp)
2690 : {
2691 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2692 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2693 :
2694 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2695 0 : if (global.Failed()) {
2696 0 : return false;
2697 : }
2698 :
2699 0 : mozilla::dom::Console::GroupEnd(global);
2700 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2701 0 : args.rval().setUndefined();
2702 0 : return true;
2703 : }
2704 :
2705 : static bool
2706 0 : time(JSContext* cx, unsigned argc, JS::Value* vp)
2707 : {
2708 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2709 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2710 :
2711 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2712 0 : if (global.Failed()) {
2713 0 : return false;
2714 : }
2715 :
2716 0 : binding_detail::FakeString arg0;
2717 0 : if (args.hasDefined(0)) {
2718 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
2719 0 : return false;
2720 : }
2721 : } else {
2722 : static const char16_t data[] = { 'd', 'e', 'f', 'a', 'u', 'l', 't', 0 };
2723 0 : arg0.Rebind(data, ArrayLength(data) - 1);
2724 : }
2725 0 : mozilla::dom::Console::Time(global, NonNullHelper(Constify(arg0)));
2726 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2727 0 : args.rval().setUndefined();
2728 0 : return true;
2729 : }
2730 :
2731 : static bool
2732 0 : timeEnd(JSContext* cx, unsigned argc, JS::Value* vp)
2733 : {
2734 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2735 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2736 :
2737 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2738 0 : if (global.Failed()) {
2739 0 : return false;
2740 : }
2741 :
2742 0 : binding_detail::FakeString arg0;
2743 0 : if (args.hasDefined(0)) {
2744 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
2745 0 : return false;
2746 : }
2747 : } else {
2748 : static const char16_t data[] = { 'd', 'e', 'f', 'a', 'u', 'l', 't', 0 };
2749 0 : arg0.Rebind(data, ArrayLength(data) - 1);
2750 : }
2751 0 : mozilla::dom::Console::TimeEnd(global, NonNullHelper(Constify(arg0)));
2752 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2753 0 : args.rval().setUndefined();
2754 0 : return true;
2755 : }
2756 :
2757 : static bool
2758 0 : exception(JSContext* cx, unsigned argc, JS::Value* vp)
2759 : {
2760 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2761 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2762 :
2763 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2764 0 : if (global.Failed()) {
2765 0 : return false;
2766 : }
2767 :
2768 0 : binding_detail::AutoSequence<JS::Value> arg0;
2769 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2770 0 : if (args.length() > 0) {
2771 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2772 0 : JS_ReportOutOfMemory(cx);
2773 0 : return false;
2774 : }
2775 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2776 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2777 0 : slot = args[variadicArg];
2778 : }
2779 : }
2780 0 : mozilla::dom::Console::Exception(global, Constify(arg0));
2781 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2782 0 : args.rval().setUndefined();
2783 0 : return true;
2784 : }
2785 :
2786 : static bool
2787 0 : timeStamp(JSContext* cx, unsigned argc, JS::Value* vp)
2788 : {
2789 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2790 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2791 :
2792 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2793 0 : if (global.Failed()) {
2794 0 : return false;
2795 : }
2796 :
2797 0 : JS::Rooted<JS::Value> arg0(cx);
2798 0 : if (args.hasDefined(0)) {
2799 0 : arg0 = args[0];
2800 : } else {
2801 0 : arg0 = JS::UndefinedValue();
2802 : }
2803 0 : mozilla::dom::Console::TimeStamp(global, arg0);
2804 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2805 0 : args.rval().setUndefined();
2806 0 : return true;
2807 : }
2808 :
2809 : static bool
2810 0 : profile(JSContext* cx, unsigned argc, JS::Value* vp)
2811 : {
2812 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2813 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2814 :
2815 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2816 0 : if (global.Failed()) {
2817 0 : return false;
2818 : }
2819 :
2820 0 : binding_detail::AutoSequence<JS::Value> arg0;
2821 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2822 0 : if (args.length() > 0) {
2823 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2824 0 : JS_ReportOutOfMemory(cx);
2825 0 : return false;
2826 : }
2827 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2828 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2829 0 : slot = args[variadicArg];
2830 : }
2831 : }
2832 0 : mozilla::dom::Console::Profile(global, Constify(arg0));
2833 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2834 0 : args.rval().setUndefined();
2835 0 : return true;
2836 : }
2837 :
2838 : static bool
2839 0 : profileEnd(JSContext* cx, unsigned argc, JS::Value* vp)
2840 : {
2841 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2842 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
2843 :
2844 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
2845 0 : if (global.Failed()) {
2846 0 : return false;
2847 : }
2848 :
2849 0 : binding_detail::AutoSequence<JS::Value> arg0;
2850 0 : SequenceRooter<JS::Value> arg0_holder(cx, &arg0);
2851 0 : if (args.length() > 0) {
2852 0 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
2853 0 : JS_ReportOutOfMemory(cx);
2854 0 : return false;
2855 : }
2856 0 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
2857 0 : JS::Value& slot = *arg0.AppendElement(mozilla::fallible);
2858 0 : slot = args[variadicArg];
2859 : }
2860 : }
2861 0 : mozilla::dom::Console::ProfileEnd(global, Constify(arg0));
2862 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
2863 0 : args.rval().setUndefined();
2864 0 : return true;
2865 : }
2866 :
2867 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
2868 : #if defined(__clang__)
2869 : #pragma clang diagnostic push
2870 : #pragma clang diagnostic ignored "-Wmissing-braces"
2871 : #endif
2872 : static const JSFunctionSpec sStaticMethods_specs[] = {
2873 : JS_FNSPEC("assert", _assert_, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2874 : JS_FNSPEC("clear", clear, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2875 : JS_FNSPEC("count", count, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2876 : JS_FNSPEC("debug", debug, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2877 : JS_FNSPEC("error", error, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2878 : JS_FNSPEC("info", info, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2879 : JS_FNSPEC("log", log, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2880 : JS_FNSPEC("table", table, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2881 : JS_FNSPEC("trace", trace, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2882 : JS_FNSPEC("warn", warn, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2883 : JS_FNSPEC("dir", dir, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2884 : JS_FNSPEC("dirxml", dirxml, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2885 : JS_FNSPEC("group", group, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2886 : JS_FNSPEC("groupCollapsed", groupCollapsed, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2887 : JS_FNSPEC("groupEnd", groupEnd, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2888 : JS_FNSPEC("time", time, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2889 : JS_FNSPEC("timeEnd", timeEnd, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2890 : JS_FNSPEC("exception", exception, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2891 : JS_FNSPEC("timeStamp", timeStamp, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2892 : JS_FNSPEC("profile", profile, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2893 : JS_FNSPEC("profileEnd", profileEnd, nullptr, 0, JSPROP_ENUMERATE, nullptr),
2894 : JS_FS_END
2895 : };
2896 : #if defined(__clang__)
2897 : #pragma clang diagnostic pop
2898 : #endif
2899 :
2900 :
2901 : // Can't be const because the pref-enabled boolean needs to be writable
2902 : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
2903 : { nullptr, &sStaticMethods_specs[0] },
2904 : { nullptr, nullptr }
2905 : };
2906 :
2907 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2908 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2909 : static_assert(21 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2910 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2911 :
2912 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
2913 : #if defined(__clang__)
2914 : #pragma clang diagnostic push
2915 : #pragma clang diagnostic ignored "-Wmissing-braces"
2916 : #endif
2917 3 : static const ConstantSpec sChromeConstants_specs[] = {
2918 : { "IS_NATIVE_CONSOLE", JS::BooleanValue(true) },
2919 : { 0, JS::UndefinedValue() }
2920 3 : };
2921 : #if defined(__clang__)
2922 : #pragma clang diagnostic pop
2923 : #endif
2924 :
2925 :
2926 : // Can't be const because the pref-enabled boolean needs to be writable
2927 : static Prefable<const ConstantSpec> sChromeConstants[] = {
2928 : { nullptr, &sChromeConstants_specs[0] },
2929 : { nullptr, nullptr }
2930 : };
2931 :
2932 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
2933 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
2934 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
2935 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
2936 :
2937 :
2938 : static uint16_t sNativeProperties_sortedPropertyIndices[21];
2939 : static PropertyInfo sNativeProperties_propertyInfos[21];
2940 :
2941 : static const NativePropertiesN<1> sNativeProperties = {
2942 : true, 0 /* sStaticMethods */,
2943 : false, 0,
2944 : false, 0,
2945 : false, 0,
2946 : false, 0,
2947 : false, 0,
2948 : false, 0,
2949 : -1,
2950 : 21,
2951 : sNativeProperties_sortedPropertyIndices,
2952 : {
2953 : { sStaticMethods, &sNativeProperties_propertyInfos[0] }
2954 : }
2955 : };
2956 : static_assert(21 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
2957 : "We have a property info count that is oversized");
2958 :
2959 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
2960 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
2961 :
2962 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
2963 : false, 0,
2964 : false, 0,
2965 : false, 0,
2966 : false, 0,
2967 : false, 0,
2968 : false, 0,
2969 : true, 0 /* sChromeConstants */,
2970 : -1,
2971 : 1,
2972 : sChromeOnlyNativeProperties_sortedPropertyIndices,
2973 : {
2974 : { sChromeConstants, &sChromeOnlyNativeProperties_propertyInfos[0] }
2975 : }
2976 : };
2977 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
2978 : "We have a property info count that is oversized");
2979 :
2980 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
2981 : {
2982 : "Console",
2983 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
2984 : JS_NULL_CLASS_OPS,
2985 : JS_NULL_CLASS_SPEC,
2986 : JS_NULL_CLASS_EXT,
2987 : JS_NULL_OBJECT_OPS
2988 : },
2989 : eInterface,
2990 : false,
2991 : prototypes::id::_ID_Count,
2992 : 0,
2993 : sNativePropertyHooks,
2994 : "[object Console]",
2995 : JS::GetRealmObjectPrototype
2996 : };
2997 :
2998 : JSObject*
2999 1 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
3000 : {
3001 1 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
3002 : }
3003 :
3004 : const NativePropertyHooks sNativePropertyHooks[] = { {
3005 : nullptr,
3006 : nullptr,
3007 : nullptr,
3008 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
3009 : prototypes::id::_ID_Count,
3010 : constructors::id::console,
3011 : nullptr,
3012 : &DefaultXrayExpandoObjectClass
3013 : } };
3014 :
3015 : void
3016 2 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
3017 : {
3018 4 : JS::Rooted<JSObject*> constructorProto(aCx, binding_detail::GetHackedNamespaceProtoObject(aCx));
3019 2 : if (!constructorProto) {
3020 0 : return;
3021 : }
3022 :
3023 : static bool sIdsInited = false;
3024 2 : if (!sIdsInited && NS_IsMainThread()) {
3025 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
3026 0 : return;
3027 : }
3028 1 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
3029 0 : return;
3030 : }
3031 1 : sIdsInited = true;
3032 : }
3033 :
3034 2 : JS::Heap<JSObject*>* protoCache = nullptr;
3035 2 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::console);
3036 6 : dom::CreateInterfaceObjects(aCx, aGlobal, nullptr,
3037 : nullptr, protoCache,
3038 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
3039 : interfaceCache,
3040 : sNativeProperties.Upcast(),
3041 2 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
3042 : "console", aDefineOnGlobal,
3043 : nullptr,
3044 2 : false);
3045 : }
3046 :
3047 : JS::Handle<JSObject*>
3048 2 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
3049 : {
3050 : /* Get the interface object for this class. This will create the object as
3051 : needed. */
3052 :
3053 : /* Make sure our global is sane. Hopefully we can remove this sometime */
3054 2 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
3055 2 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
3056 0 : return nullptr;
3057 : }
3058 :
3059 : /* Check to see whether the interface objects are already installed */
3060 2 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
3061 2 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::console)) {
3062 4 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
3063 2 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
3064 : }
3065 :
3066 : /*
3067 : * The object might _still_ be null, but that's OK.
3068 : *
3069 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
3070 : * traced by TraceProtoAndIfaceCache() and its contents are never
3071 : * changed after they have been set.
3072 : *
3073 : * Calling address() avoids the read read barrier that does gray
3074 : * unmarking, but it's not possible for the object to be gray here.
3075 : */
3076 :
3077 2 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::console);
3078 2 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
3079 2 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
3080 : }
3081 :
3082 : JSObject*
3083 1 : GetConstructorObject(JSContext* aCx)
3084 : {
3085 1 : return GetConstructorObjectHandle(aCx);
3086 : }
3087 :
3088 : } // namespace consoleBinding
3089 :
3090 :
3091 :
3092 : } // namespace dom
3093 : } // namespace mozilla
|