Bug 698551. When forwarding gets to the prototype in nodelists, make sure to use the right |this|. r=waldo,peterv

This commit is contained in:
Boris Zbarsky 2011-11-04 12:18:38 -04:00
Родитель 4199c112c7
Коммит 2c572e2413
5 изменённых файлов: 67 добавлений и 10 удалений

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

@ -144,6 +144,7 @@ _TEST_FILES = \
test_bug648465.html \
test_bug654137.html \
test_bug684544.html \
test_bug698551.html \
test_window_bar.html \
file_window_bar.html \
test_resize_move_windows.html \

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

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=698551
-->
<head>
<title>Test for Bug 698551</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=698551">Mozilla Bug 698551</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 698551 **/
var l = document.getElementsByTagName("body");
var it = Object.getPrototypeOf(l).item;
Object.defineProperty(Object.getPrototypeOf(l), "item",
{
get: function() { return it; },
});
Object.defineProperty(Object.getPrototypeOf(l), "foopy",
{
get: function() { return this[0]; },
});
is(l.foopy, document.body,
"Should end up with the body correctly when getting via [0]");
is(l.item(0), document.body,
"Should end up with the body correctly when getting via .item(0)");
is(l.length, 1, "Should have one body");
</script>
</pre>
</body>
</html>

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

@ -3833,11 +3833,18 @@ JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj, const jschar *name, siz
JS_PUBLIC_API(JSBool)
JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
return JS_ForwardGetPropertyTo(cx, obj, id, obj, vp);
}
JS_PUBLIC_API(JSBool)
JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, jsval *vp)
{
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, id);
assertSameCompartment(cx, onBehalfOf);
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED);
return obj->getGeneric(cx, id, vp);
return obj->getGeneric(cx, onBehalfOf, id, vp);
}
JS_PUBLIC_API(JSBool)
@ -3848,12 +3855,17 @@ JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsva
JS_PUBLIC_API(JSBool)
JS_GetElement(JSContext *cx, JSObject *obj, uint32 index, jsval *vp)
{
return JS_ForwardGetElementTo(cx, obj, index, obj, vp);
}
JS_PUBLIC_API(JSBool)
JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32 index, JSObject *onBehalfOf, jsval *vp)
{
CHECK_REQUEST(cx);
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return JS_GetPropertyById(cx, obj, id, vp);
assertSameCompartment(cx, obj);
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED);
return obj->getElement(cx, onBehalfOf, index, vp);
}
JS_PUBLIC_API(JSBool)
@ -3909,10 +3921,9 @@ JS_PUBLIC_API(JSBool)
JS_SetElement(JSContext *cx, JSObject *obj, uint32 index, jsval *vp)
{
CHECK_REQUEST(cx);
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return JS_SetPropertyById(cx, obj, INT_TO_JSID(index), vp);
assertSameCompartment(cx, obj);
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING);
return obj->setElement(cx, index, vp, false);
}
JS_PUBLIC_API(JSBool)

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

@ -3431,6 +3431,9 @@ JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
jsval *vp);
@ -3563,6 +3566,9 @@ JS_LookupElement(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_GetElement(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32 index, JSObject *onBehalfOf, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_SetElement(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);

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

@ -975,7 +975,7 @@ ListBase<LC>::getPropertyOnPrototype(JSContext *cx, JSObject *proxy, jsid id, bo
if (!hasProp || !vp)
return true;
return JS_GetPropertyById(cx, proto, id, vp);
return JS_ForwardGetPropertyTo(cx, proto, id, proxy, vp);
}
template<class LC>