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

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

Issue 96793002: Switch custom XMLHttpRequest bindings over to new-style ExceptionState. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Inline local binding in throwTypeError() Created 7 years 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
« no previous file with comments | « Source/bindings/v8/ExceptionState.cpp ('k') | Source/core/xml/XMLHttpRequest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, secu rityOrigin); 65 RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, secu rityOrigin);
66 66
67 v8::Handle<v8::Object> wrapper = info.Holder(); 67 v8::Handle<v8::Object> wrapper = info.Holder();
68 V8DOMWrapper::associateObjectWithWrapper<V8XMLHttpRequest>(xmlHttpRequest.re lease(), &wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dep endent); 68 V8DOMWrapper::associateObjectWithWrapper<V8XMLHttpRequest>(xmlHttpRequest.re lease(), &wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dep endent);
69 info.GetReturnValue().Set(wrapper); 69 info.GetReturnValue().Set(wrapper);
70 } 70 }
71 71
72 void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallb ackInfo<v8::Value>& info) 72 void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallb ackInfo<v8::Value>& info)
73 { 73 {
74 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); 74 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
75 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 75 ExceptionState exceptionState(ExceptionState::GetterContext, "responseText", "XMLHttpRequest", info.Holder(), info.GetIsolate());
76 ScriptValue text = xmlHttpRequest->responseText(exceptionState); 76 ScriptValue text = xmlHttpRequest->responseText(exceptionState);
77 if (exceptionState.throwIfNeeded()) 77 if (exceptionState.throwIfNeeded())
78 return; 78 return;
79 if (text.hasNoValue()) { 79 if (text.hasNoValue()) {
80 v8SetReturnValueString(info, emptyString(), info.GetIsolate()); 80 v8SetReturnValueString(info, emptyString(), info.GetIsolate());
81 return; 81 return;
82 } 82 }
83 v8SetReturnValue(info, text.v8Value()); 83 v8SetReturnValue(info, text.v8Value());
84 } 84 }
85 85
86 void V8XMLHttpRequest::responseAttributeGetterCustom(const v8::PropertyCallbackI nfo<v8::Value>& info) 86 void V8XMLHttpRequest::responseAttributeGetterCustom(const v8::PropertyCallbackI nfo<v8::Value>& info)
87 { 87 {
88 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); 88 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
89 89
90 switch (xmlHttpRequest->responseTypeCode()) { 90 switch (xmlHttpRequest->responseTypeCode()) {
91 case XMLHttpRequest::ResponseTypeDefault: 91 case XMLHttpRequest::ResponseTypeDefault:
92 case XMLHttpRequest::ResponseTypeText: 92 case XMLHttpRequest::ResponseTypeText:
93 responseTextAttributeGetterCustom(info); 93 responseTextAttributeGetterCustom(info);
94 return; 94 return;
95 95
96 case XMLHttpRequest::ResponseTypeJSON: 96 case XMLHttpRequest::ResponseTypeJSON:
97 { 97 {
98 v8::Isolate* isolate = info.GetIsolate(); 98 v8::Isolate* isolate = info.GetIsolate();
99 99
100 ExceptionState exceptionState(info.Holder(), isolate);
101 ScriptString jsonSource = xmlHttpRequest->responseJSONSource(); 100 ScriptString jsonSource = xmlHttpRequest->responseJSONSource();
102 if (exceptionState.throwIfNeeded())
103 return;
104
105 if (jsonSource.hasNoValue() || !jsonSource.v8Value()->IsString()) { 101 if (jsonSource.hasNoValue() || !jsonSource.v8Value()->IsString()) {
106 v8SetReturnValue(info, v8NullWithCheck(isolate)); 102 v8SetReturnValue(info, v8NullWithCheck(isolate));
107 return; 103 return;
108 } 104 }
109 105
110 // Catch syntax error. 106 // Catch syntax error.
111 v8::TryCatch exceptionCatcher; 107 v8::TryCatch exceptionCatcher;
112 108
113 v8::Handle<v8::Value> json = v8::JSON::Parse(jsonSource.v8Value().As <v8::String>()); 109 v8::Handle<v8::Value> json = v8::JSON::Parse(jsonSource.v8Value().As <v8::String>());
114 110
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 153 }
158 154
159 void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value >& info) 155 void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value >& info)
160 { 156 {
161 // Four cases: 157 // Four cases:
162 // open(method, url) 158 // open(method, url)
163 // open(method, url, async) 159 // open(method, url, async)
164 // open(method, url, async, user) 160 // open(method, url, async, user)
165 // open(method, url, async, user, passwd) 161 // open(method, url, async, user, passwd)
166 162
163 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "XML HttpRequest", info.Holder(), info.GetIsolate());
164
167 if (info.Length() < 2) { 165 if (info.Length() < 2) {
168 throwTypeError(ExceptionMessages::failedToExecute("open", "XMLHttpReques t", ExceptionMessages::notEnoughArguments(2, info.Length())), info.GetIsolate()) ; 166 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
169 return; 167 } else {
170 } 168 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder( ));
171 169
172 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); 170 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, method, info[0] );
171 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, urlstring, info [1]);
173 172
174 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, method, info[0]); 173 ExecutionContext* context = getExecutionContext();
175 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, urlstring, info[1]) ; 174 KURL url = context->completeURL(urlstring);
176 175
177 ExecutionContext* context = getExecutionContext(); 176 if (info.Length() >= 3) {
178 KURL url = context->completeURL(urlstring); 177 bool async = info[2]->BooleanValue();
179 178
180 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 179 if (info.Length() >= 4 && !info[3]->IsUndefined()) {
180 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCh eck>, user, info[3]);
181 181
182 if (info.Length() >= 3) { 182 if (info.Length() >= 5 && !info[4]->IsUndefined()) {
183 bool async = info[2]->BooleanValue(); 183 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNu llCheck>, password, info[4]);
184 184 xmlHttpRequest->open(method, url, async, user, password, exc eptionState);
185 if (info.Length() >= 4 && !info[3]->IsUndefined()) { 185 } else {
186 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck> , user, info[3]); 186 xmlHttpRequest->open(method, url, async, user, exceptionStat e);
187 187 }
188 if (info.Length() >= 5 && !info[4]->IsUndefined()) {
189 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCh eck>, password, info[4]);
190 xmlHttpRequest->open(method, url, async, user, password, excepti onState);
191 } else { 188 } else {
192 xmlHttpRequest->open(method, url, async, user, exceptionState); 189 xmlHttpRequest->open(method, url, async, exceptionState);
193 } 190 }
194 } else { 191 } else {
195 xmlHttpRequest->open(method, url, async, exceptionState); 192 xmlHttpRequest->open(method, url, exceptionState);
196 } 193 }
197 } else {
198 xmlHttpRequest->open(method, url, exceptionState);
199 } 194 }
200 195
201 exceptionState.throwIfNeeded(); 196 exceptionState.throwIfNeeded();
202 } 197 }
203 198
204 static bool isDocumentType(v8::Handle<v8::Value> value, v8::Isolate* isolate, Wr apperWorldType currentWorldType) 199 static bool isDocumentType(v8::Handle<v8::Value> value, v8::Isolate* isolate, Wr apperWorldType currentWorldType)
205 { 200 {
206 // FIXME: add other document types. 201 // FIXME: add other document types.
207 return V8Document::hasInstance(value, isolate, currentWorldType) || V8HTMLDo cument::hasInstance(value, isolate, currentWorldType); 202 return V8Document::hasInstance(value, isolate, currentWorldType) || V8HTMLDo cument::hasInstance(value, isolate, currentWorldType);
208 } 203 }
209 204
210 void V8XMLHttpRequest::sendMethodCustom(const v8::FunctionCallbackInfo<v8::Value >& info) 205 void V8XMLHttpRequest::sendMethodCustom(const v8::FunctionCallbackInfo<v8::Value >& info)
211 { 206 {
212 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); 207 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
213 208
214 InspectorInstrumentation::willSendXMLHttpRequest(xmlHttpRequest->executionCo ntext(), xmlHttpRequest->url()); 209 InspectorInstrumentation::willSendXMLHttpRequest(xmlHttpRequest->executionCo ntext(), xmlHttpRequest->url());
215 210
216 ExceptionState exceptionState(info.Holder(), info.GetIsolate()); 211 ExceptionState exceptionState(ExceptionState::ExecutionContext, "send", "XML HttpRequest", info.Holder(), info.GetIsolate());
217 if (info.Length() < 1) 212 if (info.Length() < 1)
218 xmlHttpRequest->send(exceptionState); 213 xmlHttpRequest->send(exceptionState);
219 else { 214 else {
220 v8::Handle<v8::Value> arg = info[0]; 215 v8::Handle<v8::Value> arg = info[0];
221 WrapperWorldType currentWorldType = worldType(info.GetIsolate()); 216 WrapperWorldType currentWorldType = worldType(info.GetIsolate());
222 if (isUndefinedOrNull(arg)) { 217 if (isUndefinedOrNull(arg)) {
223 xmlHttpRequest->send(exceptionState); 218 xmlHttpRequest->send(exceptionState);
224 } else if (isDocumentType(arg, info.GetIsolate(), currentWorldType)) { 219 } else if (isDocumentType(arg, info.GetIsolate(), currentWorldType)) {
225 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); 220 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
226 Document* document = V8Document::toNative(object); 221 Document* document = V8Document::toNative(object);
(...skipping 22 matching lines...) Expand all
249 } else { 244 } else {
250 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck> , argString, arg); 245 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck> , argString, arg);
251 xmlHttpRequest->send(argString, exceptionState); 246 xmlHttpRequest->send(argString, exceptionState);
252 } 247 }
253 } 248 }
254 249
255 exceptionState.throwIfNeeded(); 250 exceptionState.throwIfNeeded();
256 } 251 }
257 252
258 } // namespace WebCore 253 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ExceptionState.cpp ('k') | Source/core/xml/XMLHttpRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698