- report function name, if any, when warning about mismatched return

- change catchguard syntax to avoid ECMA conflict
- light XDR cleanup
This commit is contained in:
shaver%netscape.com 1999-11-24 03:36:25 +00:00
Родитель fb135d43ef
Коммит 1e29947595
3 изменённых файлов: 43 добавлений и 17 удалений

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

@ -182,7 +182,7 @@ MSG_DEF(JSMSG_COLON_AFTER_ID, 106, 0, JSEXN_SYNTAXERR, "missing : after
MSG_DEF(JSMSG_CURLY_AFTER_LIST, 107, 0, JSEXN_SYNTAXERR, "missing } after property list")
MSG_DEF(JSMSG_PAREN_IN_PAREN, 108, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical")
MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 109, 0, JSEXN_SYNTAXERR, "missing ; before statement")
MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 0, JSEXN_TYPEERR, "function does not always return a value")
MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 1, JSEXN_TYPEERR, "function {0} does not always return a value")
MSG_DEF(JSMSG_DUPLICATE_FORMAL, 111, 1, JSEXN_TYPEERR, "duplicate formal argument {0}")
MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 112, 1, JSEXN_NONE, "test for equality (==) mistyped as assignment (=)?{0}")
MSG_DEF(JSMSG_BAD_IMPORT, 113, 0, JSEXN_SYNTAXERR, "invalid import expression")
@ -229,3 +229,4 @@ MSG_DEF(JSMSG_CANT_DESCRIBE_PROPS, 153, 1, JSEXN_NONE, "can't describe non-na
MSG_DEF(JSMSG_BAD_APPLY_ARGS, 154, 0, JSEXN_TYPEERR, "second argument to Function.prototype.apply must be an array")
MSG_DEF(JSMSG_REDECLARED_VAR, 155, 2, JSEXN_TYPEERR, "redeclaration of {0} {1}")
MSG_DEF(JSMSG_UNDECLARED_VAR, 156, 1, JSEXN_TYPEERR, "assignment to undeclared variable {0}")
MSG_DEF(JSMSG_ANON_NO_RETURN_VALUE, 157, 0, JSEXN_TYPEERR, "anonymous function does not always return a value")

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

@ -371,8 +371,14 @@ FunctionBody(JSContext *cx, JSTokenStream *ts, JSFunction *fun,
/* Check for falling off the end of a function that returns a value. */
if (pn && JS_HAS_STRICT_OPTION(cx) && (tc->flags & TCF_RETURN_EXPR)) {
if (!CheckFinalReturn(pn)) {
js_ReportCompileErrorNumber(cx, ts, JSREPORT_ERROR,
JSMSG_NO_RETURN_VALUE);
if (fun->atom) {
char *name = js_GetStringBytes(ATOM_TO_STRING(fun->atom));
js_ReportCompileErrorNumber(cx, ts, JSREPORT_ERROR,
JSMSG_NO_RETURN_VALUE, name);
} else {
js_ReportCompileErrorNumber(cx, ts, JSREPORT_ERROR,
JSMSG_ANON_NO_RETURN_VALUE);
}
pn = NULL;
}
}
@ -1155,8 +1161,12 @@ Statement(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
pn3->pn_atom = CURRENT_TOKEN(ts).t_atom;
pn3->pn_expr = NULL;
#if JS_HAS_CATCH_GUARD
if (js_PeekToken(cx, ts) == TOK_COLON) {
(void)js_GetToken(cx, ts); /* eat `:' */
/*
* We use `catch (x if x === 5)' (not `catch (x : x === 5)') to
* avoid conflicting with the JS2/ECMA2 proposed catchguard syntax.
*/
if (js_PeekToken(cx, ts) == TOK_IF) {
(void)js_GetToken(cx, ts); /* eat `if' */
pn3->pn_expr = Expr(cx, ts, tc);
if (!pn3->pn_expr)
return NULL;
@ -1369,8 +1379,25 @@ Statement(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
if (JS_HAS_STRICT_OPTION(cx) &&
(tc->flags & (TCF_RETURN_EXPR | TCF_RETURN_VOID)) ==
(TCF_RETURN_EXPR | TCF_RETURN_VOID)) {
js_ReportCompileErrorNumber(cx, ts, JSREPORT_ERROR,
JSMSG_NO_RETURN_VALUE);
JSStackFrame *fp = cx->fp;
JSFunction *fun;
while (fp && !(fun = fp->fun))
fp = fp->down;
/*
* We must first find a frame with a non-native function, because
* we're compiling one. We test against non-null fp above so that
* we actually trip this assertion if something goes horribly wrong.
*/
JS_ASSERT(fp && fun && !fun->call);
if (fun->atom) {
char *name = js_GetStringBytes(ATOM_TO_STRING(fun->atom));
js_ReportCompileErrorNumber(cx, ts, JSREPORT_ERROR,
JSMSG_NO_RETURN_VALUE, name);
} else {
js_ReportCompileErrorNumber(cx, ts, JSREPORT_ERROR,
JSMSG_ANON_NO_RETURN_VALUE);
}
return NULL;
}
break;

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

@ -249,13 +249,10 @@ script_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool
XDRAtom1(JSXDRState *xdr, JSAtomListElement *ale)
{
uint32 type;
jsval value;
if (xdr->mode == JSXDR_ENCODE) {
type = JSVAL_TAG(ATOM_KEY(ale->atom));
if (xdr->mode == JSXDR_ENCODE)
value = ATOM_KEY(ale->atom);
}
if (!JS_XDRUint32(xdr, &ale->index) ||
!JS_XDRValue(xdr, &value))
@ -274,6 +271,7 @@ XDRAtomMap(JSXDRState *xdr, JSAtomMap *map)
{
uint32 length;
uintN i;
JSBool ok;
if (xdr->mode == JSXDR_ENCODE)
length = map->length;
@ -303,12 +301,12 @@ XDRAtomMap(JSXDRState *xdr, JSAtomMap *map)
al.count++;
al.list = ale;
}
if (!js_InitAtomMap(cx, map, &al)) {
JS_ARENA_RELEASE(&cx->tempPool, mark);
return JS_FALSE;
}
JS_ARENA_RELEASE(&cx->tempPool, mark);
} else if (xdr->mode == JSXDR_ENCODE) {
ok = js_InitAtomMap(cx, map, &al);
JS_ARENA_RELEASE(&cx->tempPool, mark);
return ok;
}
if (xdr->mode == JSXDR_ENCODE) {
JSAtomListElement ale;
for (i = 0; i < map->length; i++) {