Bug 1289050 - Part 2: Use ASCII or Latin1 variants of JS_ReportError in not-simple cases. r=jwalden

This commit is contained in:
Tooru Fujisawa 2016-08-15 19:20:01 +09:00
Родитель c94460a3d9
Коммит 10dd75211d
12 изменённых файлов: 115 добавлений и 113 удалений

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

@ -147,14 +147,15 @@ GetPrincipalDomainOrigin(nsIPrincipal* aPrincipal,
return GetOriginFromURI(uri, aOrigin);
}
inline void SetPendingException(JSContext *cx, const char *aMsg)
inline void SetPendingExceptionASCII(JSContext *cx, const char *aMsg)
{
JS_ReportError(cx, "%s", aMsg);
JS_ReportErrorASCII(cx, "%s", aMsg);
}
inline void SetPendingException(JSContext *cx, const char16_t *aMsg)
{
JS_ReportError(cx, "%hs", aMsg);
// FIXME: Need to convert to UTF-8 (bug XXX).
JS_ReportErrorLatin1(cx, "%hs", aMsg);
}
// Helper class to get stuff from the ClassInfo and not waste extra time with
@ -596,7 +597,7 @@ nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, nsIURI *aURI)
nsAutoCString msg("Access to '");
msg.Append(spec);
msg.AppendLiteral("' from script denied");
SetPendingException(cx, msg.get());
SetPendingExceptionASCII(cx, msg.get());
return NS_ERROR_DOM_BAD_URI;
}
@ -1305,7 +1306,7 @@ nsScriptSecurityManager::CanCreateInstance(JSContext *cx,
char cidStr[NSID_LENGTH];
aCID.ToProvidedString(cidStr);
errorMsg.Append(cidStr);
SetPendingException(cx, errorMsg.get());
SetPendingExceptionASCII(cx, errorMsg.get());
return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
}
@ -1322,7 +1323,7 @@ nsScriptSecurityManager::CanGetService(JSContext *cx,
char cidStr[NSID_LENGTH];
aCID.ToProvidedString(cidStr);
errorMsg.Append(cidStr);
SetPendingException(cx, errorMsg.get());
SetPendingExceptionASCII(cx, errorMsg.get());
return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
}

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

