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

Side by Side Diff: Source/core/inspector/InjectedScriptBase.cpp

Issue 1020233002: [bindings] [devtools] Migrate the usage of ScriptValue.toJSONValue() to ScriptValue::to<JSONValuePt… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments addressed! Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 33
34 #include "core/inspector/InjectedScriptBase.h" 34 #include "core/inspector/InjectedScriptBase.h"
35 35
36 #include "bindings/core/v8/ScriptFunctionCall.h" 36 #include "bindings/core/v8/ScriptFunctionCall.h"
37 #include "bindings/core/v8/V8Binding.h"
37 #include "core/inspector/InspectorInstrumentation.h" 38 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/inspector/InspectorTraceEvents.h" 39 #include "core/inspector/InspectorTraceEvents.h"
39 #include "platform/JSONValues.h" 40 #include "platform/JSONValues.h"
40 #include "wtf/text/WTFString.h" 41 #include "wtf/text/WTFString.h"
41 42
42 using blink::TypeBuilder::Array; 43 using blink::TypeBuilder::Array;
43 using blink::TypeBuilder::Runtime::RemoteObject; 44 using blink::TypeBuilder::Runtime::RemoteObject;
44 45
45 namespace blink { 46 namespace blink {
46 47
48 PassRefPtr<JSONValue> toJSONValue(const ScriptValue& value)
49 {
50 ScriptState* scriptState = value.scriptState();
51 ASSERT(scriptState->contextIsValid());
52 ScriptState::Scope scope(scriptState);
53 NonThrowableExceptionState exceptionState;
54 return ScriptValue::to<JSONValuePtr>(scriptState->isolate(), value, exceptio nState);
haraken 2015/03/25 04:39:15 Nit: As far as I see V8Binding.h, toScriptValue (n
55 }
56
47 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa ssRefPtr<JSONObject> object) 57 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa ssRefPtr<JSONObject> object)
48 { 58 {
49 String text; 59 String text;
50 if (!object->getString("text", &text)) 60 if (!object->getString("text", &text))
51 return nullptr; 61 return nullptr;
52 62
53 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild er::Debugger::ExceptionDetails::create().setText(text); 63 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild er::Debugger::ExceptionDetails::create().setText(text);
54 String url; 64 String url;
55 if (object->getString("url", &url)) 65 if (object->getString("url", &url))
56 exceptionDetails->setUrl(url); 66 exceptionDetails->setUrl(url);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (isEmpty() || !canAccessInspectedWindow()) { 169 if (isEmpty() || !canAccessInspectedWindow()) {
160 *result = JSONValue::null(); 170 *result = JSONValue::null();
161 return; 171 return;
162 } 172 }
163 173
164 bool hadException = false; 174 bool hadException = false;
165 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException ); 175 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException );
166 176
167 ASSERT(!hadException); 177 ASSERT(!hadException);
168 if (!hadException) { 178 if (!hadException) {
169 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState()); 179 *result = toJSONValue(resultValue);
haraken 2015/03/25 04:39:15 Unnecessary space.
170 if (!*result) 180 if (!*result)
171 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 181 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
172 } else { 182 } else {
173 *result = JSONString::create("Exception while making a call."); 183 *result = JSONString::create("Exception while making a call.");
174 } 184 }
175 } 185 }
176 186
177 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails> * exceptionDetails) 187 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails> * exceptionDetails)
178 { 188 {
179 RefPtr<JSONValue> result; 189 RefPtr<JSONValue> result;
(...skipping 21 matching lines...) Expand all
201 if (wasThrownVal) { 211 if (wasThrownVal) {
202 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails"); 212 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails");
203 if (objectExceptionDetails) 213 if (objectExceptionDetails)
204 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e()); 214 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e());
205 } 215 }
206 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); 216 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
207 *wasThrown = wasThrownVal; 217 *wasThrown = wasThrownVal;
208 } 218 }
209 219
210 } // namespace blink 220 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InjectedScriptBase.h ('k') | Source/modules/indexeddb/InspectorIndexedDBAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698