Bug 1289050 - Part 12: Use ASCII or Latin1 or UTF8 variant of JS_ReportErrorFlagsAndNumber. r=jwalden

This commit is contained in:
Tooru Fujisawa 2016-08-14 20:39:30 +09:00
Родитель 64346ea2e2
Коммит 89fced778e
15 изменённых файлов: 83 добавлений и 73 удалений

Просмотреть файл

@ -7363,8 +7363,8 @@ CheckModule(ExclusiveContext* cx, AsmJSParser& parser, ParseNode* stmtList, unsi
static bool
LinkFail(JSContext* cx, const char* str)
{
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, GetErrorMessage,
nullptr, JSMSG_USE_ASM_LINK_FAIL, str);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
JSMSG_USE_ASM_LINK_FAIL, str);
return false;
}

Просмотреть файл

@ -1579,9 +1579,12 @@ WebAssembly_validate(JSContext* cx, unsigned argc, Value* vp)
return false;
}
if (error && !JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
JSMSG_WASM_COMPILE_ERROR, error.get())) {
return false;
if (error) {
if (!JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
JSMSG_WASM_COMPILE_ERROR, error.get()))
{
return false;
}
}
callArgs.rval().setBoolean(validated);

Просмотреть файл

@ -97,8 +97,10 @@ GetDeflatedUTF8StringLength(JSContext* maybecx, const CharT* chars,
js::gc::AutoSuppressGC suppress(maybecx);
char buffer[10];
SprintfLiteral(buffer, "0x%x", c);
JS_ReportErrorFlagsAndNumber(maybecx, JSREPORT_ERROR, GetErrorMessage,
nullptr, JSMSG_BAD_SURROGATE_CHAR, buffer);
JS_ReportErrorFlagsAndNumberASCII(maybecx, JSREPORT_ERROR,
GetErrorMessage,
nullptr, JSMSG_BAD_SURROGATE_CHAR,
buffer);
}
return (size_t) -1;
}

Просмотреть файл

@ -169,19 +169,19 @@ JS::ObjectOpResult::reportStrictErrorOrWarning(JSContext* cx, HandleObject obj,
if (!str)
return false;
JSAutoByteString propName(cx, str);
if (!propName)
JSAutoByteString propName;
if (!propName.encodeUtf8(cx, str))
return false;
if (ErrorTakesObjectArgument(code_)) {
return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_,
obj->getClass()->name, propName.ptr());
return JS_ReportErrorFlagsAndNumberUTF8(cx, flags, GetErrorMessage, nullptr, code_,
obj->getClass()->name, propName.ptr());
}
return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_,
propName.ptr());
return JS_ReportErrorFlagsAndNumberUTF8(cx, flags, GetErrorMessage, nullptr, code_,
propName.ptr());
}
return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_);
return JS_ReportErrorFlagsAndNumberASCII(cx, flags, GetErrorMessage, nullptr, code_);
}
JS_PUBLIC_API(bool)
@ -192,7 +192,7 @@ JS::ObjectOpResult::reportStrictErrorOrWarning(JSContext* cx, HandleObject obj,
MOZ_ASSERT(!ErrorTakesArguments(code_));
unsigned flags = strict ? JSREPORT_ERROR : (JSREPORT_WARNING | JSREPORT_STRICT);
return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, code_);
return JS_ReportErrorFlagsAndNumberASCII(cx, flags, GetErrorMessage, nullptr, code_);
}
JS_PUBLIC_API(bool)

Просмотреть файл

@ -834,21 +834,21 @@ js::ReportIsNullOrUndefined(JSContext* cx, int spindex, HandleValue v,
if (strcmp(bytes.get(), js_undefined_str) == 0 ||
strcmp(bytes.get(), js_null_str) == 0) {
ok = JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR,
GetErrorMessage, nullptr,
JSMSG_NO_PROPERTIES, bytes.get(),
nullptr, nullptr);
ok = JS_ReportErrorFlagsAndNumberLatin1(cx, JSREPORT_ERROR,
GetErrorMessage, nullptr,
JSMSG_NO_PROPERTIES,
bytes.get());
} else if (v.isUndefined()) {
ok = JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR,
GetErrorMessage, nullptr,
JSMSG_UNEXPECTED_TYPE, bytes.get(),
js_undefined_str, nullptr);
ok = JS_ReportErrorFlagsAndNumberLatin1(cx, JSREPORT_ERROR,
GetErrorMessage, nullptr,
JSMSG_UNEXPECTED_TYPE,
bytes.get(), js_undefined_str);
} else {
MOZ_ASSERT(v.isNull());
ok = JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR,
GetErrorMessage, nullptr,
JSMSG_UNEXPECTED_TYPE, bytes.get(),
js_null_str, nullptr);
ok = JS_ReportErrorFlagsAndNumberLatin1(cx, JSREPORT_ERROR,
GetErrorMessage, nullptr,
JSMSG_UNEXPECTED_TYPE,
bytes.get(), js_null_str);
}
return ok;
@ -886,8 +886,8 @@ js::ReportValueErrorFlags(JSContext* cx, unsigned flags, const unsigned errorNum
if (!bytes)
return false;
ok = JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage,
nullptr, errorNumber, bytes.get(), arg1, arg2);
ok = JS_ReportErrorFlagsAndNumberLatin1(cx, flags, GetErrorMessage, nullptr, errorNumber,
bytes.get(), arg1, arg2);
return ok;
}

