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
;
25 using js::ReportErrorVA
;
27 JS_PUBLIC_API
bool JS::WarnASCII(JSContext
* cx
, const char* format
, ...) {
33 ok
= ReportErrorVA(cx
, IsWarning::Yes
, format
, ArgumentsAreASCII
, ap
);
38 JS_PUBLIC_API
bool JS::WarnLatin1(JSContext
* cx
, const char* format
, ...) {
44 ok
= ReportErrorVA(cx
, IsWarning::Yes
, format
, ArgumentsAreLatin1
, ap
);
49 JS_PUBLIC_API
bool JS::WarnUTF8(JSContext
* cx
, const char* format
, ...) {
55 ok
= ReportErrorVA(cx
, IsWarning::Yes
, format
, ArgumentsAreUTF8
, ap
);
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
;
71 bool js::WarnNumberASCII(JSContext
* cx
, const unsigned errorNumber
, ...) {
73 va_start(ap
, errorNumber
);
74 bool ok
= ReportErrorNumberVA(cx
, IsWarning::Yes
, GetErrorMessage
, nullptr,
75 errorNumber
, ArgumentsAreASCII
, ap
);
80 bool js::WarnNumberLatin1(JSContext
* cx
, const unsigned errorNumber
, ...) {
82 va_start(ap
, errorNumber
);
83 bool ok
= ReportErrorNumberVA(cx
, IsWarning::Yes
, GetErrorMessage
, nullptr,
84 errorNumber
, ArgumentsAreLatin1
, ap
);
89 bool js::WarnNumberUTF8(JSContext
* cx
, const unsigned errorNumber
, ...) {
91 va_start(ap
, errorNumber
);
92 bool ok
= ReportErrorNumberVA(cx
, IsWarning::Yes
, GetErrorMessage
, nullptr,
93 errorNumber
, ArgumentsAreUTF8
, ap
);
98 bool js::WarnNumberUC(JSContext
* cx
, const unsigned errorNumber
, ...) {
100 va_start(ap
, errorNumber
);
101 bool ok
= ReportErrorNumberVA(cx
, IsWarning::Yes
, GetErrorMessage
, nullptr,
102 errorNumber
, ArgumentsAreUnicode
, ap
);