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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp

Issue 1730383003: DevTools: consistently use Maybe for optional values in the protocol generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed Created 4 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
44 44
45 using blink::protocol::Array; 45 using blink::protocol::Array;
46 using blink::protocol::Debugger::CallFrame; 46 using blink::protocol::Debugger::CallFrame;
47 using blink::protocol::Debugger::CollectionEntry; 47 using blink::protocol::Debugger::CollectionEntry;
48 using blink::protocol::Debugger::FunctionDetails; 48 using blink::protocol::Debugger::FunctionDetails;
49 using blink::protocol::Debugger::GeneratorObjectDetails; 49 using blink::protocol::Debugger::GeneratorObjectDetails;
50 using blink::protocol::Runtime::PropertyDescriptor; 50 using blink::protocol::Runtime::PropertyDescriptor;
51 using blink::protocol::Runtime::InternalPropertyDescriptor; 51 using blink::protocol::Runtime::InternalPropertyDescriptor;
52 using blink::protocol::Runtime::RemoteObject; 52 using blink::protocol::Runtime::RemoteObject;
53 using blink::protocol::OptionalValue; 53 using blink::protocol::Maybe;
54 54
55 namespace blink { 55 namespace blink {
56 56
57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(PassRe fPtr<JSONObject> object) 57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(PassRe fPtr<JSONObject> object)
58 { 58 {
59 String text; 59 String text;
60 if (!object->getString("text", &text)) 60 if (!object->getString("text", &text))
61 return nullptr; 61 return nullptr;
62 62
63 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run time::ExceptionDetails::create().setText(text).build(); 63 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run time::ExceptionDetails::create().setText(text).build();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 , m_native(injectedScriptNative) 124 , m_native(injectedScriptNative)
125 , m_contextId(contextId) 125 , m_contextId(contextId)
126 { 126 {
127 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); 127 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter);
128 } 128 }
129 129
130 InjectedScript::~InjectedScript() 130 InjectedScript::~InjectedScript()
131 { 131 {
132 } 132 }
133 133
134 void InjectedScript::evaluate(ErrorString* errorString, const String& expression , const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, boo l generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, OptionalValu e<bool>* wasThrown, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDetail s) 134 void InjectedScript::evaluate(ErrorString* errorString, const String& expression , const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, boo l generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
135 { 135 {
136 v8::HandleScope handles(m_isolate); 136 v8::HandleScope handles(m_isolate);
137 V8FunctionCall function(m_client, context(), v8Value(), "evaluate"); 137 V8FunctionCall function(m_client, context(), v8Value(), "evaluate");
138 function.appendArgument(expression); 138 function.appendArgument(expression);
139 function.appendArgument(objectGroup); 139 function.appendArgument(objectGroup);
140 function.appendArgument(includeCommandLineAPI); 140 function.appendArgument(includeCommandLineAPI);
141 function.appendArgument(returnByValue); 141 function.appendArgument(returnByValue);
142 function.appendArgument(generatePreview); 142 function.appendArgument(generatePreview);
143 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); 143 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails);
144 } 144 }
145 145
146 void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje ctId, const String& expression, const String& arguments, bool returnByValue, boo l generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, OptionalValu e<bool>* wasThrown) 146 void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje ctId, const String& expression, const String& arguments, bool returnByValue, boo l generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<bool>* wasThrown)
147 { 147 {
148 v8::HandleScope handles(m_isolate); 148 v8::HandleScope handles(m_isolate);
149 V8FunctionCall function(m_client, context(), v8Value(), "callFunctionOn"); 149 V8FunctionCall function(m_client, context(), v8Value(), "callFunctionOn");
150 function.appendArgument(objectId); 150 function.appendArgument(objectId);
151 function.appendArgument(expression); 151 function.appendArgument(expression);
152 function.appendArgument(arguments); 152 function.appendArgument(arguments);
153 function.appendArgument(returnByValue); 153 function.appendArgument(returnByValue);
154 function.appendArgument(generatePreview); 154 function.appendArgument(generatePreview);
155 makeEvalCall(errorString, function, result, wasThrown); 155 makeEvalCall(errorString, function, result, wasThrown);
156 } 156 }
157 157
158 void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, v8::Local<v8: :Object> callFrames, bool isAsyncCallStack, const String& callFrameId, const Str ing& expression, const String& objectGroup, bool includeCommandLineAPI, bool ret urnByValue, bool generatePreview, OwnPtr<RemoteObject>* result, OptionalValue<bo ol>* wasThrown, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDetails) 158 void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, v8::Local<v8: :Object> callFrames, bool isAsyncCallStack, const String& callFrameId, const Str ing& expression, const String& objectGroup, bool includeCommandLineAPI, bool ret urnByValue, bool generatePreview, OwnPtr<RemoteObject>* result, Maybe<bool>* was Thrown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
159 { 159 {
160 v8::HandleScope handles(m_isolate); 160 v8::HandleScope handles(m_isolate);
161 V8FunctionCall function(m_client, context(), v8Value(), "evaluateOnCallFrame "); 161 V8FunctionCall function(m_client, context(), v8Value(), "evaluateOnCallFrame ");
162 function.appendArgument(callFrames); 162 function.appendArgument(callFrames);
163 function.appendArgument(isAsyncCallStack); 163 function.appendArgument(isAsyncCallStack);
164 function.appendArgument(callFrameId); 164 function.appendArgument(callFrameId);
165 function.appendArgument(expression); 165 function.appendArgument(expression);
166 function.appendArgument(objectGroup); 166 function.appendArgument(objectGroup);
167 function.appendArgument(includeCommandLineAPI); 167 function.appendArgument(includeCommandLineAPI);
168 function.appendArgument(returnByValue); 168 function.appendArgument(returnByValue);
(...skipping 14 matching lines...) Expand all
183 resultValue->asString(errorString); 183 resultValue->asString(errorString);
184 } else { 184 } else {
185 bool value; 185 bool value;
186 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); 186 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value);
187 } 187 }
188 return; 188 return;
189 } 189 }
190 *errorString = "Internal error"; 190 *errorString = "Internal error";
191 } 191 }
192 192
193 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, OwnPtr<Array<protocol::Debugger:: Location>>* positions) 193 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, Maybe<Array<protocol::Debugger::L ocation>>* positions)
194 { 194 {
195 v8::HandleScope handles(m_isolate); 195 v8::HandleScope handles(m_isolate);
196 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions" ); 196 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions" );
197 function.appendArgument(callFrames); 197 function.appendArgument(callFrames);
198 function.appendArgument(callFrameId); 198 function.appendArgument(callFrameId);
199 RefPtr<JSONValue> resultValue; 199 RefPtr<JSONValue> resultValue;
200 makeCall(function, &resultValue); 200 makeCall(function, &resultValue);
201 if (resultValue) { 201 if (resultValue) {
202 if (resultValue->type() == JSONValue::TypeString) { 202 if (resultValue->type() == JSONValue::TypeString) {
203 resultValue->asString(errorString); 203 resultValue->asString(errorString);
204 return; 204 return;
205 } 205 }
206 if (resultValue->type() == JSONValue::TypeArray) { 206 if (resultValue->type() == JSONValue::TypeArray) {
207 *positions = Array<protocol::Debugger::Location>::runtimeCast(result Value.release()); 207 *positions = Array<protocol::Debugger::Location>::runtimeCast(result Value.release());
208 return; 208 return;
209 } 209 }
210 } 210 }
211 *errorString = "Internal error"; 211 *errorString = "Internal error";
212 } 212 }
213 213
214 void InjectedScript::setVariableValue(ErrorString* errorString, 214 void InjectedScript::setVariableValue(ErrorString* errorString,
215 v8::Local<v8::Object> callFrames, 215 v8::Local<v8::Object> callFrames,
216 const protocol::OptionalValue<String>& callFrameIdOpt, 216 const protocol::Maybe<String>& callFrameIdOpt,
217 const protocol::OptionalValue<String>& functionObjectIdOpt, 217 const protocol::Maybe<String>& functionObjectIdOpt,
218 int scopeNumber, 218 int scopeNumber,
219 const String& variableName, 219 const String& variableName,
220 const String& newValueStr) 220 const String& newValueStr)
221 { 221 {
222 v8::HandleScope handles(m_isolate); 222 v8::HandleScope handles(m_isolate);
223 V8FunctionCall function(m_client, context(), v8Value(), "setVariableValue"); 223 V8FunctionCall function(m_client, context(), v8Value(), "setVariableValue");
224 if (callFrameIdOpt.hasValue()) { 224 if (callFrameIdOpt.isJust()) {
225 function.appendArgument(callFrames); 225 function.appendArgument(callFrames);
226 function.appendArgument(callFrameIdOpt.get()); 226 function.appendArgument(callFrameIdOpt.fromJust());
227 } else { 227 } else {
228 function.appendArgument(false); 228 function.appendArgument(false);
229 function.appendArgument(false); 229 function.appendArgument(false);
230 } 230 }
231 if (functionObjectIdOpt.hasValue()) 231 if (functionObjectIdOpt.isJust())
232 function.appendArgument(functionObjectIdOpt.get()); 232 function.appendArgument(functionObjectIdOpt.fromJust());
233 else 233 else
234 function.appendArgument(false); 234 function.appendArgument(false);
235 function.appendArgument(scopeNumber); 235 function.appendArgument(scopeNumber);
236 function.appendArgument(variableName); 236 function.appendArgument(variableName);
237 function.appendArgument(newValueStr); 237 function.appendArgument(newValueStr);
238 RefPtr<JSONValue> resultValue; 238 RefPtr<JSONValue> resultValue;
239 makeCall(function, &resultValue); 239 makeCall(function, &resultValue);
240 if (!resultValue) { 240 if (!resultValue) {
241 *errorString = "Internal error"; 241 *errorString = "Internal error";
242 return; 242 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 RefPtr<JSONValue> resultValue; 286 RefPtr<JSONValue> resultValue;
287 makeCall(function, &resultValue); 287 makeCall(function, &resultValue);
288 if (!resultValue || resultValue->type() != JSONValue::TypeArray) { 288 if (!resultValue || resultValue->type() != JSONValue::TypeArray) {
289 if (!resultValue->asString(errorString)) 289 if (!resultValue->asString(errorString))
290 *errorString = "Internal error"; 290 *errorString = "Internal error";
291 return; 291 return;
292 } 292 }
293 *result = Array<CollectionEntry>::runtimeCast(resultValue.release()); 293 *result = Array<CollectionEntry>::runtimeCast(resultValue.release());
294 } 294 }
295 295
296 void InjectedScript::getProperties(ErrorString* errorString, const String& objec tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnP tr<Array<PropertyDescriptor>>* properties, OwnPtr<protocol::Runtime::ExceptionDe tails>* exceptionDetails) 296 void InjectedScript::getProperties(ErrorString* errorString, const String& objec tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnP tr<Array<PropertyDescriptor>>* properties, Maybe<protocol::Runtime::ExceptionDet ails>* exceptionDetails)
297 { 297 {
298 v8::HandleScope handles(m_isolate); 298 v8::HandleScope handles(m_isolate);
299 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); 299 V8FunctionCall function(m_client, context(), v8Value(), "getProperties");
300 function.appendArgument(objectId); 300 function.appendArgument(objectId);
301 function.appendArgument(ownProperties); 301 function.appendArgument(ownProperties);
302 function.appendArgument(accessorPropertiesOnly); 302 function.appendArgument(accessorPropertiesOnly);
303 function.appendArgument(generatePreview); 303 function.appendArgument(generatePreview);
304 304
305 RefPtr<JSONValue> result; 305 RefPtr<JSONValue> result;
306 makeCallWithExceptionDetails(function, &result, exceptionDetails); 306 makeCallWithExceptionDetails(function, &result, exceptionDetails);
307 if (*exceptionDetails) { 307 if (exceptionDetails->isJust()) {
308 // FIXME: make properties optional 308 // FIXME: make properties optional
309 *properties = Array<PropertyDescriptor>::create(); 309 *properties = Array<PropertyDescriptor>::create();
310 return; 310 return;
311 } 311 }
312 if (!result || result->type() != JSONValue::TypeArray) { 312 if (!result || result->type() != JSONValue::TypeArray) {
313 *errorString = "Internal error"; 313 *errorString = "Internal error";
314 return; 314 return;
315 } 315 }
316 *properties = Array<PropertyDescriptor>::runtimeCast(result.release()); 316 *properties = Array<PropertyDescriptor>::runtimeCast(result.release());
317 } 317 }
318 318
319 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, OwnPtr<Array<InternalPropertyDescriptor>>* properties, OwnPtr<proto col::Runtime::ExceptionDetails>* exceptionDetails) 319 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco l::Runtime::ExceptionDetails>* exceptionDetails)
320 { 320 {
321 v8::HandleScope handles(m_isolate); 321 v8::HandleScope handles(m_isolate);
322 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti es"); 322 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti es");
323 function.appendArgument(objectId); 323 function.appendArgument(objectId);
324 324
325 RefPtr<JSONValue> result; 325 RefPtr<JSONValue> result;
326 makeCallWithExceptionDetails(function, &result, exceptionDetails); 326 makeCallWithExceptionDetails(function, &result, exceptionDetails);
327 if (*exceptionDetails) 327 if (exceptionDetails->isJust())
328 return; 328 return;
329 if (!result || result->type() != JSONValue::TypeArray) { 329 if (!result || result->type() != JSONValue::TypeArray) {
330 *errorString = "Internal error"; 330 *errorString = "Internal error";
331 return; 331 return;
332 } 332 }
333 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc riptor>::runtimeCast(result.release()); 333 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc riptor>::runtimeCast(result.release());
334 if (array->length() > 0) 334 if (array->length() > 0)
335 *properties = array.release(); 335 *properties = array.release();
336 } 336 }
337 337
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 ASSERT(!hadException); 491 ASSERT(!hadException);
492 if (!hadException) { 492 if (!hadException) {
493 *result = toJSONValue(function.context(), resultValue); 493 *result = toJSONValue(function.context(), resultValue);
494 if (!*result) 494 if (!*result)
495 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 495 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
496 } else { 496 } else {
497 *result = JSONString::create("Exception while making a call."); 497 *result = JSONString::create("Exception while making a call.");
498 } 498 }
499 } 499 }
500 500
501 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func tion, OwnPtr<protocol::Runtime::RemoteObject>* objectResult, OptionalValue<bool> * wasThrown, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDetails) 501 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func tion, OwnPtr<protocol::Runtime::RemoteObject>* objectResult, Maybe<bool>* wasThr own, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
502 { 502 {
503 RefPtr<JSONValue> result; 503 RefPtr<JSONValue> result;
504 makeCall(function, &result); 504 makeCall(function, &result);
505 if (!result) { 505 if (!result) {
506 *errorString = "Internal error: result value is empty"; 506 *errorString = "Internal error: result value is empty";
507 return; 507 return;
508 } 508 }
509 if (result->type() == JSONValue::TypeString) { 509 if (result->type() == JSONValue::TypeString) {
510 result->asString(errorString); 510 result->asString(errorString);
511 ASSERT(errorString->length()); 511 ASSERT(errorString->length());
(...skipping 12 matching lines...) Expand all
524 } 524 }
525 if (wasThrownVal) { 525 if (wasThrownVal) {
526 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails"); 526 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails");
527 if (objectExceptionDetails) 527 if (objectExceptionDetails)
528 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e()); 528 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e());
529 } 529 }
530 *objectResult = protocol::Runtime::RemoteObject::runtimeCast(resultObj); 530 *objectResult = protocol::Runtime::RemoteObject::runtimeCast(resultObj);
531 *wasThrown = wasThrownVal; 531 *wasThrown = wasThrownVal;
532 } 532 }
533 533
534 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP tr<JSONValue>* result, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDet ails) 534 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP tr<JSONValue>* result, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDeta ils)
535 { 535 {
536 v8::HandleScope handles(m_isolate); 536 v8::HandleScope handles(m_isolate);
537 v8::Context::Scope scope(context()); 537 v8::Context::Scope scope(context());
538 v8::TryCatch tryCatch(m_isolate); 538 v8::TryCatch tryCatch(m_isolate);
539 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); 539 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
540 if (tryCatch.HasCaught()) { 540 if (tryCatch.HasCaught()) {
541 v8::Local<v8::Message> message = tryCatch.Message(); 541 v8::Local<v8::Message> message = tryCatch.Message();
542 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get ()) : "Internal error"; 542 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get ()) : "Internal error";
543 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex t(text).build(); 543 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex t(text).build();
544 } else { 544 } else {
545 *result = toJSONValue(function.context(), resultValue); 545 *result = toJSONValue(function.context(), resultValue);
546 if (!*result) 546 if (!*result)
547 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 547 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
548 } 548 }
549 } 549 }
550 550
551 void InjectedScript::dispose() 551 void InjectedScript::dispose()
552 { 552 {
553 m_manager->discardInjectedScript(m_contextId); 553 m_manager->discardInjectedScript(m_contextId);
554 } 554 }
555 555
556 } // namespace blink 556 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698