Avoid recursive death in exn_toString (260541, r=shaver).

This commit is contained in:
brendan%mozilla.org 2004-09-21 01:18:00 +00:00
Родитель 353221b100
Коммит 0c6b237ee3
1 изменённых файлов: 12 добавлений и 10 удалений

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

@ -575,6 +575,7 @@ Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ok = JS_FALSE;
goto out;
}
argv[0] = STRING_TO_JSVAL(message);
} else {
message = cx->runtime->emptyString;
}
@ -586,6 +587,7 @@ Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ok = JS_FALSE;
goto out;
}
argv[1] = STRING_TO_JSVAL(filename);
} else {
filename = cx->runtime->emptyString;
}
@ -623,26 +625,26 @@ exn_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (!OBJ_GET_PROPERTY(cx, obj, (jsid)cx->runtime->atomState.nameAtom, &v))
return JS_FALSE;
name = js_ValueToString(cx, v);
if (!name)
return JS_FALSE;
name = JSVAL_IS_STRING(v) ? JSVAL_TO_STRING(v) : cx->runtime->emptyString;
if (!JS_GetProperty(cx, obj, js_message_str, &v) ||
!(message = js_ValueToString(cx, v))) {
if (!JS_GetProperty(cx, obj, js_message_str, &v))
return JS_FALSE;
}
message = JSVAL_IS_STRING(v) ? JSVAL_TO_STRING(v)
: cx->runtime->emptyString;
if (JSSTRING_LENGTH(message) != 0) {
name_length = JSSTRING_LENGTH(name);
message_length = JSSTRING_LENGTH(message);
length = name_length + message_length + 2;
length = (name_length ? name_length + 2 : 0) + message_length;
cp = chars = (jschar*) JS_malloc(cx, (length + 1) * sizeof(jschar));
if (!chars)
return JS_FALSE;
js_strncpy(cp, JSSTRING_CHARS(name), name_length);
cp += name_length;
*cp++ = ':'; *cp++ = ' ';
if (name_length) {
js_strncpy(cp, JSSTRING_CHARS(name), name_length);
cp += name_length;
*cp++ = ':'; *cp++ = ' ';
}
js_strncpy(cp, JSSTRING_CHARS(message), message_length);
cp += message_length;
*cp = 0;