OLD | NEW |
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 29 matching lines...) Expand all Loading... |
40 #include "bindings/v8/V8Utilities.h" | 40 #include "bindings/v8/V8Utilities.h" |
41 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 41 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
42 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 42 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
43 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
44 #include "core/inspector/InspectorInstrumentation.h" | 44 #include "core/inspector/InspectorInstrumentation.h" |
45 #include "core/page/Frame.h" | 45 #include "core/page/Frame.h" |
46 #include "core/workers/WorkerGlobalScope.h" | 46 #include "core/workers/WorkerGlobalScope.h" |
47 #include "core/xml/XMLHttpRequest.h" | 47 #include "core/xml/XMLHttpRequest.h" |
48 #include "wtf/ArrayBuffer.h" | 48 #include "wtf/ArrayBuffer.h" |
49 | 49 |
| 50 #include <v8.h> |
| 51 |
50 namespace WebCore { | 52 namespace WebCore { |
51 | 53 |
52 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu
e>& args) | 54 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu
e>& args) |
53 { | 55 { |
54 ScriptExecutionContext* context = getScriptExecutionContext(); | 56 ScriptExecutionContext* context = getScriptExecutionContext(); |
55 | 57 |
56 RefPtr<SecurityOrigin> securityOrigin; | 58 RefPtr<SecurityOrigin> securityOrigin; |
57 if (context->isDocument()) { | 59 if (context->isDocument()) { |
58 if (DOMWrapperWorld* world = isolatedWorldForEnteredContext()) | 60 if (DOMWrapperWorld* world = isolatedWorldForEnteredContext()) |
59 securityOrigin = world->isolatedWorldSecurityOrigin(); | 61 securityOrigin = world->isolatedWorldSecurityOrigin(); |
(...skipping 23 matching lines...) Expand all Loading... |
83 void V8XMLHttpRequest::responseAttrGetterCustom(v8::Local<v8::String> name, cons
t v8::PropertyCallbackInfo<v8::Value>& info) | 85 void V8XMLHttpRequest::responseAttrGetterCustom(v8::Local<v8::String> name, cons
t v8::PropertyCallbackInfo<v8::Value>& info) |
84 { | 86 { |
85 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); | 87 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); |
86 | 88 |
87 switch (xmlHttpRequest->responseTypeCode()) { | 89 switch (xmlHttpRequest->responseTypeCode()) { |
88 case XMLHttpRequest::ResponseTypeDefault: | 90 case XMLHttpRequest::ResponseTypeDefault: |
89 case XMLHttpRequest::ResponseTypeText: | 91 case XMLHttpRequest::ResponseTypeText: |
90 responseTextAttrGetterCustom(name, info); | 92 responseTextAttrGetterCustom(name, info); |
91 return; | 93 return; |
92 | 94 |
| 95 case XMLHttpRequest::ResponseTypeJSON: |
| 96 { |
| 97 v8::Isolate* isolate = info.GetIsolate(); |
| 98 |
| 99 ExceptionState es(isolate); |
| 100 ScriptString jsonSource = xmlHttpRequest->responseJSONSource(es); |
| 101 if (es.throwIfNeeded()) |
| 102 return; |
| 103 |
| 104 if (jsonSource.hasNoValue() || !jsonSource.v8Value()->IsString()) { |
| 105 v8SetReturnValue(info, v8NullWithCheck(isolate)); |
| 106 return; |
| 107 } |
| 108 |
| 109 // Catch syntax error. |
| 110 v8::TryCatch exceptionCatcher; |
| 111 |
| 112 v8::Handle<v8::Value> json = v8::JSON::Parse(jsonSource.v8Value().As
<v8::String>()); |
| 113 |
| 114 if (exceptionCatcher.HasCaught() || json.IsEmpty()) |
| 115 v8SetReturnValue(info, v8NullWithCheck(isolate)); |
| 116 else |
| 117 v8SetReturnValue(info, json); |
| 118 |
| 119 return; |
| 120 } |
| 121 |
93 case XMLHttpRequest::ResponseTypeDocument: | 122 case XMLHttpRequest::ResponseTypeDocument: |
94 { | 123 { |
95 ExceptionState es(info.GetIsolate()); | 124 ExceptionState es(info.GetIsolate()); |
96 Document* document = xmlHttpRequest->responseXML(es); | 125 Document* document = xmlHttpRequest->responseXML(es); |
97 if (es.throwIfNeeded()) | 126 if (es.throwIfNeeded()) |
98 return; | 127 return; |
99 v8SetReturnValueFast(info, document, xmlHttpRequest); | 128 v8SetReturnValueFast(info, document, xmlHttpRequest); |
100 return; | 129 return; |
101 } | 130 } |
102 | 131 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 ASSERT(arrayBufferView); | 240 ASSERT(arrayBufferView); |
212 xmlHttpRequest->send(arrayBufferView, es); | 241 xmlHttpRequest->send(arrayBufferView, es); |
213 } else | 242 } else |
214 xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), es); | 243 xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), es); |
215 } | 244 } |
216 | 245 |
217 es.throwIfNeeded(); | 246 es.throwIfNeeded(); |
218 } | 247 } |
219 | 248 |
220 } // namespace WebCore | 249 } // namespace WebCore |
OLD | NEW |