Bug 722121 - Remove the last now-unnecessary uses of CheckRedeclaration from JSOP_GETTER/JSOP_SETTER, as syntactically we guarantee no conflicts are possible. r=jorendorff

--HG--
extra : rebase_source : f9b9bac41153cd269e3d9a4f02a4bd6f963b82fa
This commit is contained in:
Jeff Walden 2012-01-28 23:13:12 -08:00
parent c0a49d053b
commit 638e9fa48e
2 changed files with 0 additions and 84 deletions

View File

@ -698,77 +698,6 @@ js::Execute(JSContext *cx, JSScript *script, JSObject &scopeChainArg, Value *rva
NULL /* evalInFrame */, rval);
}
bool
js::CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs)
{
JSObject *obj2;
JSProperty *prop;
uintN oldAttrs;
bool isFunction;
const char *type, *name;
if (!obj->lookupGeneric(cx, id, &obj2, &prop))
return false;
if (!prop)
return true;
if (obj2->isNative()) {
oldAttrs = ((Shape *) prop)->attributes();
} else {
if (!obj2->getGenericAttributes(cx, id, &oldAttrs))
return false;
}
/* We allow redeclaring some non-readonly properties. */
if (((oldAttrs | attrs) & JSPROP_READONLY) == 0) {
/* Allow redeclaration of variables and functions. */
if (!(attrs & (JSPROP_GETTER | JSPROP_SETTER)))
return true;
/*
* Allow adding a getter only if a property already has a setter
* but no getter and similarly for adding a setter. That is, we
* allow only the following transitions:
*
* no-property --> getter --> getter + setter
* no-property --> setter --> getter + setter
*/
if ((~(oldAttrs ^ attrs) & (JSPROP_GETTER | JSPROP_SETTER)) == 0)
return true;
/*
* Allow redeclaration of an impermanent property (in which case
* anyone could delete it and redefine it, willy-nilly).
*/
if (!(oldAttrs & JSPROP_PERMANENT))
return true;
}
isFunction = (oldAttrs & (JSPROP_GETTER | JSPROP_SETTER)) != 0;
if (!isFunction) {
Value value;
if (!obj->getGeneric(cx, id, &value))
return JS_FALSE;
isFunction = IsFunctionObject(value);
}
type = (oldAttrs & attrs & JSPROP_GETTER)
? js_getter_str
: (oldAttrs & attrs & JSPROP_SETTER)
? js_setter_str
: (oldAttrs & JSPROP_READONLY)
? js_const_str
: isFunction
? js_function_str
: js_var_str;
JSAutoByteString bytes;
name = js_ValueToPrintable(cx, IdToValue(id), &bytes);
if (!name)
return false;
JS_ALWAYS_FALSE(JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL,
JSMSG_REDECLARED_VAR, type, name));
return false;
}
JSBool
js::HasInstance(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp)
{
@ -3520,10 +3449,6 @@ BEGIN_CASE(JSOP_SETTER)
}
attrs |= JSPROP_ENUMERATE | JSPROP_SHARED;
/* Check for a readonly or permanent property of the same name. */
if (!CheckRedeclaration(cx, obj, id, attrs))
goto error;
if (!obj->defineGeneric(cx, id, UndefinedValue(), getter, setter, attrs))
goto error;

View File

@ -229,15 +229,6 @@ Interpret(JSContext *cx, StackFrame *stopFp, InterpMode mode = JSINTERP_NORMAL);
extern bool
RunScript(JSContext *cx, JSScript *script, StackFrame *fp);
extern bool
CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs);
inline bool
CheckRedeclaration(JSContext *cx, JSObject *obj, PropertyName *name, uintN attrs)
{
return CheckRedeclaration(cx, obj, ATOM_TO_JSID(name), attrs);
}
extern bool
StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval, bool *equal);