@ -610,7 +610,7 @@ JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant)
}
static void
ThrowJSException(JSContext *cx, const char *message)
ThrowJSExceptionASCII(JSContext *cx, const char *message)
{
const char *ex = PeekException();
@ -638,7 +638,7 @@ ThrowJSException(JSContext *cx, const char *message)
PopException();
} else {
::JS_ReportError(cx, message);
::JS_ReportErrorASCII(cx, message);
}
}
@ -651,7 +651,7 @@ ReportExceptionIfPending(JSContext *cx)
return true;
}
ThrowJSException(cx, nullptr);
ThrowJSExceptionASCII(cx, nullptr);
return false;
}
@ -736,8 +736,8 @@ nsJSObjWrapper::NP_HasMethod(NPObject *npobj, NPIdentifier id)
JSContext *cx = aes.cx();
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_HasMethod!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_HasMethod!");
return false;
}
@ -772,7 +772,7 @@ doInvoke(NPObject *npobj, NPIdentifier method, const NPVariant *args,
JSContext *cx = aes.cx();
if (!npobj || !result) {
ThrowJSException(cx, "Null npobj, or result in doInvoke!");
ThrowJSExceptionASCII(cx, "Null npobj, or result in doInvoke!");
return false;
}
@ -864,8 +864,8 @@ nsJSObjWrapper::NP_HasProperty(NPObject *npobj, NPIdentifier npid)
JSContext *cx = aes.cx();
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_HasProperty!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_HasProperty!");
return false;
}
@ -902,8 +902,8 @@ nsJSObjWrapper::NP_GetProperty(NPObject *npobj, NPIdentifier id,
JSContext *cx = aes.cx();
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_GetProperty!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_GetProperty!");
return false;
}
@ -936,8 +936,8 @@ nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier npid,
JSContext *cx = aes.cx();
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_SetProperty!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_SetProperty!");
return false;
}
@ -973,8 +973,8 @@ nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier npid)
JSContext *cx = aes.cx();
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_RemoveProperty!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_RemoveProperty!");
return false;
}
@ -1027,8 +1027,8 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
*count = 0;
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_Enumerate!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_Enumerate!");
return false;
}
@ -1047,7 +1047,7 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
*count = ida.length();
*idarray = (NPIdentifier *)PR_Malloc(*count * sizeof(NPIdentifier));
if (!*idarray) {
ThrowJSException(cx, "Memory allocation failed for NPIdentifier!");
ThrowJSExceptionASCII(cx, "Memory allocation failed for NPIdentifier!");
return false;
}
@ -1216,7 +1216,7 @@ NPObjWrapper_AddProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->hasMethod) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -1242,7 +1242,7 @@ NPObjWrapper_AddProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
return false;
if (!hasMethod) {
ThrowJSException(cx, "Trying to add unsupported property on NPObject!");
ThrowJSExceptionASCII(cx, "Trying to add unsupported property on NPObject!");
return false;
}
@ -1258,7 +1258,7 @@ NPObjWrapper_DelProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->removeProperty) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -1294,7 +1294,7 @@ NPObjWrapper_SetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->setProperty) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -1304,7 +1304,7 @@ NPObjWrapper_SetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
NPP npp = LookupNPP(npobj);
if (!npp) {
ThrowJSException(cx, "No NPP found for NPObject!");
ThrowJSExceptionASCII(cx, "No NPP found for NPObject!");
return false;
}
@ -1319,7 +1319,7 @@ NPObjWrapper_SetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
return false;
if (!hasProperty) {
ThrowJSException(cx, "Trying to set unsupported property on NPObject!");
ThrowJSExceptionASCII(cx, "Trying to set unsupported property on NPObject!");
return false;
}
@ -1327,7 +1327,7 @@ NPObjWrapper_SetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
NPVariant npv;
if (!JSValToNPVariant(npp, cx, vp, &npv)) {
ThrowJSException(cx, "Error converting jsval to NPVariant!");
ThrowJSExceptionASCII(cx, "Error converting jsval to NPVariant!");
return false;
}
@ -1338,7 +1338,7 @@ NPObjWrapper_SetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
return false;
if (!ok) {
ThrowJSException(cx, "Error setting property on NPObject!");
ThrowJSExceptionASCII(cx, "Error setting property on NPObject!");
return false;
}
@ -1353,7 +1353,7 @@ NPObjWrapper_GetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->hasMethod || !npobj->_class->getProperty) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -1389,7 +1389,7 @@ NPObjWrapper_GetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<js
// manipulating, and make it own any JSObject wrappers created here.
NPP npp = LookupNPP(npobj);
if (!npp) {
ThrowJSException(cx, "No NPP found for NPObject!");
ThrowJSExceptionASCII(cx, "No NPP found for NPObject!");
return false;
}
@ -1475,7 +1475,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
NPObject *npobj = GetNPObject(cx, obj);
if (!npobj || !npobj->_class) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -1485,7 +1485,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
NPP npp = LookupNPP(npobj);
if (!npp) {
ThrowJSException(cx, "Error finding NPP for NPObject!");
ThrowJSExceptionASCII(cx, "Error finding NPP for NPObject!");
return false;
}
@ -1501,7 +1501,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
npargs = (NPVariant *)PR_Malloc(argc * sizeof(NPVariant));
if (!npargs) {
ThrowJSException(cx, "Out of memory!");
ThrowJSExceptionASCII(cx, "Out of memory!");
return false;
}
@ -1511,7 +1511,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
uint32_t i;
for (i = 0; i < argc; ++i) {
if (!JSValToNPVariant(npp, cx, argv[i], npargs + i)) {
ThrowJSException(cx, "Error converting jsvals to NPVariants!");
ThrowJSExceptionASCII(cx, "Error converting jsvals to NPVariants!");
if (npargs != npargs_buf) {
PR_Free(npargs);
@ -1583,7 +1583,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
// ReportExceptionIfPending returns a return value, which is true
// if no exception was thrown. In that case, throw our own.
if (ReportExceptionIfPending(cx))
ThrowJSException(cx, msg);
ThrowJSExceptionASCII(cx, msg);
return false;
}
@ -1613,7 +1613,7 @@ NPObjWrapper_Enumerate(JSContext *cx, JS::Handle<JSObject*> obj,
{
NPObject *npobj = GetNPObject(cx, obj);
if (!npobj || !npobj->_class) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -1630,8 +1630,8 @@ NPObjWrapper_Enumerate(JSContext *cx, JS::Handle<JSObject*> obj,
if (ReportExceptionIfPending(cx)) {
// ReportExceptionIfPending returns a return value, which is true
// if no exception was thrown. In that case, throw our own.
ThrowJSException(cx, "Error enumerating properties on scriptable "
"plugin object");
ThrowJSExceptionASCII(cx, "Error enumerating properties on scriptable "
"plugin object");
}
return false;
}
@ -1662,7 +1662,7 @@ NPObjWrapper_Resolve(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid>
if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
!npobj->_class->hasMethod) {
ThrowJSException(cx, "Bad NPObject as private data!");
ThrowJSExceptionASCII(cx, "Bad NPObject as private data!");
return false;
}
@ -2060,7 +2060,7 @@ CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj,
{
if (!npobj || !npobj->_class || !npobj->_class->getProperty ||
!npobj->_class->invoke) {
ThrowJSException(cx, "Bad NPObject");
ThrowJSExceptionASCII(cx, "Bad NPObject");
return false;
}
@ -2170,7 +2170,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
NPObject *npobj = GetNPObject(cx, memberPrivate->npobjWrapper);
if (!npobj) {
ThrowJSException(cx, "Call on invalid member object");
ThrowJSExceptionASCII(cx, "Call on invalid member object");
return false;
}
@ -2184,7 +2184,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
npargs = (NPVariant *)PR_Malloc(args.length() * sizeof(NPVariant));
if (!npargs) {
ThrowJSException(cx, "Out of memory!");
ThrowJSExceptionASCII(cx, "Out of memory!");
return false;
}
@ -2193,7 +2193,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
// Convert arguments
for (uint32_t i = 0; i < args.length(); ++i) {
if (!JSValToNPVariant(memberPrivate->npp, cx, args[i], npargs + i)) {
ThrowJSException(cx, "Error converting jsvals to NPVariants!");
ThrowJSExceptionASCII(cx, "Error converting jsvals to NPVariants!");
if (npargs != npargs_buf) {
PR_Free(npargs);
@ -2222,7 +2222,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
// ReportExceptionIfPending returns a return value, which is true
// if no exception was thrown. In that case, throw our own.
if (ReportExceptionIfPending(cx))
ThrowJSException(cx, "Error calling method on NPObject!");
ThrowJSExceptionASCII(cx, "Error calling method on NPObject!");
return false;
}
@ -2299,8 +2299,8 @@ nsJSObjWrapper::HasOwnProperty(NPObject *npobj, NPIdentifier npid)
JSContext *cx = aes.cx();
if (!npobj) {
ThrowJSException(cx,
"Null npobj in nsJSObjWrapper::NP_HasOwnProperty!");
ThrowJSExceptionASCII(cx,
"Null npobj in nsJSObjWrapper::NP_HasOwnProperty!");
return false;
}

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

@ -196,9 +196,9 @@ struct RequiredStringArg {
: mCx(cx), mBytes(nullptr)
{
if (args.length() <= argi) {
JS_ReportError(cx, "%s: not enough arguments", caller);
JS_ReportErrorASCII(cx, "%s: not enough arguments", caller);
} else if (!args[argi].isString()) {
JS_ReportError(cx, "%s: invalid arguments (string expected)", caller);
JS_ReportErrorASCII(cx, "%s: invalid arguments (string expected)", caller);
} else {
mBytes = JS_EncodeString(cx, args[argi].toString());
}

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

@ -392,8 +392,8 @@ GCParameter(JSContext* cx, unsigned argc, Value* vp)
size_t paramIndex = 0;
for (;; paramIndex++) {
if (paramIndex == ArrayLength(paramMap)) {
JS_ReportError(cx,
"the first argument must be one of:" GC_PARAMETER_ARGS_LIST);
JS_ReportErrorASCII(cx,
"the first argument must be one of:" GC_PARAMETER_ARGS_LIST);
return false;
}
if (JS_FlatStringEqualsAscii(flatStr, paramMap[paramIndex].name))
@ -410,7 +410,7 @@ GCParameter(JSContext* cx, unsigned argc, Value* vp)
}
if (!info.writable) {
JS_ReportError(cx, "Attempt to change read-only parameter %s", info.name);
JS_ReportErrorASCII(cx, "Attempt to change read-only parameter %s", info.name);
return false;
}
@ -524,7 +524,7 @@ WasmTextToBinary(JSContext* cx, unsigned argc, Value* vp)
return false;
if (!args[0].isString()) {
ReportUsageError(cx, callee, "First argument must be a String");
ReportUsageErrorASCII(cx, callee, "First argument must be a String");
return false;
}
@ -534,7 +534,7 @@ WasmTextToBinary(JSContext* cx, unsigned argc, Value* vp)
if (args.hasDefined(1)) {
if (!args[1].isString()) {
ReportUsageError(cx, callee, "Second argument, if present, must be a String");
ReportUsageErrorASCII(cx, callee, "Second argument, if present, must be a String");
return false;
}
}
@ -688,7 +688,7 @@ GCPreserveCode(JSContext* cx, unsigned argc, Value* vp)
if (args.length() != 0) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
@ -706,7 +706,7 @@ GCZeal(JSContext* cx, unsigned argc, Value* vp)
if (args.length() > 2) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Too many arguments");
ReportUsageErrorASCII(cx, callee, "Too many arguments");
return false;
}
@ -737,7 +737,7 @@ ScheduleGC(JSContext* cx, unsigned argc, Value* vp)
if (args.length() > 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Too many arguments");
ReportUsageErrorASCII(cx, callee, "Too many arguments");
return false;
}
@ -794,7 +794,7 @@ VerifyPreBarriers(JSContext* cx, unsigned argc, Value* vp)
if (args.length() > 0) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Too many arguments");
ReportUsageErrorASCII(cx, callee, "Too many arguments");
return false;
}
@ -810,7 +810,7 @@ VerifyPostBarriers(JSContext* cx, unsigned argc, Value* vp)
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length()) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Too many arguments");
ReportUsageErrorASCII(cx, callee, "Too many arguments");
return false;
}
args.rval().setUndefined();
@ -824,7 +824,7 @@ GCState(JSContext* cx, unsigned argc, Value* vp)
if (args.length() != 0) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Too many arguments");
ReportUsageErrorASCII(cx, callee, "Too many arguments");
return false;
}
@ -843,7 +843,7 @@ DeterministicGC(JSContext* cx, unsigned argc, Value* vp)
if (args.length() != 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
@ -860,7 +860,7 @@ StartGC(JSContext* cx, unsigned argc, Value* vp)
if (args.length() > 2) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
@ -902,7 +902,7 @@ GCSlice(JSContext* cx, unsigned argc, Value* vp)
if (args.length() > 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
@ -931,7 +931,7 @@ AbortGC(JSContext* cx, unsigned argc, Value* vp)
if (args.length() != 0) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
@ -947,7 +947,7 @@ FullCompartmentChecks(JSContext* cx, unsigned argc, Value* vp)
if (args.length() != 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
@ -963,7 +963,7 @@ NondeterministicGetWeakMapKeys(JSContext* cx, unsigned argc, Value* vp)
if (args.length() != 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isObject()) {
@ -1702,7 +1702,7 @@ DisplayName(JSContext* cx, unsigned argc, Value* vp)
CallArgs args = CallArgsFromVp(argc, vp);
if (!args.get(0).isObject() || !args[0].toObject().is<JSFunction>()) {
RootedObject arg(cx, &args.callee());
ReportUsageError(cx, arg, "Must have one function argument");
ReportUsageErrorASCII(cx, arg, "Must have one function argument");
return false;
}
@ -1931,17 +1931,17 @@ SetJitCompilerOption(JSContext* cx, unsigned argc, Value* vp)
RootedObject callee(cx, &args.callee());
if (args.length() != 2) {
ReportUsageError(cx, callee, "Wrong number of arguments.");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments.");
return false;
}
if (!args[0].isString()) {
ReportUsageError(cx, callee, "First argument must be a String.");
ReportUsageErrorASCII(cx, callee, "First argument must be a String.");
return false;
}
if (!args[1].isInt32()) {
ReportUsageError(cx, callee, "Second argument must be an Int32.");
ReportUsageErrorASCII(cx, callee, "Second argument must be an Int32.");
return false;
}
@ -1959,7 +1959,7 @@ SetJitCompilerOption(JSContext* cx, unsigned argc, Value* vp)
#undef JIT_COMPILER_MATCH
if (opt == JSJITCOMPILER_NOT_AN_OPTION) {
ReportUsageError(cx, callee, "First argument does not name a valid option (see jsapi.h).");
ReportUsageErrorASCII(cx, callee, "First argument does not name a valid option (see jsapi.h).");
return false;
}
@ -2349,12 +2349,12 @@ ObjectAddress(JSContext* cx, unsigned argc, Value* vp)
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() != 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isObject()) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Expected object");
ReportUsageErrorASCII(cx, callee, "Expected object");
return false;
}
@ -2381,12 +2381,12 @@ SharedAddress(JSContext* cx, unsigned argc, Value* vp)
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() != 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isObject()) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Expected object");
ReportUsageErrorASCII(cx, callee, "Expected object");
return false;
}
@ -2438,7 +2438,7 @@ GetBacktrace(JSContext* cx, unsigned argc, Value* vp)
if (args.length() > 1) {
RootedObject callee(cx, &args.callee());
ReportUsageError(cx, callee, "Too many arguments");
ReportUsageErrorASCII(cx, callee, "Too many arguments");
return false;
}

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

@ -1323,7 +1323,7 @@ LoopChoiceNode::FilterASCII(int depth, bool ignore_case, bool unicode)
void
Analysis::EnsureAnalyzed(RegExpNode* that)
{
JS_CHECK_RECURSION(cx, fail("Stack overflow"); return);
JS_CHECK_RECURSION(cx, failASCII("Stack overflow"); return);
if (that->info()->been_analyzed || that->info()->being_analyzed)
return;
@ -1872,7 +1872,7 @@ irregexp::CompilePattern(JSContext* cx, RegExpShared* shared, RegExpCompileData*
Analysis analysis(cx, ignore_case, is_ascii, unicode);
analysis.EnsureAnalyzed(node);
if (analysis.has_failed()) {
JS_ReportError(cx, analysis.errorMessage());
JS_ReportErrorASCII(cx, analysis.errorMessage());
return RegExpCode();
}

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

@ -1525,7 +1525,7 @@ class Analysis : public NodeVisitor
MOZ_ASSERT(error_message_ != nullptr);
return error_message_;
}
void fail(const char* error_message) {
void failASCII(const char* error_message) {
error_message_ = error_message;
}

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

@ -379,7 +379,7 @@ js::ReportErrorVA(JSContext* cx, unsigned flags, const char* format,
/* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
void
js::ReportUsageError(JSContext* cx, HandleObject callee, const char* msg)
js::ReportUsageErrorASCII(JSContext* cx, HandleObject callee, const char* msg)
{
const char* usageStr = "usage";
PropertyName* usageAtom = Atomize(cx, usageStr, strlen(usageStr))->asPropertyName();
@ -394,7 +394,7 @@ js::ReportUsageError(JSContext* cx, HandleObject callee, const char* msg)
return;
if (!usage.isString()) {
JS_ReportError(cx, "%s", msg);
JS_ReportErrorASCII(cx, "%s", msg);
} else {
JSString* str = usage.toString();
if (!str->ensureFlat(cx))

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

@ -622,7 +622,7 @@ ExpandErrorArgumentsVA(ExclusiveContext* cx, JSErrorCallback callback,
/* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
extern void
ReportUsageError(JSContext* cx, HandleObject callee, const char* msg);
ReportUsageErrorASCII(JSContext* cx, HandleObject callee, const char* msg);
/*
* Prints a full report and returns true if the given report is non-nullptr

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

@ -4637,13 +4637,13 @@ WithSourceHook(JSContext* cx, unsigned argc, Value* vp)
RootedObject callee(cx, &args.callee());
if (args.length() != 2) {
ReportUsageError(cx, callee, "Wrong number of arguments.");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments.");
return false;
}
if (!args[0].isObject() || !args[0].toObject().is<JSFunction>()
|| !args[1].isObject() || !args[1].toObject().is<JSFunction>()) {
ReportUsageError(cx, callee, "First and second arguments must be functions.");
ReportUsageErrorASCII(cx, callee, "First and second arguments must be functions.");
return false;
}
@ -5087,12 +5087,12 @@ ReflectTrackedOptimizations(JSContext* cx, unsigned argc, Value* vp)
}
if (args.length() != 1) {
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isObject() || !args[0].toObject().is<JSFunction>()) {
ReportUsageError(cx, callee, "Argument must be a function");
ReportUsageErrorASCII(cx, callee, "Argument must be a function");
return false;
}
@ -5214,14 +5214,14 @@ DumpScopeChain(JSContext* cx, unsigned argc, Value* vp)
RootedObject callee(cx, &args.callee());
if (args.length() != 1) {
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isObject() ||
!(args[0].toObject().is<JSFunction>() || args[0].toObject().is<ModuleObject>()))
{
ReportUsageError(cx, callee, "Argument must be an interpreted function or a module");
ReportUsageErrorASCII(cx, callee, "Argument must be an interpreted function or a module");
return false;
}
@ -5231,7 +5231,7 @@ DumpScopeChain(JSContext* cx, unsigned argc, Value* vp)
if (obj->is<JSFunction>()) {
RootedFunction fun(cx, &obj->as<JSFunction>());
if (!fun->isInterpreted()) {
ReportUsageError(cx, callee, "Argument must be an interpreted function");
ReportUsageErrorASCII(cx, callee, "Argument must be an interpreted function");
return false;
}
script = fun->getOrCreateScript(cx);
@ -5487,19 +5487,19 @@ WasmLoop(JSContext* cx, unsigned argc, Value* vp)
RootedObject callee(cx, &args.callee());
if (args.length() < 1 || args.length() > 2) {
ReportUsageError(cx, callee, "Wrong number of arguments");
ReportUsageErrorASCII(cx, callee, "Wrong number of arguments");
return false;
}
if (!args[0].isString()) {
ReportUsageError(cx, callee, "First argument must be a String");
ReportUsageErrorASCII(cx, callee, "First argument must be a String");
return false;
}
RootedObject importObj(cx);
if (!args.get(1).isUndefined()) {
if (!args.get(1).isObject()) {
ReportUsageError(cx, callee, "Second argument, if present, must be an Object");
ReportUsageErrorASCII(cx, callee, "Second argument, if present, must be an Object");
return false;
}
importObj = &args[1].toObject();

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

@ -1480,7 +1480,7 @@ OptionsBase::ParseBoolean(const char* name, bool* prop)
return true;
if (!value.isBoolean()) {
JS_ReportError(mCx, "Expected a boolean value for property %s", name);
JS_ReportErrorASCII(mCx, "Expected a boolean value for property %s", name);
return false;
}
@ -1503,7 +1503,7 @@ OptionsBase::ParseObject(const char* name, MutableHandleObject prop)
return true;
if (!value.isObject()) {
JS_ReportError(mCx, "Expected an object value for property %s", name);
JS_ReportErrorASCII(mCx, "Expected an object value for property %s", name);
return false;
}
prop.set(&value.toObject());
@ -1525,7 +1525,7 @@ OptionsBase::ParseJSString(const char* name, MutableHandleString prop)
return true;
if (!value.isString()) {
JS_ReportError(mCx, "Expected a string value for property %s", name);
JS_ReportErrorASCII(mCx, "Expected a string value for property %s", name);
return false;
}
prop.set(value.toString());
@ -1547,7 +1547,7 @@ OptionsBase::ParseString(const char* name, nsCString& prop)
return true;
if (!value.isString()) {
JS_ReportError(mCx, "Expected a string value for property %s", name);
JS_ReportErrorASCII(mCx, "Expected a string value for property %s", name);
return false;
}
@ -1573,7 +1573,7 @@ OptionsBase::ParseString(const char* name, nsString& prop)
return true;
if (!value.isString()) {
JS_ReportError(mCx, "Expected a string value for property %s", name);
JS_ReportErrorASCII(mCx, "Expected a string value for property %s", name);
return false;
}
@ -1618,7 +1618,7 @@ OptionsBase::ParseUInt32(const char* name, uint32_t* prop)
return true;
if(!JS::ToUint32(mCx, value, prop)) {
JS_ReportError(mCx, "Expected a uint32_t value for property %s", name);
JS_ReportErrorASCII(mCx, "Expected a uint32_t value for property %s", name);
return false;
}
@ -1661,6 +1661,7 @@ SandboxOptions::ParseGlobalProperties()
bool
SandboxOptions::Parse()
{
/* All option names must be ASCII-only. */
bool ok = ParseObject("sandboxPrototype", &proto) &&
ParseBoolean("wantXrays", &wantXrays) &&
ParseBoolean("allowWaivers", &allowWaivers) &&

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

@ -971,7 +971,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
const char* str = "IDL methods marked with [implicit_jscontext] "
"or [optional_argc] may not be implemented in JS";
// Throw and warn for good measure.
JS_ReportError(cx, str);
JS_ReportErrorASCII(cx, str);
NS_WARNING(str);
return CheckForException(ccx, aes, name, GetInterfaceName());
}

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

@ -271,10 +271,10 @@ AccessCheck::checkPassToPrivilegedCode(JSContext* cx, HandleObject wrapper, cons
enum Access { READ = (1<<0), WRITE = (1<<1), NO_ACCESS = 0 };
static void
EnterAndThrow(JSContext* cx, JSObject* wrapper, const char* msg)
EnterAndThrowASCII(JSContext* cx, JSObject* wrapper, const char* msg)
{
JSAutoCompartment ac(cx, wrapper);
JS_ReportError(cx, msg);
JS_ReportErrorASCII(cx, msg);
}
bool
@ -337,7 +337,7 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
return false;
if (desc.hasGetterOrSetter()) {
EnterAndThrow(cx, wrapper, "__exposedProps__ must be a value property");
EnterAndThrowASCII(cx, wrapper, "__exposedProps__ must be a value property");
return false;
}
@ -346,14 +346,14 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
return false;
if (!exposedProps.isObject()) {
EnterAndThrow(cx, wrapper, "__exposedProps__ must be undefined, null, or an Object");
EnterAndThrowASCII(cx, wrapper, "__exposedProps__ must be undefined, null, or an Object");
return false;
}
RootedObject hallpass(cx, &exposedProps.toObject());
if (!AccessCheck::subsumes(js::UncheckedUnwrap(hallpass), wrappedObject)) {
EnterAndThrow(cx, wrapper, "Invalid __exposedProps__");
EnterAndThrowASCII(cx, wrapper, "Invalid __exposedProps__");
return false;
}
@ -366,7 +366,7 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
return false;
if (!desc.value().isString()) {
EnterAndThrow(cx, wrapper, "property must be a string");
EnterAndThrowASCII(cx, wrapper, "property must be a string");
return false;
}
@ -381,7 +381,7 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
switch (ch) {
case 'r':
if (access & READ) {
EnterAndThrow(cx, wrapper, "duplicate 'readable' property flag");
EnterAndThrowASCII(cx, wrapper, "duplicate 'readable' property flag");
return false;
}
access = Access(access | READ);
@ -389,20 +389,20 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
case 'w':
if (access & WRITE) {
EnterAndThrow(cx, wrapper, "duplicate 'writable' property flag");
EnterAndThrowASCII(cx, wrapper, "duplicate 'writable' property flag");
return false;
}
access = Access(access | WRITE);
break;
default:
EnterAndThrow(cx, wrapper, "properties can only be readable or read and writable");
EnterAndThrowASCII(cx, wrapper, "properties can only be readable or read and writable");
return false;
}
}
if (access == NO_ACCESS) {
EnterAndThrow(cx, wrapper, "specified properties must have a permission bit set");
EnterAndThrowASCII(cx, wrapper, "specified properties must have a permission bit set");
return false;
}
@ -417,7 +417,7 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
// Reject accessor properties.
if (desc.hasGetterOrSetter()) {
EnterAndThrow(cx, wrapper, "Exposing privileged accessor properties is prohibited");
EnterAndThrowASCII(cx, wrapper, "Exposing privileged accessor properties is prohibited");
return false;
}
@ -425,7 +425,7 @@ ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, W
if (desc.value().isObject()) {
RootedObject maybeCallable(cx, js::UncheckedUnwrap(&desc.value().toObject()));
if (JS::IsCallable(maybeCallable) && !AccessCheck::subsumes(wrapper, maybeCallable)) {
EnterAndThrow(cx, wrapper, "Exposing privileged or cross-origin callable is prohibited");
EnterAndThrowASCII(cx, wrapper, "Exposing privileged or cross-origin callable is prohibited");
return false;
}
}