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

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: Rebase 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 3989c296bd1424df45b4e8171ad81426d91473c0..844431a59152300435bd0c96b5c1fc28ff09d372 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:
+ {
+ v8::Isolate* isolate = info.GetIsolate();
+
+ ExceptionState es(isolate);
+ ScriptString jsonSource = xmlHttpRequest->responseJSONSource(es);
+ if (es.throwIfNeeded())
+ return;
+
+ 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