Bug 556876 - PropertyDescriptor::initialize can throw a SyntaxError instead of a TypeError. r=jorendorff

--HG--
extra : rebase_source : d0a38deab525d8f78f81d56d9bc78dcd5f76fb97
This commit is contained in:
Jeff Walden 2010-04-04 21:59:09 -07:00
Родитель cb77358803
Коммит 0dded63494
3 изменённых файлов: 35 добавлений и 12 удалений

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

@ -327,3 +327,4 @@ MSG_DEF(JSMSG_TYPED_ARRAY_BAD_INDEX, 244, 0, JSEXN_ERR, "invalid or out-of-rang
MSG_DEF(JSMSG_TYPED_ARRAY_NEGATIVE_ARG, 245, 1, JSEXN_ERR, "argument {0} must be >= 0")
MSG_DEF(JSMSG_TYPED_ARRAY_BAD_ARGS, 246, 0, JSEXN_ERR, "invalid arguments")
MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 247, 0, JSEXN_ERR, "call to Function() blocked by CSP")
MSG_DEF(JSMSG_BAD_GET_SET_FIELD, 248, 1, JSEXN_TYPEERR, "property descriptor's {0} field is neither undefined nor a function")

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

@ -2161,10 +2161,8 @@ PropertyDescriptor::initialize(JSContext* cx, jsid id, jsval v)
if (!HasProperty(cx, desc, ATOM_TO_JSID(cx->runtime->atomState.getAtom), &v, &hasProperty))
return false;
if (hasProperty) {
if ((JSVAL_IS_PRIMITIVE(v) || !js_IsCallable(v)) &&
v != JSVAL_VOID) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_GETTER_OR_SETTER,
if ((JSVAL_IS_PRIMITIVE(v) || !js_IsCallable(v)) && v != JSVAL_VOID) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_GET_SET_FIELD,
js_getter_str);
return false;
}
@ -2177,10 +2175,8 @@ PropertyDescriptor::initialize(JSContext* cx, jsid id, jsval v)
if (!HasProperty(cx, desc, ATOM_TO_JSID(cx->runtime->atomState.setAtom), &v, &hasProperty))
return false;
if (hasProperty) {
if ((JSVAL_IS_PRIMITIVE(v) || !js_IsCallable(v)) &&
v != JSVAL_VOID) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_GETTER_OR_SETTER,
if ((JSVAL_IS_PRIMITIVE(v) || !js_IsCallable(v)) && v != JSVAL_VOID) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_GET_SET_FIELD,
js_setter_str);
return false;
}

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

@ -683,8 +683,14 @@ TestRunner.prototype =
{
ReimplTest.defineProperty(reimplObj, "foo", desc);
}
catch (e)
catch (e2)
{
if (e.constructor !== e2.constructor)
{
this._log("Difference when comparing native/reimplementation " +
"behavior for new descriptor " + desc.toSource() +
", native threw " + e + ", reimpl threw " + e2);
}
return;
}
this._log("Difference when comparing native/reimplementation " +
@ -729,8 +735,7 @@ TestRunner.prototype =
}
catch (e)
{
if (!SameValue(NativeTest.getDescriptor(nativeObj, "foo"),
undefined))
if (!SameValue(NativeTest.getDescriptor(nativeObj, "foo"), undefined))
{
this._log("defining bad property descriptor: " + old.toSource());
return;
@ -748,6 +753,14 @@ TestRunner.prototype =
this._log("defining bad property descriptor: " + old.toSource() +
"; reimplObj: " + uneval(reimplObj));
}
if (e.constructor !== e2.constructor)
{
this._log("Different errors defining bad property descriptor: " +
old.toSource() + "; native threw " + e + ", reimpl " +
"threw " + e2);
}
return;
}
@ -780,6 +793,13 @@ TestRunner.prototype =
}
catch (e2)
{
if (e.constructor !== e2.constructor)
{
this._log("Difference when comparing native/reimplementation " +
"behavior for descriptor " + add.toSource() +
" overwriting descriptor " + old.toSource() + "; " +
"native threw " + e + ", reimpl threw " + e2);
}
return;
}
this._log("Difference when comparing native/reimplementation " +
@ -837,8 +857,14 @@ TestRunner.prototype =
{
ReimplTest.defineProperty(reimplObj, "length", desc);
}
catch (e)
catch (e2)
{
if (e.constructor !== e2.constructor)
{
this._log("Difference when comparing native/reimplementation " +
"behavior defining fun.length with " + desc.toSource() +
"; native threw " + e + ", reimpl threw " + e2);
}
return;
}
this._log("Difference when comparing Function.length native/reimpl " +