| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = stackTrace->get(i)->asObject(); | 80 RefPtr<JSONObject> stackFrame = JSONObject::cast(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 106 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->asArray()); | 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::Maybe<String>& callFrameIdOpt, | 216 const protocol::Maybe<String>& callFrameIdOpt, |
| 217 const protocol::Maybe<String>& functionObjectIdOpt, | 217 const protocol::Maybe<String>& functionObjectIdOpt, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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->asObject()); | 263 *result = FunctionDetails::runtimeCast(resultValue); |
| 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->asObject()); | 278 *result = GeneratorObjectDetails::runtimeCast(resultValue); |
| 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->asArray()); | 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, Maybe<protocol::Runtime::ExceptionDet
ails>* 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->isJust()) { | 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->asArray()); | 316 *properties = Array<PropertyDescriptor>::runtimeCast(result.release()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin
g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco
l::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->isJust()) | 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->asArray()); | 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 |
| 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; | 343 RefPtr<JSONObject> object = JSONObject::cast(parsedObjectId); |
| 344 if (!parsedObjectId->asObject(&object)) | 344 if (!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 Loading... |
| 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->asArray()); | 382 return Array<CallFrame>::runtimeCast(result.release()); |
| 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 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject(); | 398 return protocol::Runtime::RemoteObject::runtimeCast(toJSONValue(context(), r
)); |
| 399 return protocol::Runtime::RemoteObject::runtimeCast(rawResult); | |
| 400 } | 399 } |
| 401 | 400 |
| 402 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<
v8::Value> table, v8::Local<v8::Value> columns) const | 401 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<
v8::Value> table, v8::Local<v8::Value> columns) const |
| 403 { | 402 { |
| 404 v8::HandleScope handles(m_isolate); | 403 v8::HandleScope handles(m_isolate); |
| 405 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); | 404 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); |
| 406 function.appendArgument(canAccessInspectedWindow()); | 405 function.appendArgument(canAccessInspectedWindow()); |
| 407 function.appendArgument(table); | 406 function.appendArgument(table); |
| 408 if (columns.IsEmpty()) | 407 if (columns.IsEmpty()) |
| 409 function.appendArgument(false); | 408 function.appendArgument(false); |
| 410 else | 409 else |
| 411 function.appendArgument(columns); | 410 function.appendArgument(columns); |
| 412 bool hadException = false; | 411 bool hadException = false; |
| 413 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException
); | 412 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException
); |
| 414 if (hadException) | 413 if (hadException) |
| 415 return nullptr; | 414 return nullptr; |
| 416 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject(); | 415 return protocol::Runtime::RemoteObject::runtimeCast(toJSONValue(context(), r
)); |
| 417 return protocol::Runtime::RemoteObject::runtimeCast(rawResult); | |
| 418 } | 416 } |
| 419 | 417 |
| 420 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId)
const | 418 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId)
const |
| 421 { | 419 { |
| 422 return m_native->objectForId(objectId.id()); | 420 return m_native->objectForId(objectId.id()); |
| 423 } | 421 } |
| 424 | 422 |
| 425 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const | 423 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const |
| 426 { | 424 { |
| 427 return m_native->groupName(objectId.id()); | 425 return m_native->groupName(objectId.id()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 makeCall(function, &result); | 504 makeCall(function, &result); |
| 507 if (!result) { | 505 if (!result) { |
| 508 *errorString = "Internal error: result value is empty"; | 506 *errorString = "Internal error: result value is empty"; |
| 509 return; | 507 return; |
| 510 } | 508 } |
| 511 if (result->type() == JSONValue::TypeString) { | 509 if (result->type() == JSONValue::TypeString) { |
| 512 result->asString(errorString); | 510 result->asString(errorString); |
| 513 ASSERT(errorString->length()); | 511 ASSERT(errorString->length()); |
| 514 return; | 512 return; |
| 515 } | 513 } |
| 516 RefPtr<JSONObject> resultPair = result->asObject(); | 514 RefPtr<JSONObject> resultPair = JSONObject::cast(result); |
| 517 if (!resultPair) { | 515 if (!resultPair) { |
| 518 *errorString = "Internal error: result is not an Object"; | 516 *errorString = "Internal error: result is not an Object"; |
| 519 return; | 517 return; |
| 520 } | 518 } |
| 521 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); | 519 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); |
| 522 bool wasThrownVal = false; | 520 bool wasThrownVal = false; |
| 523 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | 521 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
| 524 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; | 522 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; |
| 525 return; | 523 return; |
| 526 } | 524 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 549 *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)); |
| 550 } | 548 } |
| 551 } | 549 } |
| 552 | 550 |
| 553 void InjectedScript::dispose() | 551 void InjectedScript::dispose() |
| 554 { | 552 { |
| 555 m_manager->discardInjectedScript(m_contextId); | 553 m_manager->discardInjectedScript(m_contextId); |
| 556 } | 554 } |
| 557 | 555 |
| 558 } // namespace blink | 556 } // namespace blink |
| OLD | NEW |