mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1289050 - Part 2.2: Use ASCII variant of JS_ReportError when formatting JSClass::name, and assert it is ASCII. r=jwalden
This commit is contained in:
parent
f2542c1849
commit
458bd95e06
@ -323,6 +323,13 @@ UTF8CharsToNewLatin1CharsZ(JSContext* cx, const UTF8Chars utf8, size_t* outlen);
|
||||
extern Latin1CharsZ
|
||||
LossyUTF8CharsToNewLatin1CharsZ(JSContext* cx, const UTF8Chars utf8, size_t* outlen);
|
||||
|
||||
/*
|
||||
* Returns true if all characters in the given null-terminated string are
|
||||
* ASCII, i.e. < 0x80, false otherwise.
|
||||
*/
|
||||
extern bool
|
||||
StringIsASCII(const char* s);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
inline void JS_free(JS::Latin1CharsZ& ptr) { js_free((void*)ptr.get()); }
|
||||
|
@ -317,17 +317,6 @@ checkReportFlags(JSContext* cx, unsigned* flags)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
AssertIsASCII(const char* s)
|
||||
{
|
||||
while (*s) {
|
||||
MOZ_ASSERT((*s & 0x80) == 0);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
js::ReportErrorVA(JSContext* cx, unsigned flags, const char* format,
|
||||
ErrorArgumentsType argumentsType, va_list ap)
|
||||
@ -348,10 +337,7 @@ js::ReportErrorVA(JSContext* cx, unsigned flags, const char* format,
|
||||
}
|
||||
messagelen = strlen(message);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (argumentsType == ArgumentsAreASCII)
|
||||
AssertIsASCII(message);
|
||||
#endif
|
||||
MOZ_ASSERT_IF(argumentsType == ArgumentsAreASCII, JS::StringIsASCII(message));
|
||||
|
||||
report.flags = flags;
|
||||
report.errorNumber = JSMSG_USER_DEFINED_ERROR;
|
||||
@ -570,10 +556,7 @@ class MOZ_RAII AutoMessageArgs
|
||||
const char* charArg = va_arg(ap, char*);
|
||||
size_t charArgLength = strlen(charArg);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (typeArg == ArgumentsAreASCII)
|
||||
AssertIsASCII(charArg);
|
||||
#endif
|
||||
MOZ_ASSERT_IF(typeArg == ArgumentsAreASCII, JS::StringIsASCII(charArg));
|
||||
|
||||
args_[i] = InflateString(cx, charArg, &charArgLength);
|
||||
if (!args_[i])
|
||||
@ -631,10 +614,7 @@ js::ExpandErrorArgumentsVA(ExclusiveContext* cx, JSErrorCallback callback,
|
||||
if (efs) {
|
||||
reportp->exnType = efs->exnType;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (argumentsType == ArgumentsAreASCII)
|
||||
AssertIsASCII(efs->format);
|
||||
#endif
|
||||
MOZ_ASSERT_IF(argumentsType == ArgumentsAreASCII, JS::StringIsASCII(efs->format));
|
||||
|
||||
uint16_t argCount = efs->argCount;
|
||||
MOZ_RELEASE_ASSERT(argCount <= JS::MaxNumErrorArguments);
|
||||
|
@ -3790,7 +3790,7 @@ Compile(JSContext* cx, unsigned argc, Value* vp)
|
||||
}
|
||||
if (!args[0].isString()) {
|
||||
const char* typeName = InformalValueTypeName(args[0]);
|
||||
JS_ReportError(cx, "expected string to compile, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected string to compile, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3827,7 +3827,7 @@ ParseModule(JSContext* cx, unsigned argc, Value* vp)
|
||||
|
||||
if (!args[0].isString()) {
|
||||
const char* typeName = InformalValueTypeName(args[0]);
|
||||
JS_ReportError(cx, "expected string to compile, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected string to compile, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3840,7 +3840,7 @@ ParseModule(JSContext* cx, unsigned argc, Value* vp)
|
||||
if (args.length() > 1) {
|
||||
if (!args[1].isString()) {
|
||||
const char* typeName = InformalValueTypeName(args[1]);
|
||||
JS_ReportError(cx, "expected filename string, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected filename string, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3882,7 +3882,7 @@ SetModuleResolveHook(JSContext* cx, unsigned argc, Value* vp)
|
||||
|
||||
if (!args[0].isObject() || !args[0].toObject().is<JSFunction>()) {
|
||||
const char* typeName = InformalValueTypeName(args[0]);
|
||||
JS_ReportError(cx, "expected hook function, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected hook function, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3915,7 +3915,7 @@ Parse(JSContext* cx, unsigned argc, Value* vp)
|
||||
}
|
||||
if (!args[0].isString()) {
|
||||
const char* typeName = InformalValueTypeName(args[0]);
|
||||
JS_ReportError(cx, "expected string to parse, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected string to parse, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3966,7 +3966,7 @@ SyntaxParse(JSContext* cx, unsigned argc, Value* vp)
|
||||
}
|
||||
if (!args[0].isString()) {
|
||||
const char* typeName = InformalValueTypeName(args[0]);
|
||||
JS_ReportError(cx, "expected string to parse, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected string to parse, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -4031,7 +4031,7 @@ OffThreadCompileScript(JSContext* cx, unsigned argc, Value* vp)
|
||||
}
|
||||
if (!args[0].isString()) {
|
||||
const char* typeName = InformalValueTypeName(args[0]);
|
||||
JS_ReportError(cx, "expected string to parse, got %s", typeName);
|
||||
JS_ReportErrorASCII(cx, "expected string to parse, got %s", typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -518,3 +518,14 @@ JS::ConstUTF8CharsZ::validate(size_t aLength)
|
||||
/* smallestEncoding = */ nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
JS::StringIsASCII(const char* s)
|
||||
{
|
||||
while (*s) {
|
||||
if (*s & 0x80)
|
||||
return false;
|
||||
s++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "gc/Policy.h"
|
||||
#include "gc/StoreBuffer.h"
|
||||
#include "gc/Zone.h"
|
||||
#include "js/CharacterEncoding.h"
|
||||
#include "vm/ArrayObject.h"
|
||||
#include "vm/TaggedProto.h"
|
||||
#include "vm/UnboxedObject.h"
|
||||
@ -37,6 +38,7 @@ ObjectGroup::ObjectGroup(const Class* clasp, TaggedProto proto, JSCompartment* c
|
||||
|
||||
/* Windows may not appear on prototype chains. */
|
||||
MOZ_ASSERT_IF(proto.isObject(), !IsWindow(proto.toObject()));
|
||||
MOZ_ASSERT(JS::StringIsASCII(clasp->name));
|
||||
|
||||
this->clasp_ = clasp;
|
||||
this->proto_ = proto;
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "ds/IdValuePair.h"
|
||||
#include "gc/Barrier.h"
|
||||
#include "js/CharacterEncoding.h"
|
||||
#include "js/GCHashTable.h"
|
||||
#include "vm/TaggedProto.h"
|
||||
#include "vm/TypeInference.h"
|
||||
@ -102,6 +103,7 @@ class ObjectGroup : public gc::TenuredCell
|
||||
}
|
||||
|
||||
void setClasp(const Class* clasp) {
|
||||
MOZ_ASSERT(JS::StringIsASCII(clasp->name));
|
||||
clasp_ = clasp;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user