Bug 36680: new function to report error using decompiled jsval text. r=brendan

git-svn-id: svn://10.0.0.236/trunk@218666 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
igor.bukanov%gmail.com 2007-01-19 08:37:55 +00:00
parent d6df457a7d
commit cae329a112
10 changed files with 156 additions and 201 deletions

View File

@ -1205,6 +1205,26 @@ js_ReportIsNotDefined(JSContext *cx, const char *name)
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_DEFINED, name);
}
JSBool
js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
intN spindex, jsval v, JSString *fallback,
const char *arg1, const char *arg2)
{
char *bytes;
JSBool ok;
JS_ASSERT(js_ErrorFormatString[errorNumber].argCount >= 1);
JS_ASSERT(js_ErrorFormatString[errorNumber].argCount <= 3);
bytes = js_DecompileValueGenerator(cx, spindex, v, fallback);
if (!bytes)
return JS_FALSE;
ok = JS_ReportErrorFlagsAndNumber(cx, flags, js_GetErrorMessage,
NULL, errorNumber, bytes, arg1, arg2);
JS_free(cx, bytes);
return ok;
}
#if defined DEBUG && defined XP_UNIX
/* For gdb usage. */
void js_traceon(JSContext *cx) { cx->tracefp = stderr; }

View File

@ -982,6 +982,28 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
extern void
js_ReportIsNotDefined(JSContext *cx, const char *name);
/*
* Report error using js_DecompileValueGenerator(cx, spindex, v, fallback) as
* the first argument for the error message. If the error message has less
* then 3 arguments, use null for arg1 or arg2.
*/
extern JSBool
js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
intN spindex, jsval v, JSString *fallback,
const char *arg1, const char *arg2);
#define js_ReportValueError(cx,errorNumber,spindex,v,fallback) \
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
spindex, v, fallback, NULL, NULL))
#define js_ReportValueError2(cx,errorNumber,spindex,v,fallback,arg1) \
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
spindex, v, fallback, arg1, NULL))
#define js_ReportValueError3(cx,errorNumber,spindex,v,fallback,arg1,arg2) \
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
spindex, v, fallback, arg1, arg2))
extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
/*

View File

@ -1417,7 +1417,6 @@ static JSBool
fun_hasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
{
jsval pval;
JSString *str;
if (!OBJ_GET_PROPERTY(cx, obj,
ATOM_TO_JSID(cx->runtime->atomState
@ -1431,11 +1430,8 @@ fun_hasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
* Throw a runtime error if instanceof is called on a function that
* has a non-object as its .prototype value.
*/
str = js_DecompileValueGenerator(cx, -1, OBJECT_TO_JSVAL(obj), NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_PROTOTYPE, JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_BAD_PROTOTYPE,
-1, OBJECT_TO_JSVAL(obj), NULL);
return JS_FALSE;
}
@ -2297,37 +2293,31 @@ void
js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags)
{
JSStackFrame *fp;
JSString *str;
JSTempValueRooter tvr;
const char *bytes, *source;
uintN error;
const char *name, *source;
for (fp = cx->fp; fp && !fp->spbase; fp = fp->down)
continue;
str = js_DecompileValueGenerator(cx,
(fp && fp->spbase <= vp && vp < fp->sp)
? vp - fp->sp
: (flags & JSV2F_SEARCH_STACK)
? JSDVG_SEARCH_STACK
: JSDVG_IGNORE_STACK,
*vp,
NULL);
if (str) {
JS_PUSH_TEMP_ROOT_STRING(cx, str, &tvr);
bytes = JS_GetStringBytes(str);
if (flags & JSV2F_ITERATOR) {
source = js_ValueToPrintableSource(cx, *vp);
if (source) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_ITERATOR,
bytes, js_iterator_str, source);
}
} else {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
(uintN)((flags & JSV2F_CONSTRUCT)
? JSMSG_NOT_CONSTRUCTOR
: JSMSG_NOT_FUNCTION),
bytes);
}
JS_POP_TEMP_ROOT(cx, &tvr);
name = NULL;
source = NULL;
if (flags & JSV2F_ITERATOR) {
error = JSMSG_BAD_ITERATOR;
name = js_iterator_str;
source = js_ValueToPrintableSource(cx, *vp);
if (!source)
return;
} else if (flags & JSV2F_CONSTRUCT) {
error = JSMSG_NOT_CONSTRUCTOR;
} else {
error = JSMSG_NOT_FUNCTION;
}
js_ReportValueError3(cx, error,
(fp && fp->spbase <= vp && vp < fp->sp)
? vp - fp->sp
: (flags & JSV2F_SEARCH_STACK)
? JSDVG_SEARCH_STACK
: JSDVG_IGNORE_STACK,
*vp, NULL,
name, source);
}

