From b7f487b92241f65ba165a018990a98adc074bba3 Mon Sep 17 00:00:00 2001 From: Paul Duguet Date: Sat, 22 Nov 2014 09:07:00 +0100 Subject: [PATCH] Bug 1099149 - Part 2: Add a more specific error message when 'js::ToSimdConstant' argument is of wrong type. r=bbouvier --HG-- extra : rebase_source : b7831885ec947db798e028a33a63fe9e45da8490 --- js/src/builtin/SIMD.cpp | 34 +++++++++++++++++++++++----------- js/src/js.msg | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/js/src/builtin/SIMD.cpp b/js/src/builtin/SIMD.cpp index 37c32ba23cbe..d7a865a9643e 100644 --- a/js/src/builtin/SIMD.cpp +++ b/js/src/builtin/SIMD.cpp @@ -63,15 +63,34 @@ template bool js::IsVectorObject(HandleValue v); template bool js::IsVectorObject(HandleValue v); template bool js::IsVectorObject(HandleValue v); +static inline bool +ErrorBadArgs(JSContext* cx) +{ + JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS); + return false; +} + +static inline bool +ErrorWrongTypeArg(JSContext* cx, size_t argIndex, Handle typeDescr) +{ + MOZ_ASSERT(argIndex < 10); + char charArgIndex[2]; + JS_snprintf(charArgIndex, sizeof charArgIndex, "%d", argIndex); + + HeapSlot& typeNameSlot = typeDescr->getReservedSlotRef(JS_DESCR_SLOT_STRING_REPR); + JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_SIMD_NOT_A_VECTOR, + JS_EncodeString(cx, typeNameSlot.toString()), charArgIndex); + return false; +} + template bool js::ToSimdConstant(JSContext* cx, HandleValue v, jit::SimdConstant* out) { typedef typename V::Elem Elem; - if (!IsVectorObject(v)) { - JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_SIMD_NOT_A_VECTOR); - return false; - } + Rooted typeDescr(cx, &V::GetTypeDescr(*cx->global())); + if (!IsVectorObject(v)) + return ErrorWrongTypeArg(cx, 1, typeDescr); Elem* mem = reinterpret_cast(v.toObject().as().typedMem()); *out = jit::SimdConstant::CreateX4(mem); @@ -622,13 +641,6 @@ struct ShiftRightLogical { }; } -static inline bool -ErrorBadArgs(JSContext* cx) -{ - JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS); - return false; -} - template static bool StoreResult(JSContext* cx, CallArgs& args, typename Out::Elem* result) diff --git a/js/src/js.msg b/js/src/js.msg index e863b30d7546..7e31955acd13 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -309,7 +309,7 @@ MSG_DEF(JSMSG_STRICT_CODE_LET_EXPR_STMT, 0, JSEXN_ERR, "strict mode code may not MSG_DEF(JSMSG_STRICT_CODE_WITH, 0, JSEXN_SYNTAXERR, "strict mode code may not contain 'with' statements") MSG_DEF(JSMSG_STRICT_FUNCTION_STATEMENT, 0, JSEXN_SYNTAXERR, "in strict mode code, functions may be declared only at top level or immediately within another function") MSG_DEF(JSMSG_TEMPLSTR_UNTERM_EXPR, 0, JSEXN_SYNTAXERR, "missing } in template string") -MSG_DEF(JSMSG_SIMD_NOT_A_VECTOR, 0, JSEXN_TYPEERR, "value isn't a SIMD value object") +MSG_DEF(JSMSG_SIMD_NOT_A_VECTOR, 2, JSEXN_TYPEERR, "expecting a SIMD {0} object as argument {1}") MSG_DEF(JSMSG_TOO_MANY_CASES, 0, JSEXN_INTERNALERR, "too many switch cases") MSG_DEF(JSMSG_TOO_MANY_CATCH_VARS, 0, JSEXN_SYNTAXERR, "too many catch variables") MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 0, JSEXN_SYNTAXERR, "too many constructor arguments")