Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp

Issue 21600002: Add json responseType support to XMLHttpRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: LayoutTests Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/http/tests/xmlhttprequest/response-json-expected.txt ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
diff --git a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
index 43022213a4ba580285c8db4904c7e4dd41ac1b60..fb7f192cb95c72ee3b0e2874f3e19dccb4e39900 100644
--- a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
+++ b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
@@ -47,6 +47,8 @@
#include "core/xml/XMLHttpRequest.h"
#include "wtf/ArrayBuffer.h"
+#include <v8.h>
+
namespace WebCore {
void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -90,6 +92,33 @@ void V8XMLHttpRequest::responseAttrGetterCustom(v8::Local<v8::String> name, cons
responseTextAttrGetterCustom(name, info);
return;
+ case XMLHttpRequest::ResponseTypeJson:
abarth-chromium 2013/08/06 19:28:33 ResponseTypeJson -> ResponseTypeJSON
tyoshino (SeeGerritForStatus) 2013/08/07 03:37:46 Done.
+ {
+ ExceptionState es(info.GetIsolate());
+ ScriptString jsonSource = xmlHttpRequest->responseJsonSource(es);
abarth-chromium 2013/08/06 19:28:33 responseJsonSource -> responseJSONSource
tyoshino (SeeGerritForStatus) 2013/08/07 03:37:46 Done.
+ if (es.throwIfNeeded())
+ return;
+
+ v8::Isolate* isolate = info.GetIsolate();
abarth-chromium 2013/08/06 19:28:33 Should we grab the isolate at the top of the block
tyoshino (SeeGerritForStatus) 2013/08/07 03:37:46 Yes! Done
+
+ if (jsonSource.hasNoValue() || !jsonSource.v8Value()->IsString()) {
+ v8SetReturnValue(info, v8NullWithCheck(isolate));
+ return;
+ }
+
+ // Catch syntax error.
+ v8::TryCatch exceptionCatcher;
+
+ v8::Handle<v8::Value> json = v8::JSON::Parse(jsonSource.v8Value().As<v8::String>());
+
+ if (exceptionCatcher.HasCaught() || json.IsEmpty())
+ v8SetReturnValue(info, v8NullWithCheck(isolate));
+ else
+ v8SetReturnValue(info, json);
+
+ return;
+ }
+
case XMLHttpRequest::ResponseTypeDocument:
{
ExceptionState es(info.GetIsolate());
« no previous file with comments | « LayoutTests/http/tests/xmlhttprequest/response-json-expected.txt ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698