View File

@ -1636,7 +1636,6 @@ ImportProperty(JSContext *cx, JSObject *obj, jsid id)
JSIdArray *ida;
JSProperty *prop;
JSObject *obj2, *target, *funobj, *closure;
JSString *str;
uintN attrs;
jsint i;
jsval value;
@ -1653,10 +1652,8 @@ ImportProperty(JSContext *cx, JSObject *obj, jsid id)
if (!OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop))
return JS_FALSE;
if (!prop) {
str = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK,
ID_TO_VALUE(id), NULL);
if (str)
js_ReportIsNotDefined(cx, JS_GetStringBytes(str));
js_ReportValueError(cx, JSMSG_NOT_DEFINED,
JSDVG_IGNORE_STACK, ID_TO_VALUE(id), NULL);
return JS_FALSE;
}
ok = OBJ_GET_ATTRIBUTES(cx, obj, id, prop, &attrs);
@ -1664,13 +1661,8 @@ ImportProperty(JSContext *cx, JSObject *obj, jsid id)
if (!ok)
return JS_FALSE;
if (!(attrs & JSPROP_EXPORTED)) {
str = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK,
ID_TO_VALUE(id), NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_NOT_EXPORTED,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_NOT_EXPORTED,
JSDVG_IGNORE_STACK, ID_TO_VALUE(id), NULL);
return JS_FALSE;
}
}
@ -2421,11 +2413,13 @@ interrupt:
if (nuses) {
SAVE_SP_AND_PC(fp);
for (n = -nuses; n < 0; n++) {
str = js_DecompileValueGenerator(cx, n, sp[n], NULL);
if (str) {
char *bytes = js_DecompileValueGenerator(cx, n, sp[n],
NULL);
if (bytes) {
fprintf(tracefp, "%s %s",
(n == -nuses) ? " inputs:" : ",",
JS_GetStringBytes(str));
bytes);
JS_free(cx, bytes);
}
}
fprintf(tracefp, " @ %d\n", sp - fp->spbase);
@ -2727,12 +2721,7 @@ interrupt:
SAVE_SP_AND_PC(fp);
rval = FETCH_OPND(-1);
if (JSVAL_IS_PRIMITIVE(rval)) {
str = js_DecompileValueGenerator(cx, -1, rval, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_IN_NOT_OBJECT,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_IN_NOT_OBJECT, -1, rval, NULL);
ok = JS_FALSE;
goto out;
}
@ -5458,12 +5447,8 @@ interrupt:
rval = FETCH_OPND(-1);
if (JSVAL_IS_PRIMITIVE(rval) ||
!(obj = JSVAL_TO_OBJECT(rval))->map->ops->hasInstance) {
str = js_DecompileValueGenerator(cx, -1, rval, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_INSTANCEOF_RHS,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_BAD_INSTANCEOF_RHS,
-1, rval, NULL);
ok = JS_FALSE;
goto out;
}
@ -5794,13 +5779,8 @@ interrupt:
i = JSProto_Boolean;
} else {
JS_ASSERT(JSVAL_IS_NULL(lval) || JSVAL_IS_VOID(lval));
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK,
lval, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_NO_PROPERTIES,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_NO_PROPERTIES,
JSDVG_SEARCH_STACK, lval, NULL);
ok = JS_FALSE;
goto out;
}
@ -6015,13 +5995,8 @@ interrupt:
goto out;
}
if (FRAME_TO_GENERATOR(fp)->state == JSGEN_CLOSING) {
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK,
fp->argv[-2], NULL);
if (str) {
JS_ReportErrorNumberUC(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_GENERATOR_YIELD,
JSSTRING_CHARS(str));
}
js_ReportValueError(cx, JSMSG_BAD_GENERATOR_YIELD,
JSDVG_SEARCH_STACK, fp->argv[-2], NULL);
ok = JS_FALSE;
goto out;
}
@ -6096,11 +6071,13 @@ interrupt:
if (op == JSOP_FORELEM && sp[-1] == JSVAL_FALSE)
--ndefs;
for (n = -ndefs; n < 0; n++) {
str = js_DecompileValueGenerator(cx, n, sp[n], NULL);
if (str) {
char *bytes = js_DecompileValueGenerator(cx, n, sp[n],
NULL);
if (bytes) {
fprintf(tracefp, "%s %s",
(n == -ndefs) ? " output:" : ",",
JS_GetStringBytes(str));
bytes);
JS_free(cx, bytes);
}
}
fprintf(tracefp, " @ %d\n", sp - fp->spbase);

