diff --git a/scripting/javascript/bindings/XMLHTTPRequest.cpp b/scripting/javascript/bindings/XMLHTTPRequest.cpp index 5869fd9fb3..f4c27d8bb1 100644 --- a/scripting/javascript/bindings/XMLHTTPRequest.cpp +++ b/scripting/javascript/bindings/XMLHTTPRequest.cpp @@ -322,8 +322,8 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) */ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, onreadystatechange) { - if (onreadystateCallback) { - + if (onreadystateCallback) + { JSString *tmpstr = JS_NewStringCopyZ(cx, "1"); jsval tmpval = STRING_TO_JSVAL(tmpstr); JS_SetProperty(cx, onreadystateCallback, "readyState", &tmpval); @@ -485,12 +485,15 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, status) */ 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) { - vp.set(STRING_TO_JSVAL(str)); + if (strVal != JSVAL_NULL) + { + vp.set(strVal); return JS_TRUE; - } else { + } + else + { JS_ReportError(cx, "Error trying to create JSString from data"); return JS_FALSE; } @@ -526,10 +529,11 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, withCredentials) */ 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) { - vp.set(STRING_TO_JSVAL(str)); + if (strVal != JSVAL_NULL) + { + vp.set(strVal); //JS_ReportError(cx, "Result: %s", data.str().c_str()); return JS_TRUE; } else { @@ -548,13 +552,15 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response) if (responseType == kRequestResponseTypeJSON) { jsval outVal; - JSString* str = JS_NewStringCopyZ(cx, data.str().c_str());//, dataSize); - if (JS_ParseJSON(cx, JS_GetStringCharsZ(cx, str), dataSize, &outVal)) { - + jsval strVal = std_string_to_jsval(cx, data.str()); + if (JS_ParseJSON(cx, JS_GetStringCharsZ(cx, JSVAL_TO_STRING(strVal)), dataSize, &outVal)) + { vp.set(outVal); return JS_TRUE; } - } else if (responseType == kRequestResponseTypeArrayBuffer) { + } + else if (responseType == kRequestResponseTypeArrayBuffer) + { JSObject* tmp = JS_NewArrayBuffer(cx, dataSize); uint8_t* tmpData = JS_GetArrayBufferData(tmp); data.read((char*)tmpData, dataSize); @@ -675,12 +681,14 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getAllResponseHeaders) responseheader = responseheaders.str(); - JSString* str = JS_NewStringCopyZ(cx, responseheader.c_str()); - - if (str) { - JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str)); + jsval strVal = std_string_to_jsval(cx, responseheader); + if (strVal != JSVAL_NULL) + { + JS_SET_RVAL(cx, vp, strVal); return JS_TRUE; - } else { + } + else + { JS_ReportError(cx, "Error trying to create JSString from data"); return JS_FALSE; } @@ -714,10 +722,8 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getResponseHeader) map::iterator iter = http_header.find(value); if (iter != http_header.end() ) { - JSString *js_ret_val = JS_NewStringCopyZ(cx, iter->second.c_str()); - - // iter->second - JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(js_ret_val)); + jsval js_ret_val = std_string_to_jsval(cx, iter->second); + JS_SET_RVAL(cx, vp, js_ret_val); return JS_TRUE; } else {