bug 488285 - fixing strict mode warnings with DOm window object. r=brendan

This commit is contained in:
Igor Bukanov
2009-04-15 16:09:58 +02:00
parent d494a65ad7
commit 97294cf352
4 changed files with 43 additions and 25 deletions

View File

@@ -4379,9 +4379,30 @@ js_GetMethod(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
return OBJ_GET_PROPERTY(cx, obj, id, vp);
}
JS_FRIEND_API(JSBool)
js_CheckUndeclaredVarAssignment(JSContext *cx)
{
JSStackFrame *fp;
if (!JS_HAS_STRICT_OPTION(cx) ||
!(fp = js_GetTopStackFrame(cx)) ||
!fp->regs ||
js_GetOpcode(cx, fp->script, fp->regs->pc) != JSOP_SETNAME) {
return JS_TRUE;
}
JSAtom *atom;
GET_ATOM_FROM_BYTECODE(fp->script, fp->regs->pc, 0, atom);
const char *bytes = js_AtomToPrintableString(cx, atom);
return bytes &&
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING | JSREPORT_STRICT,
js_GetErrorMessage, NULL,
JSMSG_UNDECLARED_VAR, bytes);
}
JSBool
js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id,
JSBool unqualified, jsval *vp, JSPropCacheEntry **entryp)
js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
JSPropCacheEntry **entryp)
{
uint32 shape;
int protoIndex;
@@ -4420,19 +4441,8 @@ js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id,
/* We should never add properties to lexical blocks. */
JS_ASSERT(OBJ_GET_CLASS(cx, obj) != &js_BlockClass);
if (unqualified && !OBJ_GET_PARENT(cx, obj) &&
JS_HAS_STRICT_OPTION(cx)) {
JSString *str = JSVAL_TO_STRING(ID_TO_VALUE(id));
const char *bytes = js_GetStringBytes(cx, str);
if (!bytes ||
!JS_ReportErrorFlagsAndNumber(cx,
JSREPORT_WARNING |
JSREPORT_STRICT,
js_GetErrorMessage, NULL,
JSMSG_UNDECLARED_VAR, bytes)) {
return NULL;
}
}
if (!OBJ_GET_PARENT(cx, obj) && !js_CheckUndeclaredVarAssignment(cx))
return NULL;
}
sprop = (JSScopeProperty *) prop;
@@ -4607,7 +4617,7 @@ js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id,
JSBool
js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
return js_SetPropertyHelper(cx, obj, id, false, vp, NULL);
return js_SetPropertyHelper(cx, obj, id, vp, NULL);
}
JSBool