View File

@ -347,11 +347,10 @@ js_ValueToIterator(JSContext *cx, uintN flags, jsval *vp)
{
JSObject *obj;
JSTempValueRooter tvr;
const JSAtom *atom;
JSAtom *atom;
JSBool ok;
JSObject *iterobj;
jsval arg;
JSString *str;
JS_ASSERT(!(flags & ~(JSITER_ENUMERATE |
JSITER_FOREACH |
@ -420,12 +419,10 @@ js_ValueToIterator(JSContext *cx, uintN flags, jsval *vp)
if (!js_InternalInvoke(cx, obj, *vp, JSINVOKE_ITERATOR, 1, &arg, vp))
goto bad;
if (JSVAL_IS_PRIMITIVE(*vp)) {
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, *vp, NULL);
if (str) {
JS_ReportErrorNumberUC(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_ITERATOR_RETURN,
JSSTRING_CHARS(str),
JSSTRING_CHARS(ATOM_TO_STRING(atom)));
const char *printable = js_AtomToPrintableString(cx, atom);
if (printable) {
js_ReportValueError2(cx, JSMSG_BAD_ITERATOR_RETURN,
JSDVG_SEARCH_STACK, *vp, NULL, printable);
}
goto bad;
}
@ -928,7 +925,6 @@ generator_op(JSContext *cx, JSGeneratorOp op,
JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSGenerator *gen;
JSString *str;
jsval arg;
if (!JS_InstanceOf(cx, obj, &js_GeneratorClass, argv))
@ -949,13 +945,8 @@ generator_op(JSContext *cx, JSGeneratorOp op,
case JSGENOP_SEND:
if (!JSVAL_IS_VOID(argv[0])) {
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK,
argv[0], NULL);
if (str) {
JS_ReportErrorNumberUC(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_GENERATOR_SEND,
JSSTRING_CHARS(str));
}
js_ReportValueError(cx, JSMSG_BAD_GENERATOR_SEND,
JSDVG_SEARCH_STACK, argv[0], NULL);
return JS_FALSE;
}
break;
@ -972,13 +963,9 @@ generator_op(JSContext *cx, JSGeneratorOp op,
case JSGEN_RUNNING:
case JSGEN_CLOSING:
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, argv[-1],
JS_GetFunctionId(gen->frame.fun));
if (str) {
JS_ReportErrorNumberUC(cx, js_GetErrorMessage, NULL,
JSMSG_NESTING_GENERATOR,
JSSTRING_CHARS(str));
}
js_ReportValueError(cx, JSMSG_NESTING_GENERATOR,
JSDVG_SEARCH_STACK, argv[-1],
JS_GetFunctionId(gen->frame.fun));
return JS_FALSE;
default:

View File

@ -831,7 +831,6 @@ JSBool
js_ValueToInt32(JSContext *cx, jsval v, int32 *ip)
{
jsdouble d;
JSString *str;
if (JSVAL_IS_INT(v)) {
*ip = JSVAL_TO_INT(v);
@ -840,12 +839,8 @@ js_ValueToInt32(JSContext *cx, jsval v, int32 *ip)
if (!js_ValueToNumber(cx, v, &d))
return JS_FALSE;
if (JSDOUBLE_IS_NaN(d) || d <= -2147483649.0 || 2147483648.0 <= d) {
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, v, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_CANT_CONVERT, JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_CANT_CONVERT,
JSDVG_SEARCH_STACK, v, NULL);
return JS_FALSE;
}
*ip = (int32)floor(d + 0.5); /* Round to nearest */

View File

@ -3526,7 +3526,6 @@ js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
if (JSVAL_IS_VOID(*vp) && cx->fp && (pc = cx->fp->pc)) {
JSOp op;
uintN flags;
JSString *str;
op = *pc;
if (op == JSOP_GETXPROP) {
@ -3554,13 +3553,9 @@ js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
}
/* Ok, bad undefined property reference: whine about it. */
str = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK,
ID_TO_VALUE(id), NULL);
if (!str ||
!JS_ReportErrorFlagsAndNumber(cx, flags,
js_GetErrorMessage, NULL,
JSMSG_UNDEFINED_PROP,
JS_GetStringBytes(str))) {
if (!js_ReportValueErrorFlags(cx, flags, JSMSG_UNDEFINED_PROP,
JSDVG_IGNORE_STACK, ID_TO_VALUE(id),
NULL, NULL, NULL)) {
return JS_FALSE;
}
}
@ -3744,17 +3739,10 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
JS_UNLOCK_SCOPE(cx, scope);
return JS_TRUE;
read_only_error: {
JSString *str = js_DecompileValueGenerator(cx,
JSDVG_IGNORE_STACK,
ID_TO_VALUE(id),
NULL);
if (!str)
return JS_FALSE;
return JS_ReportErrorFlagsAndNumberUC(cx, flags, js_GetErrorMessage,
NULL, JSMSG_READ_ONLY,
JS_GetStringChars(str));
}
read_only_error:
return js_ReportValueErrorFlags(cx, flags, JSMSG_READ_ONLY,
JSDVG_IGNORE_STACK, ID_TO_VALUE(id), NULL,
NULL, NULL);
}
JSBool
@ -3923,7 +3911,7 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
break;
}
if (!JSVAL_IS_PRIMITIVE(v)) {
/* Avoid recursive death through js_DecompileValueGenerator. */
/* Avoid recursive death when decompiling in js_ReportValueError. */
if (hint == JSTYPE_STRING) {
str = JS_InternString(cx, OBJ_GET_CLASS(cx, obj)->name);
if (!str)
@ -3932,15 +3920,11 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
str = NULL;
}
*vp = OBJECT_TO_JSVAL(obj);
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, save, str);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_CANT_CONVERT_TO,
JS_GetStringBytes(str),
(hint == JSTYPE_VOID)
? "primitive type"
: js_type_strs[hint]);
}
js_ReportValueError2(cx, JSMSG_CANT_CONVERT_TO,
JSDVG_SEARCH_STACK, save, str,
(hint == JSTYPE_VOID)
? "primitive type"
: js_type_strs[hint]);
return JS_FALSE;
}
out:
@ -4367,7 +4351,6 @@ JSBool
js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
{
JSClass *clasp;
JSString *str;
clasp = OBJ_GET_CLASS(cx, obj);
if (clasp->hasInstance)
@ -4388,13 +4371,8 @@ js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
}
}
#endif
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK,
OBJECT_TO_JSVAL(obj), NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_INSTANCEOF_RHS,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_BAD_INSTANCEOF_RHS,
JSDVG_SEARCH_STACK, OBJECT_TO_JSVAL(obj), NULL);
return JS_FALSE;
}
@ -4555,16 +4533,12 @@ JSObject *
js_ValueToNonNullObject(JSContext *cx, jsval v)
{
JSObject *obj;
JSString *str;
if (!js_ValueToObject(cx, v, &obj))
return NULL;
if (!obj) {
str = js_DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, v, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_NO_PROPERTIES, JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_NO_PROPERTIES,
JSDVG_SEARCH_STACK, v, NULL);
}
return obj;
}

