From fa57f582280aa9b6ba5b87d272bcac0ec1eef1a3 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Fri, 31 Aug 2001 02:36:45 +0000 Subject: [PATCH] Fixing bug 82027, problems with accessing window.history[x] from JS. r=mstoltz@netscape.com, sr=jband@netscape.com a=dbaron@fas.harvard.edu --- dom/src/base/nsDOMClassInfo.cpp | 30 ++++++++++++++++++++++++++++-- dom/src/base/nsDOMClassInfo.h | 3 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 0eba832d21a1..230812b46d7b 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -21,7 +21,6 @@ * Johnny Stenback (original author) */ -#include "nscore.h" #include "nsDOMClassInfo.h" #include "nsCRT.h" #include "nsIServiceManager.h" @@ -4449,6 +4448,33 @@ nsStringArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // History helper +NS_IMETHODIMP +nsHistorySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, + JSObject *obj, jsval id, jsval *vp, PRBool *_retval) +{ + PRBool is_number = PR_FALSE; + GetArrayIndexFromId(cx, id, &is_number); + + if (!is_number) { + return NS_OK; + } + + nsresult rv = + sSecMan->CheckPropertyAccess(cx, obj, sClassInfoData[mID].mName, "item", + nsIXPCSecurityManager::ACCESS_CALL_METHOD); + + if (NS_FAILED(rv)) { + // Let XPConnect know that the access was not granted. + *_retval = PR_FALSE; + + return NS_OK; + } + + // sec check + + return nsStringArraySH::GetProperty(wrapper, cx, obj, id, vp, _retval); +} + nsresult nsHistorySH::GetStringAt(nsISupports *aNative, PRInt32 aIndex, nsAWritableString& aResult) @@ -4459,7 +4485,7 @@ nsHistorySH::GetStringAt(nsISupports *aNative, PRInt32 aIndex, nsCOMPtr history(do_QueryInterface(aNative)); - return history->Item(NS_PTR_TO_INT32(aNative), aResult); + return history->Item(aIndex, aResult); } diff --git a/dom/src/base/nsDOMClassInfo.h b/dom/src/base/nsDOMClassInfo.h index b8b52916ea36..72e272a101ae 100644 --- a/dom/src/base/nsDOMClassInfo.h +++ b/dom/src/base/nsDOMClassInfo.h @@ -770,6 +770,9 @@ protected: nsAWritableString& aResult); public: + NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, + JSObject *obj, jsval id, jsval *vp, PRBool *_retval); + static nsIClassInfo *doCreate(nsDOMClassInfoID aID) { return new nsHistorySH(aID);