Fix toSource on exception objects so it uses toSource to generate properly-quoted, embedded string literals for message and filename (bug 96284, r=jband, sr=shaver, a=asa).

This commit is contained in:
brendan%mozilla.org 2001-09-03 19:36:24 +00:00
Родитель e96fdf8569
Коммит bbc01b505e
1 изменённых файлов: 22 добавлений и 29 удалений

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

@ -348,7 +348,7 @@ Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, JSVAL_NULL);
/* Set the 'message' property. */
if (argc > 0) {
if (argc != 0) {
message = js_ValueToString(cx, argv[0]);
if (!message)
return JS_FALSE;
@ -414,7 +414,7 @@ exn_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_FALSE;
}
if (message->length > 0) {
if (message->length != 0) {
length = name->length + message->length + 2;
cp = chars = (jschar*) JS_malloc(cx, (length + 1) * sizeof(jschar));
if (!chars)
@ -460,12 +460,12 @@ exn_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_FALSE;
if (!JS_GetProperty(cx, obj, js_message_str, &v) ||
!(message = js_ValueToString(cx, v))) {
!(message = js_ValueToSource(cx, v))) {
return JS_FALSE;
}
if (!JS_GetProperty(cx, obj, js_filename_str, &v) ||
!(filename = js_ValueToString(cx, v))) {
!(filename = js_ValueToSource(cx, v))) {
return JS_FALSE;
}
@ -482,12 +482,12 @@ exn_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
lineno_as_str = NULL;
}
length = (message->length > 0) ? name->length + message->length + 10
: name->length + 8;
/* Magic 8, for the characters in ``(new ())''. */
length = 8 + name->length + message->length;
if (filename->length > 0) {
/* append filename as ``, "{filename}"'' */
length += 4 + filename->length;
if (filename->length != 0) {
/* append filename as ``, {filename}'' */
length += 2 + filename->length;
if (lineno_as_str) {
/* append lineno as ``, {lineno_as_str}'' */
length += 2 + lineno_as_str->length;
@ -510,19 +510,16 @@ exn_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
js_strncpy(cp, name->chars, name->length);
cp += name->length;
*cp++ = '(';
if (message->length > 0) {
*cp++ = '"';
if (message->length != 0) {
js_strncpy(cp, message->chars, message->length);
cp += message->length;
*cp++ = '"';
}
if (filename->length > 0) {
/* append filename as ``, "{filename}"'' */
*cp++ = ','; *cp++ = ' '; *cp++ = '"';
if (filename->length != 0) {
/* append filename as ``, {filename}'' */
*cp++ = ','; *cp++ = ' ';
js_strncpy(cp, filename->chars, filename->length);
cp += filename->length;
*cp++ = '"';
if (lineno_as_str) {
/* append lineno as ``, {lineno_as_str}'' */
*cp++ = ','; *cp++ = ' ';
@ -549,10 +546,6 @@ exn_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JS_free(cx, chars);
return JS_FALSE;
}
result = js_QuoteString(cx, result, '"');
if (!result)
return JS_FALSE;
*rval = STRING_TO_JSVAL(result);
return JS_TRUE;
}