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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8XMLHttpRequestCustom.cpp

Issue 2472753003: Move fromJSONString to V8Binding (Closed)
Patch Set: Really swallow exception Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (text.isEmpty()) { 59 if (text.isEmpty()) {
60 v8SetReturnValueString(info, emptyString(), info.GetIsolate()); 60 v8SetReturnValueString(info, emptyString(), info.GetIsolate());
61 return; 61 return;
62 } 62 }
63 v8SetReturnValue(info, text.v8Value()); 63 v8SetReturnValue(info, text.v8Value());
64 } 64 }
65 65
66 void V8XMLHttpRequest::responseAttributeGetterCustom( 66 void V8XMLHttpRequest::responseAttributeGetterCustom(
67 const v8::FunctionCallbackInfo<v8::Value>& info) { 67 const v8::FunctionCallbackInfo<v8::Value>& info) {
68 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); 68 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder());
69 ExceptionState exceptionState(ExceptionState::GetterContext, "response",
70 "XMLHttpRequest", info.Holder(),
71 info.GetIsolate());
69 72
70 switch (xmlHttpRequest->getResponseTypeCode()) { 73 switch (xmlHttpRequest->getResponseTypeCode()) {
71 case XMLHttpRequest::ResponseTypeDefault: 74 case XMLHttpRequest::ResponseTypeDefault:
72 case XMLHttpRequest::ResponseTypeText: 75 case XMLHttpRequest::ResponseTypeText:
73 responseTextAttributeGetterCustom(info); 76 responseTextAttributeGetterCustom(info);
74 return; 77 return;
75 78
76 case XMLHttpRequest::ResponseTypeJSON: { 79 case XMLHttpRequest::ResponseTypeJSON: {
77 v8::Isolate* isolate = info.GetIsolate(); 80 v8::Isolate* isolate = info.GetIsolate();
78 81
79 ScriptString jsonSource = xmlHttpRequest->responseJSONSource(); 82 ScriptString jsonSource = xmlHttpRequest->responseJSONSource();
80 if (jsonSource.isEmpty()) { 83 if (jsonSource.isEmpty()) {
81 v8SetReturnValue(info, v8::Null(isolate)); 84 v8SetReturnValue(info, v8::Null(isolate));
82 return; 85 return;
83 } 86 }
84 87
85 // Catch syntax error. Swallows an exception (when thrown) as the 88 // Catch syntax error. Swallows an exception (when thrown) as the
86 // spec says. https://xhr.spec.whatwg.org/#response-body 89 // spec says. https://xhr.spec.whatwg.org/#response-body
87 v8::TryCatch exceptionCatcher(isolate); 90 v8::Local<v8::Value> json = fromJSONString(
88 v8::Local<v8::Value> json; 91 isolate, toCoreString(jsonSource.v8Value()), exceptionState);
89 if (v8Call(v8::JSON::Parse(isolate, jsonSource.v8Value()), json, 92 if (exceptionState.hadException()) {
90 exceptionCatcher)) 93 exceptionState.clearException();
94 v8SetReturnValue(info, v8::Null(isolate));
95 } else {
91 v8SetReturnValue(info, json); 96 v8SetReturnValue(info, json);
92 else 97 }
93 v8SetReturnValue(info, v8::Null(isolate));
94 return; 98 return;
95 } 99 }
96 100
97 case XMLHttpRequest::ResponseTypeDocument: { 101 case XMLHttpRequest::ResponseTypeDocument: {
98 ExceptionState exceptionState(ExceptionState::GetterContext, "response",
99 "XMLHttpRequest", info.Holder(),
100 info.GetIsolate());
101 Document* document = xmlHttpRequest->responseXML(exceptionState); 102 Document* document = xmlHttpRequest->responseXML(exceptionState);
102 v8SetReturnValueFast(info, document, xmlHttpRequest); 103 v8SetReturnValueFast(info, document, xmlHttpRequest);
103 return; 104 return;
104 } 105 }
105 106
106 case XMLHttpRequest::ResponseTypeBlob: { 107 case XMLHttpRequest::ResponseTypeBlob: {
107 Blob* blob = xmlHttpRequest->responseBlob(); 108 Blob* blob = xmlHttpRequest->responseBlob();
108 v8SetReturnValueFast(info, blob, xmlHttpRequest); 109 v8SetReturnValueFast(info, blob, xmlHttpRequest);
109 return; 110 return;
110 } 111 }
111 112
112 case XMLHttpRequest::ResponseTypeLegacyStream: { 113 case XMLHttpRequest::ResponseTypeLegacyStream: {
113 Stream* stream = xmlHttpRequest->responseLegacyStream(); 114 Stream* stream = xmlHttpRequest->responseLegacyStream();
114 v8SetReturnValueFast(info, stream, xmlHttpRequest); 115 v8SetReturnValueFast(info, stream, xmlHttpRequest);
115 return; 116 return;
116 } 117 }
117 118
118 case XMLHttpRequest::ResponseTypeArrayBuffer: { 119 case XMLHttpRequest::ResponseTypeArrayBuffer: {
119 DOMArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); 120 DOMArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer();
120 v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); 121 v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest);
121 return; 122 return;
122 } 123 }
123 } 124 }
124 } 125 }
125 126
126 } // namespace blink 127 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp ('k') | third_party/WebKit/Source/modules/nfc/NFC.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698