window.prompt() returns jsval instead of string, allowing it to return null when required. wants to be changed back to a string once the DOM APIs support this same thing. bug 12021. r=jst@netscape.com

This commit is contained in:
danm%netscape.com 2000-06-09 00:14:44 +00:00
Родитель 6943ccb636
Коммит cadb12d58a
4 изменённых файлов: 25 добавлений и 24 удалений

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

@ -141,7 +141,7 @@ public:
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn)=0; NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn)=0;
NS_IMETHOD Prompt(JSContext* cx, jsval* argv, PRUint32 argc, nsString& aReturn)=0; NS_IMETHOD Prompt(JSContext* cx, jsval* argv, PRUint32 argc, jsval* aReturn)=0;
NS_IMETHOD Focus()=0; NS_IMETHOD Focus()=0;
@ -265,7 +265,7 @@ public:
NS_IMETHOD Dump(const nsString& aStr); \ NS_IMETHOD Dump(const nsString& aStr); \
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc); \ NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc); \
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn); \ NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn); \
NS_IMETHOD Prompt(JSContext* cx, jsval* argv, PRUint32 argc, nsString& aReturn); \ NS_IMETHOD Prompt(JSContext* cx, jsval* argv, PRUint32 argc, jsval* aReturn); \
NS_IMETHOD Focus(); \ NS_IMETHOD Focus(); \
NS_IMETHOD Blur(); \ NS_IMETHOD Blur(); \
NS_IMETHOD Back(); \ NS_IMETHOD Back(); \
@ -355,7 +355,7 @@ public:
NS_IMETHOD Dump(const nsString& aStr) { return _to Dump(aStr); } \ NS_IMETHOD Dump(const nsString& aStr) { return _to Dump(aStr); } \
NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc) { return _to Alert(cx, argv, argc); } \ NS_IMETHOD Alert(JSContext* cx, jsval* argv, PRUint32 argc) { return _to Alert(cx, argv, argc); } \
NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn) { return _to Confirm(cx, argv, argc, aReturn); } \ NS_IMETHOD Confirm(JSContext* cx, jsval* argv, PRUint32 argc, PRBool* aReturn) { return _to Confirm(cx, argv, argc, aReturn); } \
NS_IMETHOD Prompt(JSContext* cx, jsval* argv, PRUint32 argc, nsString& aReturn) { return _to Prompt(cx, argv, argc, aReturn); } \ NS_IMETHOD Prompt(JSContext* cx, jsval* argv, PRUint32 argc, jsval* aReturn) { return _to Prompt(cx, argv, argc, aReturn); } \
NS_IMETHOD Focus() { return _to Focus(); } \ NS_IMETHOD Focus() { return _to Focus(); } \
NS_IMETHOD Blur() { return _to Blur(); } \ NS_IMETHOD Blur() { return _to Blur(); } \
NS_IMETHOD Back() { return _to Back(); } \ NS_IMETHOD Back() { return _to Back(); } \

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

@ -42,7 +42,10 @@ interface Window {
void dump(in wstring str); void dump(in wstring str);
void alert(/* ... */); void alert(/* ... */);
boolean confirm(/* ... */); boolean confirm(/* ... */);
DOMString prompt(/* ... */); // XXX prompt() should be changed back to return a string once
// the DOM APIs allow us to return null js values for a string.
// in the meantime, this is the only way to do that:
jsval prompt(/* ... */);
void focus(); void focus();
void blur(); void blur();
void back(); void back();

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

@ -1205,23 +1205,21 @@ NS_IMETHODIMP GlobalWindowImpl::Confirm(JSContext* cx, jsval* argv,
} }
NS_IMETHODIMP GlobalWindowImpl::Prompt(JSContext* cx, jsval* argv, NS_IMETHODIMP GlobalWindowImpl::Prompt(JSContext* cx, jsval* argv,
PRUint32 argc, nsString& aReturn) PRUint32 argc, jsval* aReturn)
{ {
NS_ENSURE_STATE(mDocShell); NS_ENSURE_STATE(mDocShell);
nsresult ret = NS_OK; nsresult ret = NS_OK;
nsAutoString str, initial; nsAutoString message, initial;
aReturn.Truncate(); if(argc > 0) {
if(argc > 0) nsJSUtils::nsConvertJSValToString(message, cx, argv[0]);
{
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
if(argc > 1) if(argc > 1)
nsJSUtils::nsConvertJSValToString(initial, cx, argv[1]); nsJSUtils::nsConvertJSValToString(initial, cx, argv[1]);
else else
initial.AssignWithConversion("undefined"); initial.AssignWithConversion("undefined");
} }
nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mDocShell)); nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mDocShell));
@ -1229,18 +1227,18 @@ NS_IMETHODIMP GlobalWindowImpl::Prompt(JSContext* cx, jsval* argv,
PRBool b; PRBool b;
PRUnichar* uniResult = nsnull; PRUnichar* uniResult = nsnull;
ret = prompter->Prompt(nsnull, str.GetUnicode(), nsnull, ret = prompter->Prompt(nsnull, message.GetUnicode(), nsnull,
initial.GetUnicode(), &uniResult, &b); initial.GetUnicode(), &uniResult, &b);
aReturn = uniResult;
if(uniResult) if (NS_SUCCEEDED(ret) && uniResult && b) {
JSString *jsret = JS_NewUCStringCopyZ(cx, uniResult);
*aReturn = STRING_TO_JSVAL(jsret);
}
else
*aReturn = JSVAL_NULL;
if (uniResult)
nsMemory::Free(uniResult); nsMemory::Free(uniResult);
if(NS_FAILED(ret) || !b)
{
// XXX Need to check return value and return null if the
// user hits cancel. Currently, we can only return a
// string reference.
aReturn.SetLength(0);
}
return ret; return ret;
} }

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

@ -1163,7 +1163,7 @@ WindowPrompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK; nsresult result = NS_OK;
nsAutoString nativeRet; jsval nativeRet;
// If there's no private data, this must be the prototype, so ignore // If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) { if (nsnull == nativeThis) {
return JS_TRUE; return JS_TRUE;
@ -1179,12 +1179,12 @@ WindowPrompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return nsJSUtils::nsReportError(cx, obj, result); return nsJSUtils::nsReportError(cx, obj, result);
} }
result = nativeThis->Prompt(cx, argv+0, argc-0, nativeRet); result = nativeThis->Prompt(cx, argv+0, argc-0, &nativeRet);
if (NS_FAILED(result)) { if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result); return nsJSUtils::nsReportError(cx, obj, result);
} }
nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval); *rval = nativeRet;
} }
return JS_TRUE; return JS_TRUE;