View File

@ -782,7 +782,7 @@ static ptrdiff_t
GetOff(SprintStack *ss, uintN i)
{
ptrdiff_t off;
JSString *str;
char *bytes;
off = ss->offsets[i];
if (off < 0) {
@ -795,14 +795,15 @@ GetOff(SprintStack *ss, uintN i)
return 0;
}
str = js_DecompileValueGenerator(ss->sprinter.context, off,
JSVAL_NULL, NULL);
if (!str)
bytes = js_DecompileValueGenerator(ss->sprinter.context, off,
JSVAL_NULL, NULL);
if (!bytes)
return 0;
off = SprintCString(&ss->sprinter, JS_GetStringBytes(str));
off = SprintCString(&ss->sprinter, bytes);
if (off < 0)
off = 0;
ss->offsets[i] = off;
JS_free(ss->sprinter.context, bytes);
}
return off;
}
@ -4408,7 +4409,7 @@ js_DecompileFunction(JSPrinter *jp, JSFunction *fun)
#undef LOCAL_ASSERT_RV
JSString *
char *
js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
JSString *fallback)
{
@ -4422,7 +4423,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
jssrcnote *sn;
ptrdiff_t len, oplen;
JSPrinter *jp;
JSString *name;
char *name;
for (fp = cx->fp; fp && !fp->script; fp = fp->down)
continue;
@ -4554,7 +4555,7 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
* its keyword name instead.
*/
if (op == JSOP_THIS)
return JS_NewStringCopyZ(cx, js_this_str);
return JS_strdup(cx, js_this_str);
/*
* JSOP_BINDNAME is special: it generates a value, the base object of a
@ -4737,12 +4738,20 @@ js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
jp->scope = OBJ_SCOPE(fp->fun->object);
}
jp->dvgfence = end;
if (js_DecompileCode(jp, script, begin, (uintN)len, (uintN)pcdepth))
name = js_GetPrinterOutput(jp);
if (js_DecompileCode(jp, script, begin, (uintN)len, (uintN)pcdepth)) {
name = (jp->sprinter.base) ? jp->sprinter.base : "";
name = JS_strdup(cx, name);
}
js_DestroyPrinter(jp);
}
return name;
do_fallback:
return fallback ? fallback : js_ValueToSource(cx, v);
if (!fallback) {
fallback = js_ValueToSource(cx, v);
if (!fallback)
return NULL;
}
return js_DeflateString(cx, JSSTRING_CHARS(fallback),
JSSTRING_LENGTH(fallback));
}

View File

@ -307,16 +307,18 @@ extern JSBool
js_DecompileFunction(JSPrinter *jp, JSFunction *fun);
/*
* Find the source expression that resulted in v, and return a new string
* containing it. Fall back on v's string conversion (fallback) if we can't
* find the bytecode that generated and pushed v on the operand stack.
* Find the source expression that resulted in v, and return a newly allocated
* C-string containing it. Fall back on v's string conversion (fallback) if we
* can't find the bytecode that generated and pushed v on the operand stack.
*
* Search the current stack frame if spindex is JSDVG_SEARCH_STACK. Don't
* look for v on the stack if spindex is JSDVG_IGNORE_STACK. Otherwise,
* spindex is the negative index of v, measured from cx->fp->sp, or from a
* lower frame's sp if cx->fp is native.
*
* The caller must call JS_free on the result after a succsesful call.
*/
extern JSString *
extern char *
js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
JSString *fallback);

