Better JSConsole return values

This commit is contained in:
vidur%netscape.com 1998-08-07 23:19:20 +00:00
Родитель 627b2eff62
Коммит af66e0492f
2 изменённых файлов: 11 добавлений и 18 удалений

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

@ -872,48 +872,40 @@ void JSConsole::EvaluateText(UINT aStartSel, UINT aEndSel)
LPSTR res = result; LPSTR res = result;
int bDelete = 0; int bDelete = 0;
JSContext *cx = (JSContext *)mContext->GetNativeContext();
JSString *jsstring = JS_ValueToString(cx, returnValue);
char *str = JS_GetStringBytes(jsstring);
::printf("The return value is "); ::printf("The return value is ");
if (JSVAL_IS_OBJECT(returnValue)) { if (JSVAL_IS_OBJECT(returnValue)) {
::printf("an object\n"); ::printf("an object\n");
::sprintf(result, " anObject [0x%X] ", JSVAL_TO_OBJECT(returnValue));
} }
else if (JSVAL_IS_INT(returnValue)) { else if (JSVAL_IS_INT(returnValue)) {
::printf("an int [%d]\n", JSVAL_TO_INT(returnValue)); ::printf("an int [%d]\n", JSVAL_TO_INT(returnValue));
::sprintf(result, " %d ", JSVAL_TO_INT(returnValue));
} }
else if (JSVAL_IS_DOUBLE(returnValue)) { else if (JSVAL_IS_DOUBLE(returnValue)) {
::printf("a double [%f]\n", *JSVAL_TO_DOUBLE(returnValue)); ::printf("a double [%f]\n", *JSVAL_TO_DOUBLE(returnValue));
::sprintf(result, " %f ", *JSVAL_TO_DOUBLE(returnValue));
} }
else if (JSVAL_IS_STRING(returnValue)) { else if (JSVAL_IS_STRING(returnValue)) {
::printf("a string [%s]\n", JS_GetStringBytes(JSVAL_TO_STRING(returnValue))); ::printf("a string [%s]\n", JS_GetStringBytes(JSVAL_TO_STRING(returnValue)));
char *jsRes = JS_GetStringBytes(JSVAL_TO_STRING(returnValue));
// make a string with 0xA changed to 0xD0xA
res = PrepareForTextArea(jsRes, JS_GetStringLength(JSVAL_TO_STRING(returnValue)));
if (res != jsRes) {
bDelete = 1; // if the buffer was new'ed
}
} }
else if (JSVAL_IS_BOOLEAN(returnValue)) { else if (JSVAL_IS_BOOLEAN(returnValue)) {
::printf("a boolean [%d]\n", JSVAL_TO_BOOLEAN(returnValue)); ::printf("a boolean [%d]\n", JSVAL_TO_BOOLEAN(returnValue));
if (JSVAL_TO_BOOLEAN(returnValue)) {
::strcpy(result, " true ");
}
else {
::strcpy(result, " false ");
}
} }
else if (JSVAL_IS_NULL(returnValue)) { else if (JSVAL_IS_NULL(returnValue)) {
printf("null\n"); printf("null\n");
::strcpy(result, " null ");
} }
else if (JSVAL_IS_VOID(returnValue)) { else if (JSVAL_IS_VOID(returnValue)) {
printf("void\n"); printf("void\n");
::strcpy(result, " void ");
} }
else { else {
printf("error: unknow return type!\n"); printf("error: unknow return type!\n");
::strcpy(result, " error: unknow return type! "); }
// make a string with 0xA changed to 0xD0xA
res = PrepareForTextArea(str, JS_GetStringLength(jsstring));
if (res != str) {
bDelete = 1; // if the buffer was new'ed
} }
// set the position at the end of the selection // set the position at the end of the selection

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

@ -96,3 +96,4 @@ public:
}; };
#endif /* nsViewerApp_h___ */ #endif /* nsViewerApp_h___ */