Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / vm / Warnings.cpp
blobd73e4f1116eb31940d5c9eee5f5057902d6de5ae
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "js/Warnings.h"
8 #include "vm/Warnings.h"
10 #include <stdarg.h> // va_{list,start,end}
12 #include "jstypes.h" // JS_PUBLIC_API
14 #include "js/Context.h" // js::AssertHeapIsIdle
15 #include "js/friend/ErrorMessages.h" // js::GetErrorMessage
16 #include "vm/ErrorReporting.h" // IsWarning
17 #include "vm/JSContext.h" // js::ArgumentsAre{ASCII,Latin1,UTF8}, js::ReportError{Number}VA
19 using js::ArgumentsAreASCII;
20 using js::ArgumentsAreLatin1;
21 using js::ArgumentsAreUTF8;
22 using js::AssertHeapIsIdle;
23 using js::GetErrorMessage;
24 using js::IsWarning;
25 using js::ReportErrorVA;
27 JS_PUBLIC_API bool JS::WarnASCII(JSContext* cx, const char* format, ...) {
28 va_list ap;
29 bool ok;
31 AssertHeapIsIdle();
32 va_start(ap, format);
33 ok = ReportErrorVA(cx, IsWarning::Yes, format, ArgumentsAreASCII, ap);
34 va_end(ap);
35 return ok;
38 JS_PUBLIC_API bool JS::WarnLatin1(JSContext* cx, const char* format, ...) {
39 va_list ap;
40 bool ok;
42 AssertHeapIsIdle();
43 va_start(ap, format);
44 ok = ReportErrorVA(cx, IsWarning::Yes, format, ArgumentsAreLatin1, ap);
45 va_end(ap);
46 return ok;
49 JS_PUBLIC_API bool JS::WarnUTF8(JSContext* cx, const char* format, ...) {
50 va_list ap;
51 bool ok;
53 AssertHeapIsIdle();
54 va_start(ap, format);
55 ok = ReportErrorVA(cx, IsWarning::Yes, format, ArgumentsAreUTF8, ap);
56 va_end(ap);
57 return ok;
60 JS_PUBLIC_API JS::WarningReporter JS::GetWarningReporter(JSContext* cx) {
61 return cx->runtime()->warningReporter;
64 JS_PUBLIC_API JS::WarningReporter JS::SetWarningReporter(
65 JSContext* cx, WarningReporter reporter) {
66 WarningReporter older = cx->runtime()->warningReporter;
67 cx->runtime()->warningReporter = reporter;
68 return older;
71 bool js::WarnNumberASCII(JSContext* cx, const unsigned errorNumber, ...) {
72 va_list ap;
73 va_start(ap, errorNumber);
74 bool ok = ReportErrorNumberVA(cx, IsWarning::Yes, GetErrorMessage, nullptr,
75 errorNumber, ArgumentsAreASCII, ap);
76 va_end(ap);
77 return ok;
80 bool js::WarnNumberLatin1(JSContext* cx, const unsigned errorNumber, ...) {
81 va_list ap;
82 va_start(ap, errorNumber);
83 bool ok = ReportErrorNumberVA(cx, IsWarning::Yes, GetErrorMessage, nullptr,
84 errorNumber, ArgumentsAreLatin1, ap);
85 va_end(ap);
86 return ok;
89 bool js::WarnNumberUTF8(JSContext* cx, const unsigned errorNumber, ...) {
90 va_list ap;
91 va_start(ap, errorNumber);
92 bool ok = ReportErrorNumberVA(cx, IsWarning::Yes, GetErrorMessage, nullptr,
93 errorNumber, ArgumentsAreUTF8, ap);
94 va_end(ap);
95 return ok;
98 bool js::WarnNumberUC(JSContext* cx, const unsigned errorNumber, ...) {
99 va_list ap;
100 va_start(ap, errorNumber);
101 bool ok = ReportErrorNumberVA(cx, IsWarning::Yes, GetErrorMessage, nullptr,
102 errorNumber, ArgumentsAreUnicode, ap);
103 va_end(ap);
104 return ok;