Bug 353116 - ""has no properties" is misleading and should be replaced with "is null or undefined"" [p=rich@rd.gen.nz (Rich Dougherty) r=brendan r=crowder a1.9=damons]

This commit is contained in:
reed@reedloden.com 2007-11-12 21:23:22 -08:00
Родитель 2a994e105b
Коммит 62253eed3a
5 изменённых файлов: 45 добавлений и 6 удалений

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

@ -301,3 +301,4 @@ MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 218, 0, JSEXN_TYPEERR, "reduce of empty ar
MSG_DEF(JSMSG_NON_LIST_XML_METHOD, 219, 2, JSEXN_TYPEERR, "cannot call {0} method on an XML list with {1} elements")
MSG_DEF(JSMSG_BAD_DELETE_OPERAND, 220, 0, JSEXN_SYNTAXERR, "invalid delete operand")
MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 221, 0, JSEXN_SYNTAXERR, "invalid increment/decrement operand")
MSG_DEF(JSMSG_NULL_OR_UNDEFINED, 222, 2, JSEXN_TYPEERR, "{0} is {1}")

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

@ -1218,6 +1218,40 @@ js_ReportIsNotDefined(JSContext *cx, const char *name)
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_DEFINED, name);
}
JSBool
js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, jsval v,
JSString *fallback)
{
char *bytes;
JSBool ok;
bytes = js_DecompileValueGenerator(cx, spindex, v, fallback);
if (!bytes)
return JS_FALSE;
if (strcmp(bytes, js_undefined_str) == 0 ||
strcmp(bytes, js_null_str) == 0) {
ok = JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR,
js_GetErrorMessage, NULL,
JSMSG_NO_PROPERTIES, bytes,
NULL, NULL);
} else if (JSVAL_IS_VOID(v)) {
ok = JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR,
js_GetErrorMessage, NULL,
JSMSG_NULL_OR_UNDEFINED, bytes,
js_undefined_str, NULL);
} else {
JS_ASSERT(JSVAL_IS_NULL(v));
ok = JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR,
js_GetErrorMessage, NULL,
JSMSG_NULL_OR_UNDEFINED, bytes,
js_null_str, NULL);
}
JS_free(cx, bytes);
return ok;
}
JSBool
js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
intN spindex, jsval v, JSString *fallback,

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

@ -977,6 +977,13 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
extern void
js_ReportIsNotDefined(JSContext *cx, const char *name);
/*
* Report an attempt to access the property of a null or undefined value (v).
*/
extern JSBool
js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, jsval v,
JSString *fallback);
/*
* Report error using js_DecompileValueGenerator(cx, spindex, v, fallback) as
* the first argument for the error message. If the error message has less

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

@ -5852,8 +5852,7 @@ interrupt:
i = JSProto_Boolean;
} else {
JS_ASSERT(JSVAL_IS_NULL(lval) || JSVAL_IS_VOID(lval));
js_ReportValueError(cx, JSMSG_NO_PROPERTIES, -2, lval,
NULL);
js_ReportIsNullOrUndefined(cx, -2, lval, NULL);
ok = JS_FALSE;
goto out;
}

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

@ -4651,10 +4651,8 @@ js_ValueToNonNullObject(JSContext *cx, jsval v)
if (!js_ValueToObject(cx, v, &obj))
return NULL;
if (!obj) {
js_ReportValueError(cx, JSMSG_NO_PROPERTIES,
JSDVG_SEARCH_STACK, v, NULL);
}
if (!obj)
js_ReportIsNullOrUndefined(cx, JSDVG_SEARCH_STACK, v, NULL);
return obj;
}