From 7c9b5321a53b09152e395b97a51cb06e66f51184 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 4 Nov 2011 12:18:38 -0400 Subject: [PATCH] Bug 698551. When forwarding gets to the prototype in nodelists, make sure to use the right |this|. r=waldo,peterv --- dom/tests/mochitest/bugs/Makefile.in | 1 + dom/tests/mochitest/bugs/test_bug698551.html | 39 ++++++++++++++++++++ js/src/jsapi.cpp | 29 ++++++++++----- js/src/jsapi.h | 6 +++ js/xpconnect/src/dombindings.cpp | 2 +- 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 dom/tests/mochitest/bugs/test_bug698551.html diff --git a/dom/tests/mochitest/bugs/Makefile.in b/dom/tests/mochitest/bugs/Makefile.in index 6f39e72957e..62eaf858add 100644 --- a/dom/tests/mochitest/bugs/Makefile.in +++ b/dom/tests/mochitest/bugs/Makefile.in @@ -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 \ diff --git a/dom/tests/mochitest/bugs/test_bug698551.html b/dom/tests/mochitest/bugs/test_bug698551.html new file mode 100644 index 00000000000..70a002bb97b --- /dev/null +++ b/dom/tests/mochitest/bugs/test_bug698551.html @@ -0,0 +1,39 @@ + + + + + Test for Bug 698551 + + + + +Mozilla Bug 698551 +

+ +
+
+
+ + diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 0c670ffe01b..1f1ef983e99 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -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) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index f004601d852..9641cf841a0 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -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); diff --git a/js/xpconnect/src/dombindings.cpp b/js/xpconnect/src/dombindings.cpp index b1f38681622..55f120594e9 100644 --- a/js/xpconnect/src/dombindings.cpp +++ b/js/xpconnect/src/dombindings.cpp @@ -975,7 +975,7 @@ ListBase::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