Corrected prototype for History::Go()

This commit is contained in:
vidur%netscape.com 1999-09-21 05:12:46 +00:00
Родитель 98097f2f1d
Коммит 5099c9e9a9
3 изменённых файлов: 42 добавлений и 17 удалений

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

@ -171,14 +171,47 @@ HistoryImpl::Forward()
return NS_OK;
}
NS_IMETHODIMP
HistoryImpl::Go(PRInt32 aIndex)
NS_IMETHODIMP
HistoryImpl::Go(JSContext* cx, jsval* argv, PRUint32 argc)
{
if (nsnull != mWebShell) {
mWebShell->GoTo(aIndex);
}
nsresult result = NS_OK;
if (argc > 0) {
if (JSVAL_IS_INT(argv[0])) {
PRInt32 delta = JSVAL_TO_INT(argv[0]);
PRInt32 curIndex;
return NS_OK;
result = mWebShell->GetHistoryIndex(curIndex);
if (NS_SUCCEEDED(result)) {
result = mWebShell->GoTo(curIndex + delta);
}
}
else {
JSString* jsstr = JS_ValueToString(cx, argv[0]);
PRInt32 i, count;
if (nsnull != jsstr) {
nsAutoString substr(JS_GetStringBytes(jsstr));
result = mWebShell->GetHistoryLength(count);
for (i = 0; (i < count) && NS_SUCCEEDED(result); i++) {
const PRUnichar* urlstr;
nsAutoString url;
// XXX Ownership rules for the string passed back for this
// method are not XPCOM compliant. If they were correct,
// we'd be deallocating the string passed back.
result = mWebShell->GetURL(i, &urlstr);
url.SetString(urlstr);
if (-1 != url.Find(substr)) {
result = mWebShell->GoTo(i);
break;
}
}
}
}
}
return result;
}

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

@ -45,7 +45,7 @@ public:
NS_IMETHOD GetNext(nsString& aNext);
NS_IMETHOD Back();
NS_IMETHOD Forward();
NS_IMETHOD Go(PRInt32 aIndex);
NS_IMETHOD Go(JSContext* cx, jsval* argv, PRUint32 argc);
protected:
nsIWebShell* mWebShell;

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

@ -311,7 +311,6 @@ HistoryGo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMHistory *nativeThis = (nsIDOMHistory*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
PRInt32 b0;
*rval = JSVAL_NULL;
@ -334,15 +333,8 @@ HistoryGo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
{
if (argc < 1) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_NUMBER_ERR);
}
result = nativeThis->Go(b0);
result = nativeThis->Go(cx, argv+0, argc-0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
@ -392,7 +384,7 @@ static JSFunctionSpec HistoryMethods[] =
{
{"back", HistoryBack, 0},
{"forward", HistoryForward, 0},
{"go", HistoryGo, 1},
{"go", HistoryGo, 0},
{0}
};