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

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

Issue 1734693003: Revert of DevTools: simplify JSONValues API, prepare to the OwnPtr migration. (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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<JSONArray> stackTrace = object->getArray("stackTrace"); 76 RefPtr<JSONArray> 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<JSONObject> stackFrame = JSONObject::cast(stackTrace->get(i)) ; 80 RefPtr<JSONObject> stackFrame = stackTrace->get(i)->asObject();
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->asArray());
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::OptionalValue<String>& callFrameIdOpt,
217 const protocol::OptionalValue<String>& functionObjectIdOpt, 217 const protocol::OptionalValue<String>& functionObjectIdOpt,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 v8::HandleScope handles(m_isolate); 253 v8::HandleScope handles(m_isolate);
254 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails" ); 254 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails" );
255 function.appendArgument(functionId); 255 function.appendArgument(functionId);
256 RefPtr<JSONValue> resultValue; 256 RefPtr<JSONValue> resultValue;
257 makeCall(function, &resultValue); 257 makeCall(function, &resultValue);
258 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { 258 if (!resultValue || resultValue->type() != JSONValue::TypeObject) {
259 if (!resultValue->asString(errorString)) 259 if (!resultValue->asString(errorString))
260 *errorString = "Internal error"; 260 *errorString = "Internal error";
261 return; 261 return;
262 } 262 }
263 *result = FunctionDetails::runtimeCast(resultValue); 263 *result = FunctionDetails::runtimeCast(resultValue->asObject());
264 } 264 }
265 265
266 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, OwnPtr<GeneratorObjectDetails>* result) 266 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, OwnPtr<GeneratorObjectDetails>* result)
267 { 267 {
268 v8::HandleScope handles(m_isolate); 268 v8::HandleScope handles(m_isolate);
269 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD etails"); 269 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD etails");
270 function.appendArgument(objectId); 270 function.appendArgument(objectId);
271 RefPtr<JSONValue> resultValue; 271 RefPtr<JSONValue> resultValue;
272 makeCall(function, &resultValue); 272 makeCall(function, &resultValue);
273 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { 273 if (!resultValue || resultValue->type() != JSONValue::TypeObject) {
274 if (!resultValue->asString(errorString)) 274 if (!resultValue->asString(errorString))
275 *errorString = "Internal error"; 275 *errorString = "Internal error";
276 return; 276 return;
277 } 277 }
278 *result = GeneratorObjectDetails::runtimeCast(resultValue); 278 *result = GeneratorObjectDetails::runtimeCast(resultValue->asObject());
279 } 279 }
280 280
281 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, OwnPtr<Array<CollectionEntry>>* result) 281 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, OwnPtr<Array<CollectionEntry>>* result)
282 { 282 {
283 v8::HandleScope handles(m_isolate); 283 v8::HandleScope handles(m_isolate);
284 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie s"); 284 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie s");
285 function.appendArgument(objectId); 285 function.appendArgument(objectId);
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->asArray());
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, OwnPtr<protocol::Runtime::ExceptionDe tails>* 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) {
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->asArray());
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, OwnPtr<Array<InternalPropertyDescriptor>>* properties, OwnPtr<proto col::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)
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->asArray());
334 if (array->length() > 0) 334 if (array->length() > 0)
335 *properties = array.release(); 335 *properties = array.release();
336 } 336 }
337 337
338 void InjectedScript::releaseObject(const String& objectId) 338 void InjectedScript::releaseObject(const String& objectId)
339 { 339 {
340 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); 340 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId);
341 if (!parsedObjectId) 341 if (!parsedObjectId)
342 return; 342 return;
343 RefPtr<JSONObject> object = JSONObject::cast(parsedObjectId); 343 RefPtr<JSONObject> object;
344 if (!object) 344 if (!parsedObjectId->asObject(&object))
345 return; 345 return;
346 int boundId = 0; 346 int boundId = 0;
347 if (!object->getNumber("id", &boundId)) 347 if (!object->getNumber("id", &boundId))
348 return; 348 return;
349 m_native->unbind(boundId); 349 m_native->unbind(boundId);
350 } 350 }
351 351
352 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script > script, bool includeCommandLineAPI) 352 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script > script, bool includeCommandLineAPI)
353 { 353 {
354 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI Symbol(m_isolate); 354 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI Symbol(m_isolate);
(...skipping 17 matching lines...) Expand all
372 { 372 {
373 v8::HandleScope handles(m_isolate); 373 v8::HandleScope handles(m_isolate);
374 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); 374 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames");
375 function.appendArgument(callFrames); 375 function.appendArgument(callFrames);
376 function.appendArgument(asyncOrdinal); 376 function.appendArgument(asyncOrdinal);
377 bool hadException = false; 377 bool hadException = false;
378 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); 378 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException);
379 ASSERT(!hadException); 379 ASSERT(!hadException);
380 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue); 380 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue);
381 if (result && result->type() == JSONValue::TypeArray) 381 if (result && result->type() == JSONValue::TypeArray)
382 return Array<CallFrame>::runtimeCast(result.release()); 382 return Array<CallFrame>::runtimeCast(result->asArray());
383 return Array<CallFrame>::create(); 383 return Array<CallFrame>::create();
384 } 384 }
385 385
386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local <v8::Value> value, const String& groupName, bool generatePreview) const 386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local <v8::Value> value, const String& groupName, bool generatePreview) const
387 { 387 {
388 v8::HandleScope handles(m_isolate); 388 v8::HandleScope handles(m_isolate);
389 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); 389 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject");
390 function.appendArgument(value); 390 function.appendArgument(value);
391 function.appendArgument(groupName); 391 function.appendArgument(groupName);
392 function.appendArgument(canAccessInspectedWindow()); 392 function.appendArgument(canAccessInspectedWindow());
393 function.appendArgument(generatePreview); 393 function.appendArgument(generatePreview);
394 bool hadException = false; 394 bool hadException = false;
395 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; 395 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ;
396 if (hadException) 396 if (hadException)
397 return nullptr; 397 return nullptr;
398 return protocol::Runtime::RemoteObject::runtimeCast(toJSONValue(context(), r )); 398 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject();
399 return protocol::Runtime::RemoteObject::runtimeCast(rawResult);
399 } 400 }
400 401
401 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const 402 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const
402 { 403 {
403 v8::HandleScope handles(m_isolate); 404 v8::HandleScope handles(m_isolate);
404 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); 405 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable");
405 function.appendArgument(canAccessInspectedWindow()); 406 function.appendArgument(canAccessInspectedWindow());
406 function.appendArgument(table); 407 function.appendArgument(table);
407 if (columns.IsEmpty()) 408 if (columns.IsEmpty())
408 function.appendArgument(false); 409 function.appendArgument(false);
409 else 410 else
410 function.appendArgument(columns); 411 function.appendArgument(columns);
411 bool hadException = false; 412 bool hadException = false;
412 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException ); 413 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException );
413 if (hadException) 414 if (hadException)
414 return nullptr; 415 return nullptr;
415 return protocol::Runtime::RemoteObject::runtimeCast(toJSONValue(context(), r )); 416 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject();
417 return protocol::Runtime::RemoteObject::runtimeCast(rawResult);
416 } 418 }
417 419
418 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const 420 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const
419 { 421 {
420 return m_native->objectForId(objectId.id()); 422 return m_native->objectForId(objectId.id());
421 } 423 }
422 424
423 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const 425 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const
424 { 426 {
425 return m_native->groupName(objectId.id()); 427 return m_native->groupName(objectId.id());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 makeCall(function, &result); 506 makeCall(function, &result);
505 if (!result) { 507 if (!result) {
506 *errorString = "Internal error: result value is empty"; 508 *errorString = "Internal error: result value is empty";
507 return; 509 return;
508 } 510 }
509 if (result->type() == JSONValue::TypeString) { 511 if (result->type() == JSONValue::TypeString) {
510 result->asString(errorString); 512 result->asString(errorString);
511 ASSERT(errorString->length()); 513 ASSERT(errorString->length());
512 return; 514 return;
513 } 515 }
514 RefPtr<JSONObject> resultPair = JSONObject::cast(result); 516 RefPtr<JSONObject> resultPair = result->asObject();
515 if (!resultPair) { 517 if (!resultPair) {
516 *errorString = "Internal error: result is not an Object"; 518 *errorString = "Internal error: result is not an Object";
517 return; 519 return;
518 } 520 }
519 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); 521 RefPtr<JSONObject> resultObj = resultPair->getObject("result");
520 bool wasThrownVal = false; 522 bool wasThrownVal = false;
521 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { 523 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
522 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; 524 *errorString = "Internal error: result is not a pair of value and wasThr own flag";
523 return; 525 return;
524 } 526 }
(...skipping 22 matching lines...) Expand all
547 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 549 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
548 } 550 }
549 } 551 }
550 552
551 void InjectedScript::dispose() 553 void InjectedScript::dispose()
552 { 554 {
553 m_manager->discardInjectedScript(m_contextId); 555 m_manager->discardInjectedScript(m_contextId);
554 } 556 }
555 557
556 } // namespace blink 558 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698