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

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

Issue 1745423002: DevTools: migrate protocol values from RefPtr to OwnPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::Maybe; 53 using blink::protocol::Maybe;
54 54
55 namespace blink { 55 namespace blink {
56 56
57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(PassRe fPtr<protocol::DictionaryValue> object) 57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(protoc ol::DictionaryValue* 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();
64 String url; 64 String url;
65 if (object->getString("url", &url)) 65 if (object->getString("url", &url))
66 exceptionDetails->setUrl(url); 66 exceptionDetails->setUrl(url);
67 int line = 0; 67 int line = 0;
68 if (object->getNumber("line", &line)) 68 if (object->getNumber("line", &line))
69 exceptionDetails->setLine(line); 69 exceptionDetails->setLine(line);
70 int column = 0; 70 int column = 0;
71 if (object->getNumber("column", &column)) 71 if (object->getNumber("column", &column))
72 exceptionDetails->setColumn(column); 72 exceptionDetails->setColumn(column);
73 int originScriptId = 0; 73 int originScriptId = 0;
74 object->getNumber("scriptId", &originScriptId); 74 object->getNumber("scriptId", &originScriptId);
75 75
76 RefPtr<protocol::ListValue> stackTrace = object->getArray("stackTrace"); 76 protocol::ListValue* stackTrace = object->getArray("stackTrace");
77 if (stackTrace && stackTrace->length() > 0) { 77 if (stackTrace && stackTrace->length() > 0) {
78 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol: :Array<protocol::Runtime::CallFrame>::create(); 78 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol: :Array<protocol::Runtime::CallFrame>::create();
79 for (unsigned i = 0; i < stackTrace->length(); ++i) { 79 for (unsigned i = 0; i < stackTrace->length(); ++i) {
80 RefPtr<protocol::DictionaryValue> stackFrame = protocol::DictionaryV alue::cast(stackTrace->get(i)); 80 protocol::DictionaryValue* stackFrame = protocol::DictionaryValue::c ast(stackTrace->get(i));
81 int lineNumber = 0; 81 int lineNumber = 0;
82 stackFrame->getNumber("lineNumber", &lineNumber); 82 stackFrame->getNumber("lineNumber", &lineNumber);
83 int column = 0; 83 int column = 0;
84 stackFrame->getNumber("column", &column); 84 stackFrame->getNumber("column", &column);
85 int scriptId = 0; 85 int scriptId = 0;
86 stackFrame->getNumber("scriptId", &scriptId); 86 stackFrame->getNumber("scriptId", &scriptId);
87 if (i == 0 && scriptId == originScriptId) 87 if (i == 0 && scriptId == originScriptId)
88 originScriptId = 0; 88 originScriptId = 0;
89 89
90 String sourceURL; 90 String sourceURL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) 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 *result = makeEvalCall(errorString, function, 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, Maybe<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 *result = makeEvalCall(errorString, function, 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, Maybe<bool>* was Thrown, Maybe<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);
169 function.appendArgument(generatePreview); 169 function.appendArgument(generatePreview);
170 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); 170 *result = makeEvalCall(errorString, function, wasThrown, exceptionDetails);
171 } 171 }
172 172
173 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object > callFrames, const String& callFrameId) 173 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object > callFrames, const String& callFrameId)
174 { 174 {
175 v8::HandleScope handles(m_isolate); 175 v8::HandleScope handles(m_isolate);
176 V8FunctionCall function(m_client, context(), v8Value(), "restartFrame"); 176 V8FunctionCall function(m_client, context(), v8Value(), "restartFrame");
177 function.appendArgument(callFrames); 177 function.appendArgument(callFrames);
178 function.appendArgument(callFrameId); 178 function.appendArgument(callFrameId);
179 RefPtr<protocol::Value> resultValue; 179 OwnPtr<protocol::Value> resultValue = makeCall(function);
180 makeCall(function, &resultValue);
181 if (resultValue) { 180 if (resultValue) {
182 if (resultValue->type() == protocol::Value::TypeString) { 181 if (resultValue->type() == protocol::Value::TypeString) {
183 resultValue->asString(errorString); 182 resultValue->asString(errorString);
184 } else { 183 } else {
185 bool value; 184 bool value;
186 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); 185 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value);
187 } 186 }
188 return; 187 return;
189 } 188 }
190 *errorString = "Internal error"; 189 *errorString = "Internal error";
191 } 190 }
192 191
193 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, Maybe<Array<protocol::Debugger::L ocation>>* positions) 192 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, Maybe<Array<protocol::Debugger::L ocation>>* positions)
194 { 193 {
195 v8::HandleScope handles(m_isolate); 194 v8::HandleScope handles(m_isolate);
196 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions" ); 195 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions" );
197 function.appendArgument(callFrames); 196 function.appendArgument(callFrames);
198 function.appendArgument(callFrameId); 197 function.appendArgument(callFrameId);
199 RefPtr<protocol::Value> resultValue; 198 OwnPtr<protocol::Value> resultValue = makeCall(function);
200 makeCall(function, &resultValue);
201 if (resultValue) { 199 if (resultValue) {
202 if (resultValue->type() == protocol::Value::TypeString) { 200 if (resultValue->type() == protocol::Value::TypeString) {
203 resultValue->asString(errorString); 201 resultValue->asString(errorString);
204 return; 202 return;
205 } 203 }
206 if (resultValue->type() == protocol::Value::TypeArray) { 204 if (resultValue->type() == protocol::Value::TypeArray) {
207 protocol::ErrorSupport errors(errorString); 205 protocol::ErrorSupport errors(errorString);
208 *positions = Array<protocol::Debugger::Location>::parse(resultValue. release(), &errors); 206 *positions = Array<protocol::Debugger::Location>::parse(resultValue. get(), &errors);
209 return; 207 return;
210 } 208 }
211 } 209 }
212 *errorString = "Internal error"; 210 *errorString = "Internal error";
213 } 211 }
214 212
215 void InjectedScript::setVariableValue(ErrorString* errorString, 213 void InjectedScript::setVariableValue(ErrorString* errorString,
216 v8::Local<v8::Object> callFrames, 214 v8::Local<v8::Object> callFrames,
217 const protocol::Maybe<String>& callFrameIdOpt, 215 const protocol::Maybe<String>& callFrameIdOpt,
218 const protocol::Maybe<String>& functionObjectIdOpt, 216 const protocol::Maybe<String>& functionObjectIdOpt,
(...skipping 10 matching lines...) Expand all
229 function.appendArgument(false); 227 function.appendArgument(false);
230 function.appendArgument(false); 228 function.appendArgument(false);
231 } 229 }
232 if (functionObjectIdOpt.isJust()) 230 if (functionObjectIdOpt.isJust())
233 function.appendArgument(functionObjectIdOpt.fromJust()); 231 function.appendArgument(functionObjectIdOpt.fromJust());
234 else 232 else
235 function.appendArgument(false); 233 function.appendArgument(false);
236 function.appendArgument(scopeNumber); 234 function.appendArgument(scopeNumber);
237 function.appendArgument(variableName); 235 function.appendArgument(variableName);
238 function.appendArgument(newValueStr); 236 function.appendArgument(newValueStr);
239 RefPtr<protocol::Value> resultValue; 237 OwnPtr<protocol::Value> resultValue = makeCall(function);
240 makeCall(function, &resultValue);
241 if (!resultValue) { 238 if (!resultValue) {
242 *errorString = "Internal error"; 239 *errorString = "Internal error";
243 return; 240 return;
244 } 241 }
245 if (resultValue->type() == protocol::Value::TypeString) { 242 if (resultValue->type() == protocol::Value::TypeString) {
246 resultValue->asString(errorString); 243 resultValue->asString(errorString);
247 return; 244 return;
248 } 245 }
249 // Normal return. 246 // Normal return.
250 } 247 }
251 248
252 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, OwnPtr<FunctionDetails>* result) 249 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, OwnPtr<FunctionDetails>* result)
253 { 250 {
254 v8::HandleScope handles(m_isolate); 251 v8::HandleScope handles(m_isolate);
255 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails" ); 252 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails" );
256 function.appendArgument(functionId); 253 function.appendArgument(functionId);
257 RefPtr<protocol::Value> resultValue; 254 OwnPtr<protocol::Value> resultValue = makeCall(function);
258 makeCall(function, &resultValue);
259 protocol::ErrorSupport errors(errorString); 255 protocol::ErrorSupport errors(errorString);
260 *result = FunctionDetails::parse(resultValue, &errors); 256 *result = FunctionDetails::parse(resultValue.get(), &errors);
261 } 257 }
262 258
263 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, OwnPtr<GeneratorObjectDetails>* result) 259 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, OwnPtr<GeneratorObjectDetails>* result)
264 { 260 {
265 v8::HandleScope handles(m_isolate); 261 v8::HandleScope handles(m_isolate);
266 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD etails"); 262 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD etails");
267 function.appendArgument(objectId); 263 function.appendArgument(objectId);
268 RefPtr<protocol::Value> resultValue; 264 OwnPtr<protocol::Value> resultValue = makeCall(function);
269 makeCall(function, &resultValue);
270 protocol::ErrorSupport errors(errorString); 265 protocol::ErrorSupport errors(errorString);
271 *result = GeneratorObjectDetails::parse(resultValue, &errors); 266 *result = GeneratorObjectDetails::parse(resultValue.get(), &errors);
272 } 267 }
273 268
274 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, OwnPtr<Array<CollectionEntry>>* result) 269 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, OwnPtr<Array<CollectionEntry>>* result)
275 { 270 {
276 v8::HandleScope handles(m_isolate); 271 v8::HandleScope handles(m_isolate);
277 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie s"); 272 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie s");
278 function.appendArgument(objectId); 273 function.appendArgument(objectId);
279 RefPtr<protocol::Value> resultValue; 274 OwnPtr<protocol::Value> resultValue = makeCall(function);
280 makeCall(function, &resultValue);
281 protocol::ErrorSupport errors(errorString); 275 protocol::ErrorSupport errors(errorString);
282 *result = Array<CollectionEntry>::parse(resultValue, &errors); 276 *result = Array<CollectionEntry>::parse(resultValue.get(), &errors);
283 } 277 }
284 278
285 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) 279 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)
286 { 280 {
287 v8::HandleScope handles(m_isolate); 281 v8::HandleScope handles(m_isolate);
288 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); 282 V8FunctionCall function(m_client, context(), v8Value(), "getProperties");
289 function.appendArgument(objectId); 283 function.appendArgument(objectId);
290 function.appendArgument(ownProperties); 284 function.appendArgument(ownProperties);
291 function.appendArgument(accessorPropertiesOnly); 285 function.appendArgument(accessorPropertiesOnly);
292 function.appendArgument(generatePreview); 286 function.appendArgument(generatePreview);
293 287
294 RefPtr<protocol::Value> result; 288 OwnPtr<protocol::Value> result = makeCallWithExceptionDetails(function, exce ptionDetails);
295 makeCallWithExceptionDetails(function, &result, exceptionDetails);
296 if (exceptionDetails->isJust()) { 289 if (exceptionDetails->isJust()) {
297 // FIXME: make properties optional 290 // FIXME: make properties optional
298 *properties = Array<PropertyDescriptor>::create(); 291 *properties = Array<PropertyDescriptor>::create();
299 return; 292 return;
300 } 293 }
301 protocol::ErrorSupport errors(errorString); 294 protocol::ErrorSupport errors(errorString);
302 *properties = Array<PropertyDescriptor>::parse(result.release(), &errors); 295 *properties = Array<PropertyDescriptor>::parse(result.get(), &errors);
303 } 296 }
304 297
305 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco l::Runtime::ExceptionDetails>* exceptionDetails) 298 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco l::Runtime::ExceptionDetails>* exceptionDetails)
306 { 299 {
307 v8::HandleScope handles(m_isolate); 300 v8::HandleScope handles(m_isolate);
308 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti es"); 301 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti es");
309 function.appendArgument(objectId); 302 function.appendArgument(objectId);
310 303
311 RefPtr<protocol::Value> result; 304 OwnPtr<protocol::Value> result = makeCallWithExceptionDetails(function, exce ptionDetails);
312 makeCallWithExceptionDetails(function, &result, exceptionDetails);
313 if (exceptionDetails->isJust()) 305 if (exceptionDetails->isJust())
314 return; 306 return;
315 protocol::ErrorSupport errors(errorString); 307 protocol::ErrorSupport errors(errorString);
316 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc riptor>::parse(result.release(), &errors); 308 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc riptor>::parse(result.get(), &errors);
317 if (!errors.hasErrors() && array->length() > 0) 309 if (!errors.hasErrors() && array->length() > 0)
318 *properties = array.release(); 310 *properties = array.release();
319 } 311 }
320 312
321 void InjectedScript::releaseObject(const String& objectId) 313 void InjectedScript::releaseObject(const String& objectId)
322 { 314 {
323 RefPtr<protocol::Value> parsedObjectId = protocol::parseJSON(objectId); 315 OwnPtr<protocol::Value> parsedObjectId = protocol::parseJSON(objectId);
324 if (!parsedObjectId) 316 if (!parsedObjectId)
325 return; 317 return;
326 RefPtr<protocol::DictionaryValue> object = protocol::DictionaryValue::cast(p arsedObjectId); 318 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get());
327 if (!object) 319 if (!object)
328 return; 320 return;
329 int boundId = 0; 321 int boundId = 0;
330 if (!object->getNumber("id", &boundId)) 322 if (!object->getNumber("id", &boundId))
331 return; 323 return;
332 m_native->unbind(boundId); 324 m_native->unbind(boundId);
333 } 325 }
334 326
335 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script > script, bool includeCommandLineAPI) 327 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script > script, bool includeCommandLineAPI)
336 { 328 {
(...skipping 16 matching lines...) Expand all
353 345
354 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal) 346 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal)
355 { 347 {
356 v8::HandleScope handles(m_isolate); 348 v8::HandleScope handles(m_isolate);
357 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); 349 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames");
358 function.appendArgument(callFrames); 350 function.appendArgument(callFrames);
359 function.appendArgument(asyncOrdinal); 351 function.appendArgument(asyncOrdinal);
360 bool hadException = false; 352 bool hadException = false;
361 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); 353 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException);
362 ASSERT(!hadException); 354 ASSERT(!hadException);
363 RefPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue) ; 355 OwnPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue) ;
364 protocol::ErrorSupport errors; 356 protocol::ErrorSupport errors;
365 if (result && result->type() == protocol::Value::TypeArray) 357 if (result && result->type() == protocol::Value::TypeArray)
366 return Array<CallFrame>::parse(result.release(), &errors); 358 return Array<CallFrame>::parse(result.get(), &errors);
367 return Array<CallFrame>::create(); 359 return Array<CallFrame>::create();
368 } 360 }
369 361
370 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local <v8::Value> value, const String& groupName, bool generatePreview) const 362 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local <v8::Value> value, const String& groupName, bool generatePreview) const
371 { 363 {
372 v8::HandleScope handles(m_isolate); 364 v8::HandleScope handles(m_isolate);
373 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); 365 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject");
374 function.appendArgument(value); 366 function.appendArgument(value);
375 function.appendArgument(groupName); 367 function.appendArgument(groupName);
376 function.appendArgument(canAccessInspectedWindow()); 368 function.appendArgument(canAccessInspectedWindow());
377 function.appendArgument(generatePreview); 369 function.appendArgument(generatePreview);
378 bool hadException = false; 370 bool hadException = false;
379 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; 371 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ;
380 if (hadException) 372 if (hadException)
381 return nullptr; 373 return nullptr;
382 protocol::ErrorSupport errors; 374 protocol::ErrorSupport errors;
383 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), r), &errors); 375 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), r). get(), &errors);
384 } 376 }
385 377
386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const 378 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const
387 { 379 {
388 v8::HandleScope handles(m_isolate); 380 v8::HandleScope handles(m_isolate);
389 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); 381 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable");
390 function.appendArgument(canAccessInspectedWindow()); 382 function.appendArgument(canAccessInspectedWindow());
391 function.appendArgument(table); 383 function.appendArgument(table);
392 if (columns.IsEmpty()) 384 if (columns.IsEmpty())
393 function.appendArgument(false); 385 function.appendArgument(false);
394 else 386 else
395 function.appendArgument(columns); 387 function.appendArgument(columns);
396 bool hadException = false; 388 bool hadException = false;
397 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException ); 389 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException );
398 if (hadException) 390 if (hadException)
399 return nullptr; 391 return nullptr;
400 protocol::ErrorSupport errors; 392 protocol::ErrorSupport errors;
401 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), r), &errors); 393 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), r). get(), &errors);
402 } 394 }
403 395
404 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const 396 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const
405 { 397 {
406 return m_native->objectForId(objectId.id()); 398 return m_native->objectForId(objectId.id());
407 } 399 }
408 400
409 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const 401 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const
410 { 402 {
411 return m_native->groupName(objectId.id()); 403 return m_native->groupName(objectId.id());
412 } 404 }
413 405
414 void InjectedScript::releaseObjectGroup(const String& objectGroup) 406 void InjectedScript::releaseObjectGroup(const String& objectGroup)
415 { 407 {
416 v8::HandleScope handles(m_isolate); 408 v8::HandleScope handles(m_isolate);
417 m_native->releaseObjectGroup(objectGroup); 409 m_native->releaseObjectGroup(objectGroup);
418 if (objectGroup == "console") { 410 if (objectGroup == "console") {
419 V8FunctionCall function(m_client, context(), v8Value(), "clearLastEvalua tionResult"); 411 V8FunctionCall function(m_client, context(), v8Value(), "clearLastEvalua tionResult");
420 bool hadException = false; 412 bool hadException = false;
421 callFunctionWithEvalEnabled(function, hadException); 413 callFunctionWithEvalEnabled(function, hadException);
422 ASSERT(!hadException); 414 ASSERT(!hadException);
423 } 415 }
424 } 416 }
425 417
426 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) 418 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled)
427 { 419 {
428 v8::HandleScope handles(m_isolate); 420 v8::HandleScope handles(m_isolate);
429 V8FunctionCall function(m_client, context(), v8Value(), "setCustomObjectForm atterEnabled"); 421 V8FunctionCall function(m_client, context(), v8Value(), "setCustomObjectForm atterEnabled");
430 function.appendArgument(enabled); 422 function.appendArgument(enabled);
431 RefPtr<protocol::Value> result; 423 makeCall(function);
432 makeCall(function, &result);
433 } 424 }
434 425
435 bool InjectedScript::canAccessInspectedWindow() const 426 bool InjectedScript::canAccessInspectedWindow() const
436 { 427 {
437 v8::Local<v8::Context> callingContext = m_isolate->GetCallingContext(); 428 v8::Local<v8::Context> callingContext = m_isolate->GetCallingContext();
438 if (callingContext.IsEmpty()) 429 if (callingContext.IsEmpty())
439 return true; 430 return true;
440 return m_client->callingContextCanAccessContext(callingContext, context()); 431 return m_client->callingContextCanAccessContext(callingContext, context());
441 } 432 }
442 433
(...skipping 14 matching lines...) Expand all
457 bool evalIsDisabled = !localContext->IsCodeGenerationFromStringsAllowed(); 448 bool evalIsDisabled = !localContext->IsCodeGenerationFromStringsAllowed();
458 // Temporarily enable allow evals for inspector. 449 // Temporarily enable allow evals for inspector.
459 if (evalIsDisabled) 450 if (evalIsDisabled)
460 localContext->AllowCodeGenerationFromStrings(true); 451 localContext->AllowCodeGenerationFromStrings(true);
461 v8::Local<v8::Value> resultValue = function.call(hadException); 452 v8::Local<v8::Value> resultValue = function.call(hadException);
462 if (evalIsDisabled) 453 if (evalIsDisabled)
463 localContext->AllowCodeGenerationFromStrings(false); 454 localContext->AllowCodeGenerationFromStrings(false);
464 return resultValue; 455 return resultValue;
465 } 456 }
466 457
467 void InjectedScript::makeCall(V8FunctionCall& function, RefPtr<protocol::Value>* result) 458 PassOwnPtr<protocol::Value> InjectedScript::makeCall(V8FunctionCall& function)
468 { 459 {
460 OwnPtr<protocol::Value> result;
469 if (!canAccessInspectedWindow()) { 461 if (!canAccessInspectedWindow()) {
470 *result = protocol::StringValue::create("Can not access given context.") ; 462 result = protocol::StringValue::create("Can not access given context.");
471 return; 463 return nullptr;
472 } 464 }
473 465
474 bool hadException = false; 466 bool hadException = false;
475 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had Exception); 467 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had Exception);
476 468
477 ASSERT(!hadException); 469 ASSERT(!hadException);
478 if (!hadException) { 470 if (!hadException) {
479 *result = toProtocolValue(function.context(), resultValue); 471 result = toProtocolValue(function.context(), resultValue);
480 if (!*result) 472 if (!result)
481 *result = protocol::StringValue::create(String::format("Object has t oo long reference chain(must not be longer than %d)", protocol::Value::maxDepth) ); 473 result = protocol::StringValue::create(String::format("Object has to o long reference chain(must not be longer than %d)", protocol::Value::maxDepth)) ;
482 } else { 474 } else {
483 *result = protocol::StringValue::create("Exception while making a call." ); 475 result = protocol::StringValue::create("Exception while making a call.") ;
484 } 476 }
477 return result.release();
485 } 478 }
486 479
487 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func tion, OwnPtr<protocol::Runtime::RemoteObject>* objectResult, Maybe<bool>* wasThr own, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) 480 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::makeEvalCall(ErrorSt ring* errorString, V8FunctionCall& function, Maybe<bool>* wasThrown, Maybe<proto col::Runtime::ExceptionDetails>* exceptionDetails)
488 { 481 {
489 RefPtr<protocol::Value> result; 482 OwnPtr<protocol::Value> result = makeCall(function);
490 makeCall(function, &result);
491 if (!result) { 483 if (!result) {
492 *errorString = "Internal error: result value is empty"; 484 *errorString = "Internal error: result value is empty";
493 return; 485 return nullptr;
494 } 486 }
495 if (result->type() == protocol::Value::TypeString) { 487 if (result->type() == protocol::Value::TypeString) {
496 result->asString(errorString); 488 result->asString(errorString);
497 ASSERT(errorString->length()); 489 ASSERT(errorString->length());
498 return; 490 return nullptr;
499 } 491 }
500 RefPtr<protocol::DictionaryValue> resultPair = protocol::DictionaryValue::ca st(result); 492 protocol::DictionaryValue* resultPair = protocol::DictionaryValue::cast(resu lt.get());
501 if (!resultPair) { 493 if (!resultPair) {
502 *errorString = "Internal error: result is not an Object"; 494 *errorString = "Internal error: result is not an Object";
503 return; 495 return nullptr;
504 } 496 }
505 RefPtr<protocol::DictionaryValue> resultObj = resultPair->getObject("result" ); 497 protocol::DictionaryValue* resultObj = resultPair->getObject("result");
506 bool wasThrownVal = false; 498 bool wasThrownVal = false;
507 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { 499 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
508 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; 500 *errorString = "Internal error: result is not a pair of value and wasThr own flag";
509 return; 501 return nullptr;
510 } 502 }
511 if (wasThrownVal) { 503 if (wasThrownVal) {
512 RefPtr<protocol::DictionaryValue> objectExceptionDetails = resultPair->g etObject("exceptionDetails"); 504 protocol::DictionaryValue* objectExceptionDetails = resultPair->getObjec t("exceptionDetails");
513 if (objectExceptionDetails) 505 if (objectExceptionDetails)
514 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e()); 506 *exceptionDetails = toExceptionDetails(objectExceptionDetails);
515 } 507 }
516 protocol::ErrorSupport errors(errorString); 508 protocol::ErrorSupport errors(errorString);
517 *objectResult = protocol::Runtime::RemoteObject::parse(resultObj, &errors);
518 *wasThrown = wasThrownVal; 509 *wasThrown = wasThrownVal;
510 return protocol::Runtime::RemoteObject::parse(resultObj, &errors);
519 } 511 }
520 512
521 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP tr<protocol::Value>* result, Maybe<protocol::Runtime::ExceptionDetails>* excepti onDetails) 513 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
522 { 514 {
515 OwnPtr<protocol::Value> result;
523 v8::HandleScope handles(m_isolate); 516 v8::HandleScope handles(m_isolate);
524 v8::Context::Scope scope(context()); 517 v8::Context::Scope scope(context());
525 v8::TryCatch tryCatch(m_isolate); 518 v8::TryCatch tryCatch(m_isolate);
526 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); 519 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
527 if (tryCatch.HasCaught()) { 520 if (tryCatch.HasCaught()) {
528 v8::Local<v8::Message> message = tryCatch.Message(); 521 v8::Local<v8::Message> message = tryCatch.Message();
529 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get ()) : "Internal error"; 522 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get ()) : "Internal error";
530 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex t(text).build(); 523 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex t(text).build();
531 } else { 524 } else {
532 *result = toProtocolValue(function.context(), resultValue); 525 result = toProtocolValue(function.context(), resultValue);
533 if (!*result) 526 if (!result)
534 *result = protocol::StringValue::create(String::format("Object has t oo long reference chain(must not be longer than %d)", protocol::Value::maxDepth) ); 527 result = protocol::StringValue::create(String::format("Object has to o long reference chain(must not be longer than %d)", protocol::Value::maxDepth)) ;
535 } 528 }
529 return result.release();
536 } 530 }
537 531
538 void InjectedScript::dispose() 532 void InjectedScript::dispose()
539 { 533 {
540 m_manager->discardInjectedScript(m_contextId); 534 m_manager->discardInjectedScript(m_contextId);
541 } 535 }
542 536
543 } // namespace blink 537 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698