Ensure consistent warnings when accessing undefined names, bug 706240. r=waldo

This commit is contained in:
Brian Hackett 2011-12-08 19:50:09 -08:00
parent 73697fd6b9
commit 919522b206

View File

@ -5921,44 +5921,47 @@ js_GetPropertyHelperInline(JSContext *cx, JSObject *obj, JSObject *receiver, jsi
*/
jsbytecode *pc;
if (vp->isUndefined() && ((pc = js_GetCurrentBytecodePC(cx)) != NULL)) {
JSOp op;
uintN flags;
JSOp op = (JSOp) *pc;
op = (JSOp) *pc;
if (op == JSOP_GETXPROP) {
flags = JSREPORT_ERROR;
} else {
if (!cx->hasStrictOption() ||
cx->stack.currentScript()->warnedAboutUndefinedProp ||
(op != JSOP_GETPROP && op != JSOP_GETELEM)) {
return JS_TRUE;
}
/*
* XXX do not warn about missing __iterator__ as the function
* may be called from JS_GetMethodById. See bug 355145.
*/
if (JSID_IS_ATOM(id, cx->runtime->atomState.iteratorAtom))
return JS_TRUE;
/* Do not warn about tests like (obj[prop] == undefined). */
if (cx->resolveFlags == RESOLVE_INFER) {
pc += js_CodeSpec[op].length;
if (Detecting(cx, pc))
return JS_TRUE;
} else if (cx->resolveFlags & JSRESOLVE_DETECTING) {
return JS_TRUE;
}
flags = JSREPORT_WARNING | JSREPORT_STRICT;
cx->stack.currentScript()->warnedAboutUndefinedProp = true;
/* Undefined property during a name lookup, report an error. */
JSAutoByteString printable;
if (js_ValueToPrintable(cx, IdToValue(id), &printable))
js_ReportIsNotDefined(cx, printable.ptr());
return false;
}
if (!cx->hasStrictOption() ||
cx->stack.currentScript()->warnedAboutUndefinedProp ||
(op != JSOP_GETPROP && op != JSOP_GETELEM)) {
return JS_TRUE;
}
/*
* XXX do not warn about missing __iterator__ as the function
* may be called from JS_GetMethodById. See bug 355145.
*/
if (JSID_IS_ATOM(id, cx->runtime->atomState.iteratorAtom))
return JS_TRUE;
/* Do not warn about tests like (obj[prop] == undefined). */
if (cx->resolveFlags == RESOLVE_INFER) {
pc += js_CodeSpec[op].length;
if (Detecting(cx, pc))
return JS_TRUE;
} else if (cx->resolveFlags & JSRESOLVE_DETECTING) {
return JS_TRUE;
}
uintN flags = JSREPORT_WARNING | JSREPORT_STRICT;
cx->stack.currentScript()->warnedAboutUndefinedProp = true;
/* Ok, bad undefined property reference: whine about it. */
if (!js_ReportValueErrorFlags(cx, flags, JSMSG_UNDEFINED_PROP,
JSDVG_IGNORE_STACK, IdToValue(id),
NULL, NULL, NULL)) {
return JS_FALSE;
NULL, NULL, NULL))
{
return false;
}
}
return JS_TRUE;