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

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: 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(ScriptState* scriptState, const ScriptValue& v alue)
haraken 2015/03/24 15:23:10 BTW, what's a relationship between scriptState and
49 {
50 ASSERT(scriptState->contextIsValid());
51 ScriptState::Scope scope(scriptState);
vivekg 2015/03/24 05:21:49 When I remove above scope, we get this crash log:
52 NonThrowableExceptionState exceptionState;
53 return ScriptValue::to<JSONValuePtr>(scriptState->isolate(), value, exceptio nState);
54 }
55
47 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa ssRefPtr<JSONObject> object) 56 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa ssRefPtr<JSONObject> object)
48 { 57 {
49 String text; 58 String text;
50 if (!object->getString("text", &text)) 59 if (!object->getString("text", &text))
51 return nullptr; 60 return nullptr;
52 61
53 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild er::Debugger::ExceptionDetails::create().setText(text); 62 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild er::Debugger::ExceptionDetails::create().setText(text);
54 String url; 63 String url;
55 if (object->getString("url", &url)) 64 if (object->getString("url", &url))
56 exceptionDetails->setUrl(url); 65 exceptionDetails->setUrl(url);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (isEmpty() || !canAccessInspectedWindow()) { 168 if (isEmpty() || !canAccessInspectedWindow()) {
160 *result = JSONValue::null(); 169 *result = JSONValue::null();
161 return; 170 return;
162 } 171 }
163 172
164 bool hadException = false; 173 bool hadException = false;
165 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException ); 174 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException );
166 175
167 ASSERT(!hadException); 176 ASSERT(!hadException);
168 if (!hadException) { 177 if (!hadException) {
169 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState()); 178 *result = toJSONValue(m_injectedScriptObject.scriptState(), resultValue );
170 if (!*result) 179 if (!*result)
171 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 180 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
172 } else { 181 } else {
173 *result = JSONString::create("Exception while making a call."); 182 *result = JSONString::create("Exception while making a call.");
174 } 183 }
175 } 184 }
176 185
177 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails> * exceptionDetails) 186 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails> * exceptionDetails)
178 { 187 {
179 RefPtr<JSONValue> result; 188 RefPtr<JSONValue> result;
(...skipping 21 matching lines...) Expand all
201 if (wasThrownVal) { 210 if (wasThrownVal) {
202 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails"); 211 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails");
203 if (objectExceptionDetails) 212 if (objectExceptionDetails)
204 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e()); 213 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e());
205 } 214 }
206 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); 215 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
207 *wasThrown = wasThrownVal; 216 *wasThrown = wasThrownVal;
208 } 217 }
209 218
210 } // namespace blink 219 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698