View File

@ -2138,12 +2138,8 @@ ToXML(JSContext *cx, jsval v)
return obj;
bad:
str = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK, v, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_XML_CONVERSION,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_BAD_XML_CONVERSION,
JSDVG_IGNORE_STACK, v, NULL);
return NULL;
}
@ -2224,12 +2220,8 @@ ToXMLList(JSContext *cx, jsval v)
return listobj;
bad:
str = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK, v, NULL);
if (str) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_XMLLIST_CONVERSION,
JS_GetStringBytes(str));
}
js_ReportValueError(cx, JSMSG_BAD_XMLLIST_CONVERSION,
JSDVG_IGNORE_STACK, v, NULL);
return NULL;
}
@ -3073,12 +3065,8 @@ ToAttributeName(JSContext *cx, jsval v)
uri = prefix = cx->runtime->emptyString;
} else {
if (JSVAL_IS_PRIMITIVE(v)) {
name = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK, v, NULL);
if (name) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_XML_ATTR_NAME,
JS_GetStringBytes(name));
}
js_ReportValueError(cx, JSMSG_BAD_XML_ATTR_NAME,
JSDVG_IGNORE_STACK, v, NULL);
return NULL;
}
@ -3116,6 +3104,12 @@ ToAttributeName(JSContext *cx, jsval v)
return qn;
}
static void
ReportBadXMLName(JSContext *cx, jsval id)
{
js_ReportValueError(cx, JSMSG_BAD_XML_NAME, JSDVG_IGNORE_STACK, id, NULL);
}
static JSXMLQName *
ToXMLName(JSContext *cx, jsval v, jsid *funidp)
{
@ -3130,9 +3124,7 @@ ToXMLName(JSContext *cx, jsval v, jsid *funidp)
name = JSVAL_TO_STRING(v);
} else {
if (JSVAL_IS_PRIMITIVE(v)) {
name = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK, v, NULL);
if (name)
goto bad;
ReportBadXMLName(cx, v);
return NULL;
}
@ -3455,19 +3447,6 @@ out:
return copy;
}
static void
ReportBadXMLName(JSContext *cx, jsval id)
{
JSString *name;
name = js_DecompileValueGenerator(cx, JSDVG_IGNORE_STACK, id, NULL);
if (name) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_XML_NAME,
JS_GetStringBytes(name));
}
}
/* ECMA-357 9.1.1.4 XML [[DeleteByIndex]]. */
static JSBool
DeleteByIndex(JSContext *cx, JSXML *xml, jsval id, jsval *vp)