Просмотреть файл

@ -2559,8 +2559,8 @@ date_toJSON(JSContext* cx, unsigned argc, Value* vp)
/* Step 5. */
if (!IsCallable(toISO)) {
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js::GetErrorMessage, nullptr,
JSMSG_BAD_TOISOSTRING_PROP);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, js::GetErrorMessage, nullptr,
JSMSG_BAD_TOISOSTRING_PROP);
return false;
}

Просмотреть файл

@ -109,8 +109,8 @@ AdvanceToActiveCallLinear(JSContext* cx, NonBuiltinScriptFrameIter& iter, Handle
static void
ThrowTypeErrorBehavior(JSContext* cx)
{
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_THROW_TYPE_ERROR);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_THROW_TYPE_ERROR);
}
static bool
@ -144,8 +144,8 @@ ArgumentsRestrictions(JSContext* cx, HandleFunction fun)
// Otherwise emit a strict warning about |f.arguments| to discourage use of
// this non-standard, performance-harmful feature.
if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING | JSREPORT_STRICT, GetErrorMessage,
nullptr, JSMSG_DEPRECATED_USAGE, js_arguments_str))
if (!JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_WARNING | JSREPORT_STRICT, GetErrorMessage,
nullptr, JSMSG_DEPRECATED_USAGE, js_arguments_str))
{
return false;
}
@ -231,8 +231,8 @@ CallerRestrictions(JSContext* cx, HandleFunction fun)
// Otherwise emit a strict warning about |f.caller| to discourage use of
// this non-standard, performance-harmful feature.
if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING | JSREPORT_STRICT, GetErrorMessage,
nullptr, JSMSG_DEPRECATED_USAGE, js_caller_str))
if (!JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_WARNING | JSREPORT_STRICT, GetErrorMessage,
nullptr, JSMSG_DEPRECATED_USAGE, js_caller_str))
{
return false;
}
@ -287,8 +287,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args)
MOZ_ASSERT(!callerFun->isBuiltin(), "non-builtin iterator returned a builtin?");
if (callerFun->strict()) {
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_CALLER_IS_STRICT);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_CALLER_IS_STRICT);
return false;
}
}
@ -352,8 +352,8 @@ CallerSetterImpl(JSContext* cx, const CallArgs& args)
MOZ_ASSERT(!callerFun->isBuiltin(), "non-builtin iterator returned a builtin?");
if (callerFun->strict()) {
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_CALLER_IS_STRICT);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_CALLER_IS_STRICT);
return false;
}

Просмотреть файл

@ -3281,12 +3281,12 @@ GetObjectSlotNameFunctor::operator()(JS::CallbackTracer* trc, char* buf, size_t
bool
js::ReportGetterOnlyAssignment(JSContext* cx, bool strict)
{
return JS_ReportErrorFlagsAndNumber(cx,
strict
? JSREPORT_ERROR
: JSREPORT_WARNING | JSREPORT_STRICT,
GetErrorMessage, nullptr,
JSMSG_GETTER_ONLY);
return JS_ReportErrorFlagsAndNumberASCII(cx,
strict
? JSREPORT_ERROR
: JSREPORT_WARNING | JSREPORT_STRICT,
GetErrorMessage, nullptr,
JSMSG_GETTER_ONLY);
}

Просмотреть файл

@ -2103,11 +2103,12 @@ ScriptSource::setDisplayURL(ExclusiveContext* cx, const char16_t* displayURL)
{
MOZ_ASSERT(displayURL);
if (hasDisplayURL()) {
// FIXME: filename_.get() should be UTF-8 (bug 987069).
if (cx->isJSContext() &&
!JS_ReportErrorFlagsAndNumber(cx->asJSContext(), JSREPORT_WARNING,
GetErrorMessage, nullptr,
JSMSG_ALREADY_HAS_PRAGMA, filename_.get(),
"//# sourceURL"))
!JS_ReportErrorFlagsAndNumberLatin1(cx->asJSContext(), JSREPORT_WARNING,
GetErrorMessage, nullptr,
JSMSG_ALREADY_HAS_PRAGMA, filename_.get(),
"//# sourceURL"))
{
return false;
}

Просмотреть файл

@ -231,8 +231,8 @@ ReportInvalidCharacter(JSContext* cx, uint32_t offset)
{
char buffer[10];
SprintfLiteral(buffer, "%u", offset);
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_MALFORMED_UTF8_CHAR, buffer);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_MALFORMED_UTF8_CHAR, buffer);
}
static void
@ -256,8 +256,8 @@ ReportTooBigCharacter(JSContext* cx, uint32_t v)
{
char buffer[10];
SprintfLiteral(buffer, "0x%x", v + 0x10000);
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_UTF8_CHAR_TOO_LARGE, buffer);
JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_UTF8_CHAR_TOO_LARGE, buffer);
}
static void

