зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1542120 - Add js/public/Warnings.h for warning-related JSAPI. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D26273 --HG-- rename : js/src/jsapi.h => js/public/Warnings.h extra : moz-landing-system : lando
This commit is contained in:
Родитель
512a56bf3c
Коммит
5327fe7f3e
|
@ -73,6 +73,7 @@
|
||||||
// Helper Classes
|
// Helper Classes
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarnASCII
|
||||||
#include "js/Wrapper.h"
|
#include "js/Wrapper.h"
|
||||||
#include "nsCharSeparatedTokenizer.h"
|
#include "nsCharSeparatedTokenizer.h"
|
||||||
#include "nsReadableUtils.h"
|
#include "nsReadableUtils.h"
|
||||||
|
@ -4549,7 +4550,7 @@ nsGlobalWindowInner::ShowSlowScriptDialog(JSContext* aCx,
|
||||||
// (since that spins the event loop). In that (rare) case, we just kill the
|
// (since that spins the event loop). In that (rare) case, we just kill the
|
||||||
// script and report a warning.
|
// script and report a warning.
|
||||||
if (!nsContentUtils::IsSafeToRunScript()) {
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
||||||
JS_ReportWarningASCII(aCx, "A long running script was terminated");
|
JS::WarnASCII(aCx, "A long running script was terminated");
|
||||||
return KillSlowScript;
|
return KillSlowScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
#include "js/Conversions.h"
|
#include "js/Conversions.h"
|
||||||
#include "js/HeapAPI.h"
|
#include "js/HeapAPI.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarnASCII
|
||||||
|
|
||||||
#include "mozilla/Alignment.h"
|
#include "mozilla/Alignment.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
|
@ -2023,9 +2024,9 @@ already_AddRefed<CanvasPattern> CanvasRenderingContext2D::CreatePattern(
|
||||||
if (!srcSurf) {
|
if (!srcSurf) {
|
||||||
JSContext* context = nsContentUtils::GetCurrentJSContext();
|
JSContext* context = nsContentUtils::GetCurrentJSContext();
|
||||||
if (context) {
|
if (context) {
|
||||||
JS_ReportWarningASCII(context,
|
JS::WarnASCII(context,
|
||||||
"CanvasRenderingContext2D.createPattern()"
|
"CanvasRenderingContext2D.createPattern() failed to "
|
||||||
" failed to snapshot source canvas.");
|
"snapshot source canvas.");
|
||||||
}
|
}
|
||||||
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -2070,9 +2071,9 @@ already_AddRefed<CanvasPattern> CanvasRenderingContext2D::CreatePattern(
|
||||||
if (!srcSurf) {
|
if (!srcSurf) {
|
||||||
JSContext* context = nsContentUtils::GetCurrentJSContext();
|
JSContext* context = nsContentUtils::GetCurrentJSContext();
|
||||||
if (context) {
|
if (context) {
|
||||||
JS_ReportWarningASCII(context,
|
JS::WarnASCII(context,
|
||||||
"CanvasRenderingContext2D.createPattern()"
|
"CanvasRenderingContext2D.createPattern() failed to "
|
||||||
" failed to prepare source ImageBitmap.");
|
"prepare source ImageBitmap.");
|
||||||
}
|
}
|
||||||
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "GLContext.h"
|
#include "GLContext.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarnASCII
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
#include "mozilla/gfx/Logging.h"
|
#include "mozilla/gfx/Logging.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
|
@ -68,7 +69,7 @@ void WebGLContext::GenerateWarning(const char* fmt, va_list ap) const {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
VsprintfLiteral(buf, fmt, ap);
|
VsprintfLiteral(buf, fmt, ap);
|
||||||
|
|
||||||
// no need to print to stderr, as JS_ReportWarning takes care of this for us.
|
// JS::WarnASCII will print to stderr for us.
|
||||||
|
|
||||||
if (!mCanvasElement) {
|
if (!mCanvasElement) {
|
||||||
return;
|
return;
|
||||||
|
@ -81,13 +82,12 @@ void WebGLContext::GenerateWarning(const char* fmt, va_list ap) const {
|
||||||
|
|
||||||
JSContext* cx = api.cx();
|
JSContext* cx = api.cx();
|
||||||
const auto funcName = FuncName();
|
const auto funcName = FuncName();
|
||||||
JS_ReportWarningASCII(cx, "WebGL warning: %s: %s", funcName, buf);
|
JS::WarnASCII(cx, "WebGL warning: %s: %s", funcName, buf);
|
||||||
if (!ShouldGenerateWarnings()) {
|
if (!ShouldGenerateWarnings()) {
|
||||||
JS_ReportWarningASCII(cx,
|
JS::WarnASCII(cx,
|
||||||
"WebGL: No further warnings will be reported for"
|
"WebGL: No further warnings will be reported for this WebGL "
|
||||||
" this WebGL context."
|
"context. (already reported %d warnings)",
|
||||||
" (already reported %d warnings)",
|
mAlreadyGeneratedWarnings);
|
||||||
mAlreadyGeneratedWarnings);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,15 +119,14 @@ void WebGLContext::GeneratePerfWarning(const char* fmt, ...) const {
|
||||||
////
|
////
|
||||||
|
|
||||||
const auto funcName = FuncName();
|
const auto funcName = FuncName();
|
||||||
JS_ReportWarningASCII(cx, "WebGL perf warning: %s: %s", funcName, buf);
|
JS::WarnASCII(cx, "WebGL perf warning: %s: %s", funcName, buf);
|
||||||
mNumPerfWarnings++;
|
mNumPerfWarnings++;
|
||||||
|
|
||||||
if (!ShouldGeneratePerfWarnings()) {
|
if (!ShouldGeneratePerfWarnings()) {
|
||||||
JS_ReportWarningASCII(
|
JS::WarnASCII(cx,
|
||||||
cx,
|
"WebGL: After reporting %u, no further perf warnings will be "
|
||||||
"WebGL: After reporting %u, no further perf warnings will"
|
"reported for this WebGL context.",
|
||||||
" be reported for this WebGL context.",
|
uint32_t(mNumPerfWarnings));
|
||||||
uint32_t(mNumPerfWarnings));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsIScriptError.h"
|
#include "nsIScriptError.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarnASCII
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
@ -55,9 +56,9 @@ void MediaError::GetMessage(nsAString& aResult) const {
|
||||||
if (api.Init(ownerDoc->GetScopeObject())) {
|
if (api.Init(ownerDoc->GetScopeObject())) {
|
||||||
// We prefer this API because it can also print to our debug log and
|
// We prefer this API because it can also print to our debug log and
|
||||||
// try server's log viewer.
|
// try server's log viewer.
|
||||||
JS_ReportWarningASCII(api.cx(), "%s", message.get());
|
JS::WarnASCII(api.cx(), "%s", message.get());
|
||||||
} else {
|
} else {
|
||||||
// If failed to use JS_ReportWarningASCII, fall back to
|
// If failed to use JS::WarnASCII, fall back to
|
||||||
// nsContentUtils::ReportToConsoleNonLocalized, which can only print to
|
// nsContentUtils::ReportToConsoleNonLocalized, which can only print to
|
||||||
// JavaScript console.
|
// JavaScript console.
|
||||||
nsContentUtils::ReportToConsoleNonLocalized(
|
nsContentUtils::ReportToConsoleNonLocalized(
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "js/StableStringChars.h"
|
#include "js/StableStringChars.h"
|
||||||
|
#include "js/Warnings.h" // JS::{Get,}WarningReporter
|
||||||
#include "xpcpublic.h"
|
#include "xpcpublic.h"
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
#include "nsIDocShell.h"
|
#include "nsIDocShell.h"
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "js/Debug.h"
|
#include "js/Debug.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarningReporter
|
||||||
|
|
||||||
class nsPIDOMWindowInner;
|
class nsPIDOMWindowInner;
|
||||||
class nsGlobalWindowInner;
|
class nsGlobalWindowInner;
|
||||||
|
|
|
@ -261,7 +261,7 @@ class JSErrorReport : public JSErrorBase {
|
||||||
* JSErrorReport flag values. These may be freely composed.
|
* JSErrorReport flag values. These may be freely composed.
|
||||||
*/
|
*/
|
||||||
#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */
|
#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */
|
||||||
#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
|
#define JSREPORT_WARNING 0x1 /* reported via JS::Warn* */
|
||||||
#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */
|
#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */
|
||||||
#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */
|
#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functionality for issuing and handling warnings.
|
||||||
|
*
|
||||||
|
* Warnings are situations that aren't inherently full-blown errors (and perhaps
|
||||||
|
* for spec compliance *can't* be), but that may represent dubious programming
|
||||||
|
* practice that embeddings may wish to know about. (That said, SpiderMonkey
|
||||||
|
* exposes various options that, when active, automatically upgrade warnings to
|
||||||
|
* errors. See |JS::TransitiveCompileOptions::werrorOptions| and
|
||||||
|
* |JS::ContextOptions::werror()|.)
|
||||||
|
*
|
||||||
|
* SpiderMonkey recognizes an unspecified set of syntactic patterns and runtime
|
||||||
|
* behaviors as triggering a warning. Embeddings may also recognize and report
|
||||||
|
* additional warnings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef js_Warnings_h
|
||||||
|
#define js_Warnings_h
|
||||||
|
|
||||||
|
#include "mozilla/Assertions.h" // MOZ_ASSERT
|
||||||
|
#include "mozilla/Attributes.h" // MOZ_FORMAT_PRINTF, MOZ_RAII
|
||||||
|
|
||||||
|
#include "jstypes.h" // JS_PUBLIC_API
|
||||||
|
|
||||||
|
struct JSContext;
|
||||||
|
class JSErrorReport;
|
||||||
|
|
||||||
|
namespace JS {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a warning represented by the sprintf-like conversion of ASCII format
|
||||||
|
* filled from trailing ASCII arguments.
|
||||||
|
*
|
||||||
|
* Return true iff the warning was successfully reported without reporting an
|
||||||
|
* error (or being upgraded into one).
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API bool WarnASCII(JSContext* cx, const char* format, ...)
|
||||||
|
MOZ_FORMAT_PRINTF(2, 3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a warning represented by the sprintf-like conversion of Latin-1 format
|
||||||
|
* filled from trailing Latin-1 arguments.
|
||||||
|
*
|
||||||
|
* Return true iff the warning was successfully reported without reporting an
|
||||||
|
* error (or being upgraded into one).
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API bool WarnLatin1(JSContext* cx, const char* format, ...)
|
||||||
|
MOZ_FORMAT_PRINTF(2, 3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a warning represented by the sprintf-like conversion of UTF-8 format
|
||||||
|
* filled from trailing UTF-8 arguments.
|
||||||
|
*
|
||||||
|
* Return true iff the warning was successfully reported without reporting an
|
||||||
|
* error (or being upgraded into one).
|
||||||
|
*/
|
||||||
|
extern JS_PUBLIC_API bool WarnUTF8(JSContext* cx, const char* format, ...)
|
||||||
|
MOZ_FORMAT_PRINTF(2, 3);
|
||||||
|
|
||||||
|
using WarningReporter = void (*)(JSContext* cx, JSErrorReport* report);
|
||||||
|
|
||||||
|
extern JS_PUBLIC_API WarningReporter GetWarningReporter(JSContext* cx);
|
||||||
|
|
||||||
|
extern JS_PUBLIC_API WarningReporter
|
||||||
|
SetWarningReporter(JSContext* cx, WarningReporter reporter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple RAII class that clears the registered warning reporter on
|
||||||
|
* construction and restores it on destruction.
|
||||||
|
*
|
||||||
|
* A fresh warning reporter *may* be set while an instance of this class is
|
||||||
|
* live, but it must be unset in LIFO fashion by the time that instance is
|
||||||
|
* destroyed.
|
||||||
|
*/
|
||||||
|
class MOZ_RAII JS_PUBLIC_API AutoSuppressWarningReporter {
|
||||||
|
JSContext* context_;
|
||||||
|
WarningReporter prevReporter_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AutoSuppressWarningReporter(JSContext* cx) : context_(cx) {
|
||||||
|
prevReporter_ = SetWarningReporter(context_, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
~AutoSuppressWarningReporter() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
WarningReporter reporter =
|
||||||
|
#endif
|
||||||
|
SetWarningReporter(context_, prevReporter_);
|
||||||
|
MOZ_ASSERT(reporter == nullptr, "Unexpected WarningReporter active");
|
||||||
|
SetWarningReporter(context_, prevReporter_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace JS
|
||||||
|
|
||||||
|
#endif // js_Warnings_h
|
|
@ -25,6 +25,7 @@ typedef uint32_t HashNumber;
|
||||||
#include "js/PropertySpec.h"
|
#include "js/PropertySpec.h"
|
||||||
#include "js/SourceText.h"
|
#include "js/SourceText.h"
|
||||||
#include "js/StructuredClone.h"
|
#include "js/StructuredClone.h"
|
||||||
|
#include "js/Warnings.h"
|
||||||
|
|
||||||
// Replacements for types that are too difficult for rust-bindgen.
|
// Replacements for types that are too difficult for rust-bindgen.
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
#include "js/Initialization.h"
|
#include "js/Initialization.h"
|
||||||
|
#include "js/Warnings.h" // JS::SetWarningReporter
|
||||||
|
|
||||||
using namespace JS;
|
using namespace JS;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "js/Equality.h" // JS::SameValue
|
#include "js/Equality.h" // JS::SameValue
|
||||||
#include "js/RegExpFlags.h" // JS::RegExpFlags
|
#include "js/RegExpFlags.h" // JS::RegExpFlags
|
||||||
#include "js/Vector.h"
|
#include "js/Vector.h"
|
||||||
|
#include "js/Warnings.h" // JS::SetWarningReporter
|
||||||
#include "vm/JSContext.h"
|
#include "vm/JSContext.h"
|
||||||
|
|
||||||
/* Note: Aborts on OOM. */
|
/* Note: Aborts on OOM. */
|
||||||
|
|
|
@ -4860,42 +4860,6 @@ JS_PUBLIC_API void JS_ReportErrorNumberUCArray(JSContext* cx,
|
||||||
errorNumber, args);
|
errorNumber, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API bool JS_ReportWarningASCII(JSContext* cx, const char* format,
|
|
||||||
...) {
|
|
||||||
va_list ap;
|
|
||||||
bool ok;
|
|
||||||
|
|
||||||
AssertHeapIsIdle();
|
|
||||||
va_start(ap, format);
|
|
||||||
ok = ReportErrorVA(cx, JSREPORT_WARNING, format, ArgumentsAreASCII, ap);
|
|
||||||
va_end(ap);
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_PUBLIC_API bool JS_ReportWarningLatin1(JSContext* cx, const char* format,
|
|
||||||
...) {
|
|
||||||
va_list ap;
|
|
||||||
bool ok;
|
|
||||||
|
|
||||||
AssertHeapIsIdle();
|
|
||||||
va_start(ap, format);
|
|
||||||
ok = ReportErrorVA(cx, JSREPORT_WARNING, format, ArgumentsAreLatin1, ap);
|
|
||||||
va_end(ap);
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_PUBLIC_API bool JS_ReportWarningUTF8(JSContext* cx, const char* format,
|
|
||||||
...) {
|
|
||||||
va_list ap;
|
|
||||||
bool ok;
|
|
||||||
|
|
||||||
AssertHeapIsIdle();
|
|
||||||
va_start(ap, format);
|
|
||||||
ok = ReportErrorVA(cx, JSREPORT_WARNING, format, ArgumentsAreUTF8, ap);
|
|
||||||
va_end(ap);
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_PUBLIC_API bool JS_ReportErrorFlagsAndNumberASCII(
|
JS_PUBLIC_API bool JS_ReportErrorFlagsAndNumberASCII(
|
||||||
JSContext* cx, unsigned flags, JSErrorCallback errorCallback, void* userRef,
|
JSContext* cx, unsigned flags, JSErrorCallback errorCallback, void* userRef,
|
||||||
const unsigned errorNumber, ...) {
|
const unsigned errorNumber, ...) {
|
||||||
|
@ -4962,17 +4926,6 @@ JS_PUBLIC_API void JS_ReportAllocationOverflow(JSContext* cx) {
|
||||||
ReportAllocationOverflow(cx);
|
ReportAllocationOverflow(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API JS::WarningReporter JS::GetWarningReporter(JSContext* cx) {
|
|
||||||
return cx->runtime()->warningReporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_PUBLIC_API JS::WarningReporter JS::SetWarningReporter(
|
|
||||||
JSContext* cx, JS::WarningReporter reporter) {
|
|
||||||
WarningReporter older = cx->runtime()->warningReporter;
|
|
||||||
cx->runtime()->warningReporter = reporter;
|
|
||||||
return older;
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
JS_PUBLIC_API bool JS_SetDefaultLocale(JSRuntime* rt, const char* locale) {
|
JS_PUBLIC_API bool JS_SetDefaultLocale(JSRuntime* rt, const char* locale) {
|
||||||
|
|
|
@ -2652,24 +2652,6 @@ extern JS_PUBLIC_API void JS_ReportErrorNumberUCArray(
|
||||||
JSContext* cx, JSErrorCallback errorCallback, void* userRef,
|
JSContext* cx, JSErrorCallback errorCallback, void* userRef,
|
||||||
const unsigned errorNumber, const char16_t** args);
|
const unsigned errorNumber, const char16_t** args);
|
||||||
|
|
||||||
/**
|
|
||||||
* As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
|
|
||||||
* Return true if there was no error trying to issue the warning, and if the
|
|
||||||
* warning was not converted into an error due to the JSOPTION_WERROR option
|
|
||||||
* being set, false otherwise.
|
|
||||||
*/
|
|
||||||
extern JS_PUBLIC_API bool JS_ReportWarningASCII(JSContext* cx,
|
|
||||||
const char* format, ...)
|
|
||||||
MOZ_FORMAT_PRINTF(2, 3);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API bool JS_ReportWarningLatin1(JSContext* cx,
|
|
||||||
const char* format, ...)
|
|
||||||
MOZ_FORMAT_PRINTF(2, 3);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API bool JS_ReportWarningUTF8(JSContext* cx,
|
|
||||||
const char* format, ...)
|
|
||||||
MOZ_FORMAT_PRINTF(2, 3);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API bool JS_ReportErrorFlagsAndNumberASCII(
|
extern JS_PUBLIC_API bool JS_ReportErrorFlagsAndNumberASCII(
|
||||||
JSContext* cx, unsigned flags, JSErrorCallback errorCallback, void* userRef,
|
JSContext* cx, unsigned flags, JSErrorCallback errorCallback, void* userRef,
|
||||||
const unsigned errorNumber, ...);
|
const unsigned errorNumber, ...);
|
||||||
|
@ -2698,33 +2680,6 @@ extern JS_PUBLIC_API void JS_ReportAllocationOverflow(JSContext* cx);
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
using WarningReporter = void (*)(JSContext* cx, JSErrorReport* report);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API WarningReporter
|
|
||||||
SetWarningReporter(JSContext* cx, WarningReporter reporter);
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API WarningReporter GetWarningReporter(JSContext* cx);
|
|
||||||
|
|
||||||
// Suppress the Warning Reporter callback temporarily.
|
|
||||||
class MOZ_RAII JS_PUBLIC_API AutoSuppressWarningReporter {
|
|
||||||
JSContext* context_;
|
|
||||||
WarningReporter prevReporter_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit AutoSuppressWarningReporter(JSContext* cx) : context_(cx) {
|
|
||||||
prevReporter_ = SetWarningReporter(context_, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
~AutoSuppressWarningReporter() {
|
|
||||||
#ifdef DEBUG
|
|
||||||
WarningReporter reporter =
|
|
||||||
#endif
|
|
||||||
SetWarningReporter(context_, prevReporter_);
|
|
||||||
MOZ_ASSERT(reporter == nullptr, "Unexpected WarningReporter active");
|
|
||||||
SetWarningReporter(context_, prevReporter_);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern JS_PUBLIC_API bool CreateError(
|
extern JS_PUBLIC_API bool CreateError(
|
||||||
JSContext* cx, JSExnType type, HandleObject stack, HandleString fileName,
|
JSContext* cx, JSExnType type, HandleObject stack, HandleString fileName,
|
||||||
uint32_t lineNumber, uint32_t columnNumber, JSErrorReport* report,
|
uint32_t lineNumber, uint32_t columnNumber, JSErrorReport* report,
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "js/CharacterEncoding.h"
|
#include "js/CharacterEncoding.h"
|
||||||
#include "js/PropertySpec.h"
|
#include "js/PropertySpec.h"
|
||||||
#include "js/UniquePtr.h"
|
#include "js/UniquePtr.h"
|
||||||
|
#include "js/Warnings.h" // JS::{,Set}WarningReporter
|
||||||
#include "js/Wrapper.h"
|
#include "js/Wrapper.h"
|
||||||
#include "util/StringBuffer.h"
|
#include "util/StringBuffer.h"
|
||||||
#include "vm/ErrorObject.h"
|
#include "vm/ErrorObject.h"
|
||||||
|
|
|
@ -191,6 +191,7 @@ EXPORTS.js += [
|
||||||
'../public/Utility.h',
|
'../public/Utility.h',
|
||||||
'../public/Value.h',
|
'../public/Value.h',
|
||||||
'../public/Vector.h',
|
'../public/Vector.h',
|
||||||
|
'../public/Warnings.h',
|
||||||
'../public/WeakMapPtr.h',
|
'../public/WeakMapPtr.h',
|
||||||
'../public/Wrapper.h',
|
'../public/Wrapper.h',
|
||||||
]
|
]
|
||||||
|
@ -328,6 +329,7 @@ UNIFIED_SOURCES += [
|
||||||
'vm/UbiNodeCensus.cpp',
|
'vm/UbiNodeCensus.cpp',
|
||||||
'vm/UbiNodeShortestPaths.cpp',
|
'vm/UbiNodeShortestPaths.cpp',
|
||||||
'vm/Value.cpp',
|
'vm/Value.cpp',
|
||||||
|
'vm/Warnings.cpp',
|
||||||
'vm/Xdr.cpp',
|
'vm/Xdr.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
#include "js/StableStringChars.h"
|
#include "js/StableStringChars.h"
|
||||||
#include "js/StructuredClone.h"
|
#include "js/StructuredClone.h"
|
||||||
#include "js/SweepingAPI.h"
|
#include "js/SweepingAPI.h"
|
||||||
|
#include "js/Warnings.h" // JS::SetWarningReporter
|
||||||
#include "js/Wrapper.h"
|
#include "js/Wrapper.h"
|
||||||
#include "perf/jsperf.h"
|
#include "perf/jsperf.h"
|
||||||
#include "shell/jsoptparse.h"
|
#include "shell/jsoptparse.h"
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "jsexn.h"
|
#include "jsexn.h"
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
|
|
||||||
|
#include "js/Warnings.h" // JS::WarningReporter
|
||||||
#include "vm/GlobalObject.h"
|
#include "vm/GlobalObject.h"
|
||||||
#include "vm/JSContext.h"
|
#include "vm/JSContext.h"
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "js/UniquePtr.h"
|
#include "js/UniquePtr.h"
|
||||||
#include "js/Utility.h"
|
#include "js/Utility.h"
|
||||||
#include "js/Vector.h"
|
#include "js/Vector.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarningReporter
|
||||||
#include "threading/Thread.h"
|
#include "threading/Thread.h"
|
||||||
#include "vm/Caches.h"
|
#include "vm/Caches.h"
|
||||||
#include "vm/CodeCoverage.h"
|
#include "vm/CodeCoverage.h"
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "js/Date.h"
|
#include "js/Date.h"
|
||||||
#include "js/PropertySpec.h"
|
#include "js/PropertySpec.h"
|
||||||
#include "js/StableStringChars.h"
|
#include "js/StableStringChars.h"
|
||||||
|
#include "js/Warnings.h" // JS::{,Set}WarningReporter
|
||||||
#include "js/Wrapper.h"
|
#include "js/Wrapper.h"
|
||||||
#include "util/StringBuffer.h"
|
#include "util/StringBuffer.h"
|
||||||
#include "vm/ArgumentsObject.h"
|
#include "vm/ArgumentsObject.h"
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "js/Warnings.h"
|
||||||
|
|
||||||
|
#include <stdarg.h> // va_{list,start,end}
|
||||||
|
|
||||||
|
#include "jsapi.h" // js::AssertHeapIsIdle
|
||||||
|
#include "jstypes.h" // JS_PUBLIC_API
|
||||||
|
|
||||||
|
#include "js/ErrorReport.h" // JSREPORT_WARNING
|
||||||
|
#include "vm/JSContext.h" // js::ArgumentsAre{ASCII,Latin1,UTF8}, js::ReportErrorVA
|
||||||
|
|
||||||
|
using js::ArgumentsAreASCII;
|
||||||
|
using js::ArgumentsAreLatin1;
|
||||||
|
using js::ArgumentsAreUTF8;
|
||||||
|
using js::AssertHeapIsIdle;
|
||||||
|
using js::ReportErrorVA;
|
||||||
|
|
||||||
|
JS_PUBLIC_API bool JS::WarnASCII(JSContext* cx, const char* format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
AssertHeapIsIdle();
|
||||||
|
va_start(ap, format);
|
||||||
|
ok = ReportErrorVA(cx, JSREPORT_WARNING, format, ArgumentsAreASCII, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API bool JS::WarnLatin1(JSContext* cx, const char* format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
AssertHeapIsIdle();
|
||||||
|
va_start(ap, format);
|
||||||
|
ok = ReportErrorVA(cx, JSREPORT_WARNING, format, ArgumentsAreLatin1, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API bool JS::WarnUTF8(JSContext* cx, const char* format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
AssertHeapIsIdle();
|
||||||
|
va_start(ap, format);
|
||||||
|
ok = ReportErrorVA(cx, JSREPORT_WARNING, format, ArgumentsAreUTF8, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API JS::WarningReporter JS::GetWarningReporter(JSContext* cx) {
|
||||||
|
return cx->runtime()->warningReporter;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_PUBLIC_API JS::WarningReporter JS::SetWarningReporter(
|
||||||
|
JSContext* cx, WarningReporter reporter) {
|
||||||
|
WarningReporter older = cx->runtime()->warningReporter;
|
||||||
|
cx->runtime()->warningReporter = reporter;
|
||||||
|
return older;
|
||||||
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
#include "js/PropertySpec.h"
|
#include "js/PropertySpec.h"
|
||||||
#include "js/SourceText.h"
|
#include "js/SourceText.h"
|
||||||
#include "js/Utility.h"
|
#include "js/Utility.h"
|
||||||
|
#include "js/Warnings.h" // JS::SetWarningReporter
|
||||||
#include "prnetdb.h"
|
#include "prnetdb.h"
|
||||||
#include "nsITimer.h"
|
#include "nsITimer.h"
|
||||||
#include "mozilla/net/DNS.h"
|
#include "mozilla/net/DNS.h"
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "nsAppShell.h"
|
#include "nsAppShell.h"
|
||||||
#include "nsIXPConnect.h"
|
#include "nsIXPConnect.h"
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
|
#include "js/Warnings.h" // JS::WarnUTF8
|
||||||
#include "xpcpublic.h"
|
#include "xpcpublic.h"
|
||||||
|
|
||||||
#include "mozilla/ScopeExit.h"
|
#include "mozilla/ScopeExit.h"
|
||||||
|
@ -296,7 +297,7 @@ nsresult BoxData(const nsAString& aEvent, JSContext* aCx, JS::HandleValue aData,
|
||||||
|
|
||||||
NS_ConvertUTF16toUTF8 event(aEvent);
|
NS_ConvertUTF16toUTF8 event(aEvent);
|
||||||
if (JS_IsExceptionPending(aCx)) {
|
if (JS_IsExceptionPending(aCx)) {
|
||||||
JS_ReportWarningUTF8(aCx, "Error dispatching %s", event.get());
|
JS::WarnUTF8(aCx, "Error dispatching %s", event.get());
|
||||||
} else {
|
} else {
|
||||||
JS_ReportErrorUTF8(aCx, "Invalid event data for %s", event.get());
|
JS_ReportErrorUTF8(aCx, "Invalid event data for %s", event.get());
|
||||||
}
|
}
|
||||||
|
@ -566,7 +567,7 @@ nsresult UnboxData(jni::String::Param aEvent, JSContext* aCx,
|
||||||
|
|
||||||
nsCString event = aEvent->ToCString();
|
nsCString event = aEvent->ToCString();
|
||||||
if (JS_IsExceptionPending(aCx)) {
|
if (JS_IsExceptionPending(aCx)) {
|
||||||
JS_ReportWarningUTF8(aCx, "Error dispatching %s", event.get());
|
JS::WarnUTF8(aCx, "Error dispatching %s", event.get());
|
||||||
} else {
|
} else {
|
||||||
JS_ReportErrorUTF8(aCx, "Invalid event data for %s", event.get());
|
JS_ReportErrorUTF8(aCx, "Invalid event data for %s", event.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
#include "js/Debug.h"
|
#include "js/Debug.h"
|
||||||
#include "js/GCAPI.h"
|
#include "js/GCAPI.h"
|
||||||
|
#include "js/Warnings.h" // JS::SetWarningReporter
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsCycleCollectionNoteRootCallback.h"
|
#include "nsCycleCollectionNoteRootCallback.h"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче