mirror of https://github.com/axmolengine/axmol.git
closed #2586: The utf8 response in XmlHttpRequest are mess codes.
This commit is contained in:
parent
d79e6dee7a
commit
5407719f44
|
@ -322,8 +322,8 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest)
|
||||||
*/
|
*/
|
||||||
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, onreadystatechange)
|
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, onreadystatechange)
|
||||||
{
|
{
|
||||||
if (onreadystateCallback) {
|
if (onreadystateCallback)
|
||||||
|
{
|
||||||
JSString *tmpstr = JS_NewStringCopyZ(cx, "1");
|
JSString *tmpstr = JS_NewStringCopyZ(cx, "1");
|
||||||
jsval tmpval = STRING_TO_JSVAL(tmpstr);
|
jsval tmpval = STRING_TO_JSVAL(tmpstr);
|
||||||
JS_SetProperty(cx, onreadystateCallback, "readyState", &tmpval);
|
JS_SetProperty(cx, onreadystateCallback, "readyState", &tmpval);
|
||||||
|
@ -485,12 +485,15 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, status)
|
||||||
*/
|
*/
|
||||||
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, statusText)
|
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, statusText)
|
||||||
{
|
{
|
||||||
JSString* str = JS_NewStringCopyZ(cx, statusText.c_str());//, dataSize);
|
jsval strVal = std_string_to_jsval(cx, statusText);
|
||||||
|
|
||||||
if (str) {
|
if (strVal != JSVAL_NULL)
|
||||||
vp.set(STRING_TO_JSVAL(str));
|
{
|
||||||
|
vp.set(strVal);
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
JS_ReportError(cx, "Error trying to create JSString from data");
|
JS_ReportError(cx, "Error trying to create JSString from data");
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -526,10 +529,11 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, withCredentials)
|
||||||
*/
|
*/
|
||||||
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText)
|
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText)
|
||||||
{
|
{
|
||||||
JSString* str = JS_NewStringCopyZ(cx, data.str().c_str());//, dataSize);
|
jsval strVal = std_string_to_jsval(cx, data.str());
|
||||||
|
|
||||||
if (str) {
|
if (strVal != JSVAL_NULL)
|
||||||
vp.set(STRING_TO_JSVAL(str));
|
{
|
||||||
|
vp.set(strVal);
|
||||||
//JS_ReportError(cx, "Result: %s", data.str().c_str());
|
//JS_ReportError(cx, "Result: %s", data.str().c_str());
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -548,13 +552,15 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response)
|
||||||
if (responseType == kRequestResponseTypeJSON) {
|
if (responseType == kRequestResponseTypeJSON) {
|
||||||
jsval outVal;
|
jsval outVal;
|
||||||
|
|
||||||
JSString* str = JS_NewStringCopyZ(cx, data.str().c_str());//, dataSize);
|
jsval strVal = std_string_to_jsval(cx, data.str());
|
||||||
if (JS_ParseJSON(cx, JS_GetStringCharsZ(cx, str), dataSize, &outVal)) {
|
if (JS_ParseJSON(cx, JS_GetStringCharsZ(cx, JSVAL_TO_STRING(strVal)), dataSize, &outVal))
|
||||||
|
{
|
||||||
vp.set(outVal);
|
vp.set(outVal);
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
} else if (responseType == kRequestResponseTypeArrayBuffer) {
|
}
|
||||||
|
else if (responseType == kRequestResponseTypeArrayBuffer)
|
||||||
|
{
|
||||||
JSObject* tmp = JS_NewArrayBuffer(cx, dataSize);
|
JSObject* tmp = JS_NewArrayBuffer(cx, dataSize);
|
||||||
uint8_t* tmpData = JS_GetArrayBufferData(tmp);
|
uint8_t* tmpData = JS_GetArrayBufferData(tmp);
|
||||||
data.read((char*)tmpData, dataSize);
|
data.read((char*)tmpData, dataSize);
|
||||||
|
@ -675,12 +681,14 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getAllResponseHeaders)
|
||||||
|
|
||||||
responseheader = responseheaders.str();
|
responseheader = responseheaders.str();
|
||||||
|
|
||||||
JSString* str = JS_NewStringCopyZ(cx, responseheader.c_str());
|
jsval strVal = std_string_to_jsval(cx, responseheader);
|
||||||
|
if (strVal != JSVAL_NULL)
|
||||||
if (str) {
|
{
|
||||||
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
|
JS_SET_RVAL(cx, vp, strVal);
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
JS_ReportError(cx, "Error trying to create JSString from data");
|
JS_ReportError(cx, "Error trying to create JSString from data");
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -714,10 +722,8 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getResponseHeader)
|
||||||
map<string, string>::iterator iter = http_header.find(value);
|
map<string, string>::iterator iter = http_header.find(value);
|
||||||
if (iter != http_header.end() ) {
|
if (iter != http_header.end() ) {
|
||||||
|
|
||||||
JSString *js_ret_val = JS_NewStringCopyZ(cx, iter->second.c_str());
|
jsval js_ret_val = std_string_to_jsval(cx, iter->second);
|
||||||
|
JS_SET_RVAL(cx, vp, js_ret_val);
|
||||||
// iter->second
|
|
||||||
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(js_ret_val));
|
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue