bug 488995 - fixing error reporting for getter-only properties. r=mrbkap sr=jst

This commit is contained in:
Igor Bukanov 2009-04-22 12:39:08 +02:00
parent b8845d61de
commit e4bc4e81cb
5 changed files with 39 additions and 9 deletions

View File

@ -5987,6 +5987,21 @@ js_IsCallable(JSObject *obj, JSContext *cx)
return callable;
}
void
js_ReportGetterOnlyAssignment(JSContext *cx)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_GETTER_ONLY, NULL);
}
JS_FRIEND_API(JSBool)
js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
js_ReportGetterOnlyAssignment(cx);
return JS_FALSE;
}
#ifdef DEBUG
/*

View File

@ -854,6 +854,12 @@ js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
extern JSBool
js_IsCallable(JSObject *obj, JSContext *cx);
void
js_ReportGetterOnlyAssignment(JSContext *cx);
extern JS_FRIEND_API(JSBool)
js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
#ifdef DEBUG
JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n);
JS_FRIEND_API(void) js_DumpString(JSString *str);

View File

@ -375,8 +375,7 @@ js_SetSprop(JSContext* cx, JSScopeProperty* sprop, JSObject* obj, jsval* vp)
}
if (sprop->attrs & JSPROP_GETTER) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_GETTER_ONLY, NULL);
js_ReportGetterOnlyAssignment(cx);
return JS_FALSE;
}

View File

@ -295,18 +295,23 @@ JSBool XPCIDispatchExtension::DefineProperty(XPCCallContext & ccx,
// Define the property on the object
NS_ASSERTION(member->IsProperty(), "way broken!");
propFlags |= JSPROP_GETTER | JSPROP_SHARED;
JSPropertyOp getter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj);
JSPropertyOp setter;
if(member->IsSetter())
{
propFlags |= JSPROP_SETTER;
propFlags &= ~JSPROP_READONLY;
setter = getter;
}
else
{
setter = js_GetterOnlyPropertyStub;
}
AutoResolveName arn(ccx, idval);
if(resolved)
*resolved = JS_TRUE;
return JS_ValueToId(ccx, idval, &id) &&
JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID, getter, setter,
propFlags);
}

View File

@ -469,21 +469,26 @@ DefinePropertyIfFound(XPCCallContext& ccx,
NS_ASSERTION(member->IsAttribute(), "way broken!");
propFlags |= JSPROP_GETTER | JSPROP_SHARED;
JSObject* funobj = JSVAL_TO_OBJECT(funval);
JSPropertyOp getter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj);
JSPropertyOp setter;
if(member->IsWritableAttribute())
{
propFlags |= JSPROP_SETTER;
propFlags &= ~JSPROP_READONLY;
setter = getter;
}
else
{
setter = js_GetterOnlyPropertyStub;
}
AutoResolveName arn(ccx, idval);
if(resolved)
*resolved = JS_TRUE;
JSObject* funobj = JSVAL_TO_OBJECT(funval);
return JS_ValueToId(ccx, idval, &id) &&
JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID, getter, setter,
propFlags);
}