Просмотреть файл

@ -352,9 +352,10 @@ class MOZ_RAII js::EnterDebuggeeNoExecute
char linenoStr[15];
SprintfLiteral(linenoStr, "%" PRIuSIZE, script->lineno());
unsigned flags = warning ? JSREPORT_WARNING : JSREPORT_ERROR;
return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr,
JSMSG_DEBUGGEE_WOULD_RUN,
filename, linenoStr);
// FIXME: filename should be UTF-8 (bug 987069).
return JS_ReportErrorFlagsAndNumberLatin1(cx, flags, GetErrorMessage, nullptr,
JSMSG_DEBUGGEE_WOULD_RUN,
filename, linenoStr);
}
}
return true;

Просмотреть файл

@ -565,8 +565,8 @@ GlobalObject::warnOnceAbout(JSContext* cx, HandleObject obj, WarnOnceFlag flag,
MOZ_ASSERT_IF(!v.isUndefined(), v.toInt32());
int32_t flags = v.isUndefined() ? 0 : v.toInt32();
if (!(flags & flag)) {
if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
errorNumber))
if (!JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
errorNumber))
{
return false;
}

Просмотреть файл

@ -593,8 +593,8 @@ ThrowIfNotConstructing(JSContext *cx, const CallArgs &args, const char *builtinN
{
if (args.isConstructing())
return true;
return JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_BUILTIN_CTOR_NO_NEW, builtinName);
return JS_ReportErrorFlagsAndNumberASCII(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_BUILTIN_CTOR_NO_NEW, builtinName);
}
inline bool

Просмотреть файл

@ -2086,7 +2086,7 @@ js::GetPropertyForNameLookup(JSContext* cx, HandleObject obj, HandleId id, Mutab
/*** [[Set]] *************************************************************************************/
static bool
MaybeReportUndeclaredVarAssignment(JSContext* cx, JSString* propname)
MaybeReportUndeclaredVarAssignment(JSContext* cx, HandleString propname)
{
unsigned flags;
{
@ -2105,10 +2105,11 @@ MaybeReportUndeclaredVarAssignment(JSContext* cx, JSString* propname)
return true;
}
JSAutoByteString bytes(cx, propname);
return !!bytes &&
JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr,
JSMSG_UNDECLARED_VAR, bytes.ptr());
JSAutoByteString bytes;
if (!bytes.encodeUtf8(cx, propname))
return false;
return JS_ReportErrorFlagsAndNumberUTF8(cx, flags, GetErrorMessage, nullptr,
JSMSG_UNDECLARED_VAR, bytes.ptr());
}
/*
@ -2269,7 +2270,8 @@ SetNonexistentProperty(JSContext* cx, HandleId id, HandleValue v, HandleValue re
QualifiedBool qualified, ObjectOpResult& result)
{
if (!qualified && receiver.isObject() && receiver.toObject().isUnqualifiedVarObj()) {
if (!MaybeReportUndeclaredVarAssignment(cx, JSID_TO_STRING(id)))
RootedString idStr(cx, JSID_TO_STRING(id));
if (!MaybeReportUndeclaredVarAssignment(cx, idStr))
return false;
}

Просмотреть файл

@ -1056,11 +1056,12 @@ js::ParseRegExpFlags(JSContext* cx, JSString* flagStr, RegExpFlag* flagsOut)
}
if (!ok) {
char charBuf[2];
charBuf[0] = char(lastParsed);
charBuf[1] = '\0';
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_BAD_REGEXP_FLAG, charBuf);
TwoByteChars range(&lastParsed, 1);
UniqueChars utf8(JS::CharsToNewUTF8CharsZ(nullptr, range).c_str());
if (!utf8)
return false;
JS_ReportErrorFlagsAndNumberUTF8(cx, JSREPORT_ERROR, GetErrorMessage, nullptr,
JSMSG_BAD_REGEXP_FLAG, utf8.get());
return false;
}