| OLD | NEW |
| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 protocol::ErrorSupport errors(errorString); |
| 208 *positions = Array<protocol::Debugger::Location>::parse(resultValue.
release(), &errors); |
| 208 return; | 209 return; |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 *errorString = "Internal error"; | 212 *errorString = "Internal error"; |
| 212 } | 213 } |
| 213 | 214 |
| 214 void InjectedScript::setVariableValue(ErrorString* errorString, | 215 void InjectedScript::setVariableValue(ErrorString* errorString, |
| 215 v8::Local<v8::Object> callFrames, | 216 v8::Local<v8::Object> callFrames, |
| 216 const protocol::Maybe<String>& callFrameIdOpt, | 217 const protocol::Maybe<String>& callFrameIdOpt, |
| 217 const protocol::Maybe<String>& functionObjectIdOpt, | 218 const protocol::Maybe<String>& functionObjectIdOpt, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 248 // Normal return. | 249 // Normal return. |
| 249 } | 250 } |
| 250 | 251 |
| 251 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String&
functionId, OwnPtr<FunctionDetails>* result) | 252 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String&
functionId, OwnPtr<FunctionDetails>* result) |
| 252 { | 253 { |
| 253 v8::HandleScope handles(m_isolate); | 254 v8::HandleScope handles(m_isolate); |
| 254 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails"
); | 255 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails"
); |
| 255 function.appendArgument(functionId); | 256 function.appendArgument(functionId); |
| 256 RefPtr<JSONValue> resultValue; | 257 RefPtr<JSONValue> resultValue; |
| 257 makeCall(function, &resultValue); | 258 makeCall(function, &resultValue); |
| 258 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { | 259 protocol::ErrorSupport errors(errorString); |
| 259 if (!resultValue->asString(errorString)) | 260 *result = FunctionDetails::parse(resultValue, &errors); |
| 260 *errorString = "Internal error"; | |
| 261 return; | |
| 262 } | |
| 263 *result = FunctionDetails::runtimeCast(resultValue); | |
| 264 } | 261 } |
| 265 | 262 |
| 266 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S
tring& objectId, OwnPtr<GeneratorObjectDetails>* result) | 263 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S
tring& objectId, OwnPtr<GeneratorObjectDetails>* result) |
| 267 { | 264 { |
| 268 v8::HandleScope handles(m_isolate); | 265 v8::HandleScope handles(m_isolate); |
| 269 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD
etails"); | 266 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD
etails"); |
| 270 function.appendArgument(objectId); | 267 function.appendArgument(objectId); |
| 271 RefPtr<JSONValue> resultValue; | 268 RefPtr<JSONValue> resultValue; |
| 272 makeCall(function, &resultValue); | 269 makeCall(function, &resultValue); |
| 273 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { | 270 protocol::ErrorSupport errors(errorString); |
| 274 if (!resultValue->asString(errorString)) | 271 *result = GeneratorObjectDetails::parse(resultValue, &errors); |
| 275 *errorString = "Internal error"; | |
| 276 return; | |
| 277 } | |
| 278 *result = GeneratorObjectDetails::runtimeCast(resultValue); | |
| 279 } | 272 } |
| 280 | 273 |
| 281 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String
& objectId, OwnPtr<Array<CollectionEntry>>* result) | 274 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String
& objectId, OwnPtr<Array<CollectionEntry>>* result) |
| 282 { | 275 { |
| 283 v8::HandleScope handles(m_isolate); | 276 v8::HandleScope handles(m_isolate); |
| 284 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie
s"); | 277 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie
s"); |
| 285 function.appendArgument(objectId); | 278 function.appendArgument(objectId); |
| 286 RefPtr<JSONValue> resultValue; | 279 RefPtr<JSONValue> resultValue; |
| 287 makeCall(function, &resultValue); | 280 makeCall(function, &resultValue); |
| 288 if (!resultValue || resultValue->type() != JSONValue::TypeArray) { | 281 protocol::ErrorSupport errors(errorString); |
| 289 if (!resultValue->asString(errorString)) | 282 *result = Array<CollectionEntry>::parse(resultValue, &errors); |
| 290 *errorString = "Internal error"; | |
| 291 return; | |
| 292 } | |
| 293 *result = Array<CollectionEntry>::runtimeCast(resultValue.release()); | |
| 294 } | 283 } |
| 295 | 284 |
| 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) | 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) |
| 297 { | 286 { |
| 298 v8::HandleScope handles(m_isolate); | 287 v8::HandleScope handles(m_isolate); |
| 299 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); | 288 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); |
| 300 function.appendArgument(objectId); | 289 function.appendArgument(objectId); |
| 301 function.appendArgument(ownProperties); | 290 function.appendArgument(ownProperties); |
| 302 function.appendArgument(accessorPropertiesOnly); | 291 function.appendArgument(accessorPropertiesOnly); |
| 303 function.appendArgument(generatePreview); | 292 function.appendArgument(generatePreview); |
| 304 | 293 |
| 305 RefPtr<JSONValue> result; | 294 RefPtr<JSONValue> result; |
| 306 makeCallWithExceptionDetails(function, &result, exceptionDetails); | 295 makeCallWithExceptionDetails(function, &result, exceptionDetails); |
| 307 if (exceptionDetails->isJust()) { | 296 if (exceptionDetails->isJust()) { |
| 308 // FIXME: make properties optional | 297 // FIXME: make properties optional |
| 309 *properties = Array<PropertyDescriptor>::create(); | 298 *properties = Array<PropertyDescriptor>::create(); |
| 310 return; | 299 return; |
| 311 } | 300 } |
| 312 if (!result || result->type() != JSONValue::TypeArray) { | 301 protocol::ErrorSupport errors(errorString); |
| 313 *errorString = "Internal error"; | 302 *properties = Array<PropertyDescriptor>::parse(result.release(), &errors); |
| 314 return; | |
| 315 } | |
| 316 *properties = Array<PropertyDescriptor>::runtimeCast(result.release()); | |
| 317 } | 303 } |
| 318 | 304 |
| 319 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin
g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco
l::Runtime::ExceptionDetails>* exceptionDetails) | 305 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin
g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco
l::Runtime::ExceptionDetails>* exceptionDetails) |
| 320 { | 306 { |
| 321 v8::HandleScope handles(m_isolate); | 307 v8::HandleScope handles(m_isolate); |
| 322 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti
es"); | 308 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti
es"); |
| 323 function.appendArgument(objectId); | 309 function.appendArgument(objectId); |
| 324 | 310 |
| 325 RefPtr<JSONValue> result; | 311 RefPtr<JSONValue> result; |
| 326 makeCallWithExceptionDetails(function, &result, exceptionDetails); | 312 makeCallWithExceptionDetails(function, &result, exceptionDetails); |
| 327 if (exceptionDetails->isJust()) | 313 if (exceptionDetails->isJust()) |
| 328 return; | 314 return; |
| 329 if (!result || result->type() != JSONValue::TypeArray) { | 315 protocol::ErrorSupport errors(errorString); |
| 330 *errorString = "Internal error"; | 316 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc
riptor>::parse(result.release(), &errors); |
| 331 return; | 317 if (!errors.hasErrors() && array->length() > 0) |
| 332 } | |
| 333 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc
riptor>::runtimeCast(result.release()); | |
| 334 if (array->length() > 0) | |
| 335 *properties = array.release(); | 318 *properties = array.release(); |
| 336 } | 319 } |
| 337 | 320 |
| 338 void InjectedScript::releaseObject(const String& objectId) | 321 void InjectedScript::releaseObject(const String& objectId) |
| 339 { | 322 { |
| 340 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); | 323 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); |
| 341 if (!parsedObjectId) | 324 if (!parsedObjectId) |
| 342 return; | 325 return; |
| 343 RefPtr<JSONObject> object = JSONObject::cast(parsedObjectId); | 326 RefPtr<JSONObject> object = JSONObject::cast(parsedObjectId); |
| 344 if (!object) | 327 if (!object) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 371 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object
> callFrames, int asyncOrdinal) | 354 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object
> callFrames, int asyncOrdinal) |
| 372 { | 355 { |
| 373 v8::HandleScope handles(m_isolate); | 356 v8::HandleScope handles(m_isolate); |
| 374 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); | 357 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); |
| 375 function.appendArgument(callFrames); | 358 function.appendArgument(callFrames); |
| 376 function.appendArgument(asyncOrdinal); | 359 function.appendArgument(asyncOrdinal); |
| 377 bool hadException = false; | 360 bool hadException = false; |
| 378 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function,
hadException); | 361 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function,
hadException); |
| 379 ASSERT(!hadException); | 362 ASSERT(!hadException); |
| 380 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue); | 363 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue); |
| 364 protocol::ErrorSupport errors; |
| 381 if (result && result->type() == JSONValue::TypeArray) | 365 if (result && result->type() == JSONValue::TypeArray) |
| 382 return Array<CallFrame>::runtimeCast(result.release()); | 366 return Array<CallFrame>::parse(result.release(), &errors); |
| 383 return Array<CallFrame>::create(); | 367 return Array<CallFrame>::create(); |
| 384 } | 368 } |
| 385 | 369 |
| 386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local
<v8::Value> value, const String& groupName, bool generatePreview) const | 370 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local
<v8::Value> value, const String& groupName, bool generatePreview) const |
| 387 { | 371 { |
| 388 v8::HandleScope handles(m_isolate); | 372 v8::HandleScope handles(m_isolate); |
| 389 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); | 373 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); |
| 390 function.appendArgument(value); | 374 function.appendArgument(value); |
| 391 function.appendArgument(groupName); | 375 function.appendArgument(groupName); |
| 392 function.appendArgument(canAccessInspectedWindow()); | 376 function.appendArgument(canAccessInspectedWindow()); |
| 393 function.appendArgument(generatePreview); | 377 function.appendArgument(generatePreview); |
| 394 bool hadException = false; | 378 bool hadException = false; |
| 395 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException)
; | 379 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException)
; |
| 396 if (hadException) | 380 if (hadException) |
| 397 return nullptr; | 381 return nullptr; |
| 398 return protocol::Runtime::RemoteObject::runtimeCast(toJSONValue(context(), r
)); | 382 protocol::ErrorSupport errors; |
| 383 return protocol::Runtime::RemoteObject::parse(toJSONValue(context(), r), &er
rors); |
| 399 } | 384 } |
| 400 | 385 |
| 401 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<
v8::Value> table, v8::Local<v8::Value> columns) const | 386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<
v8::Value> table, v8::Local<v8::Value> columns) const |
| 402 { | 387 { |
| 403 v8::HandleScope handles(m_isolate); | 388 v8::HandleScope handles(m_isolate); |
| 404 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); | 389 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); |
| 405 function.appendArgument(canAccessInspectedWindow()); | 390 function.appendArgument(canAccessInspectedWindow()); |
| 406 function.appendArgument(table); | 391 function.appendArgument(table); |
| 407 if (columns.IsEmpty()) | 392 if (columns.IsEmpty()) |
| 408 function.appendArgument(false); | 393 function.appendArgument(false); |
| 409 else | 394 else |
| 410 function.appendArgument(columns); | 395 function.appendArgument(columns); |
| 411 bool hadException = false; | 396 bool hadException = false; |
| 412 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException
); | 397 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException
); |
| 413 if (hadException) | 398 if (hadException) |
| 414 return nullptr; | 399 return nullptr; |
| 415 return protocol::Runtime::RemoteObject::runtimeCast(toJSONValue(context(), r
)); | 400 protocol::ErrorSupport errors; |
| 401 return protocol::Runtime::RemoteObject::parse(toJSONValue(context(), r), &er
rors); |
| 416 } | 402 } |
| 417 | 403 |
| 418 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId)
const | 404 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId)
const |
| 419 { | 405 { |
| 420 return m_native->objectForId(objectId.id()); | 406 return m_native->objectForId(objectId.id()); |
| 421 } | 407 } |
| 422 | 408 |
| 423 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const | 409 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const |
| 424 { | 410 { |
| 425 return m_native->groupName(objectId.id()); | 411 return m_native->groupName(objectId.id()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 bool wasThrownVal = false; | 506 bool wasThrownVal = false; |
| 521 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | 507 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
| 522 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; | 508 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; |
| 523 return; | 509 return; |
| 524 } | 510 } |
| 525 if (wasThrownVal) { | 511 if (wasThrownVal) { |
| 526 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep
tionDetails"); | 512 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep
tionDetails"); |
| 527 if (objectExceptionDetails) | 513 if (objectExceptionDetails) |
| 528 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas
e()); | 514 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas
e()); |
| 529 } | 515 } |
| 530 *objectResult = protocol::Runtime::RemoteObject::runtimeCast(resultObj); | 516 protocol::ErrorSupport errors(errorString); |
| 517 *objectResult = protocol::Runtime::RemoteObject::parse(resultObj, &errors); |
| 531 *wasThrown = wasThrownVal; | 518 *wasThrown = wasThrownVal; |
| 532 } | 519 } |
| 533 | 520 |
| 534 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP
tr<JSONValue>* result, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDeta
ils) | 521 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP
tr<JSONValue>* result, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDeta
ils) |
| 535 { | 522 { |
| 536 v8::HandleScope handles(m_isolate); | 523 v8::HandleScope handles(m_isolate); |
| 537 v8::Context::Scope scope(context()); | 524 v8::Context::Scope scope(context()); |
| 538 v8::TryCatch tryCatch(m_isolate); | 525 v8::TryCatch tryCatch(m_isolate); |
| 539 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 526 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
| 540 if (tryCatch.HasCaught()) { | 527 if (tryCatch.HasCaught()) { |
| 541 v8::Local<v8::Message> message = tryCatch.Message(); | 528 v8::Local<v8::Message> message = tryCatch.Message(); |
| 542 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get
()) : "Internal error"; | 529 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get
()) : "Internal error"; |
| 543 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex
t(text).build(); | 530 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex
t(text).build(); |
| 544 } else { | 531 } else { |
| 545 *result = toJSONValue(function.context(), resultValue); | 532 *result = toJSONValue(function.context(), resultValue); |
| 546 if (!*result) | 533 if (!*result) |
| 547 *result = JSONString::create(String::format("Object has too long ref
erence chain(must not be longer than %d)", JSONValue::maxDepth)); | 534 *result = JSONString::create(String::format("Object has too long ref
erence chain(must not be longer than %d)", JSONValue::maxDepth)); |
| 548 } | 535 } |
| 549 } | 536 } |
| 550 | 537 |
| 551 void InjectedScript::dispose() | 538 void InjectedScript::dispose() |
| 552 { | 539 { |
| 553 m_manager->discardInjectedScript(m_contextId); | 540 m_manager->discardInjectedScript(m_contextId); |
| 554 } | 541 } |
| 555 | 542 |
| 556 } // namespace blink | 543 } // namespace blink |
| OLD | NEW |