| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 scopeEndPositions[i] = scopeDetails.endPosition ? scopeDetails.endPositi
on() : 0; | 411 scopeEndPositions[i] = scopeDetails.endPosition ? scopeDetails.endPositi
on() : 0; |
| 412 scopeFunctions[i] = scopeDetails.func ? scopeDetails.func() : null; | 412 scopeFunctions[i] = scopeDetails.func ? scopeDetails.func() : null; |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Calculated lazily. | 415 // Calculated lazily. |
| 416 var scopeChain; | 416 var scopeChain; |
| 417 var funcMirror; | 417 var funcMirror; |
| 418 var location; | 418 var location; |
| 419 var scopeStartLocations; | 419 var scopeStartLocations; |
| 420 var scopeEndLocations; | 420 var scopeEndLocations; |
| 421 var details; |
| 421 | 422 |
| 422 function createLocation(script, pos) | 423 function createLocation(script, pos) |
| 423 { | 424 { |
| 424 if (!script) | 425 if (!script) |
| 425 return null; | 426 return null; |
| 426 | 427 |
| 427 location = script.locationFromPosition(pos, true); | 428 var location = script.locationFromPosition(pos, true); |
| 428 return { | 429 return { |
| 429 "lineNumber": location.line, | 430 "lineNumber": location.line, |
| 430 "columnNumber": location.column, | 431 "columnNumber": location.column, |
| 431 "scriptId": String(script.id()) | 432 "scriptId": String(script.id()) |
| 432 } | 433 } |
| 433 } | 434 } |
| 434 | 435 |
| 435 function lazyScopeChain() | 436 function lazyScopeChain() |
| 436 { | 437 { |
| 437 if (!scopeChain) { | 438 if (!scopeChain) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 458 scopeTypes.length = scopeChain.length; | 459 scopeTypes.length = scopeChain.length; |
| 459 scopeNames.length = scopeChain.length; | 460 scopeNames.length = scopeChain.length; |
| 460 scopeObjects = null; // Free for GC. | 461 scopeObjects = null; // Free for GC. |
| 461 scopeFunctions = null; | 462 scopeFunctions = null; |
| 462 scopeStartPositions = null; | 463 scopeStartPositions = null; |
| 463 scopeEndPositions = null; | 464 scopeEndPositions = null; |
| 464 } | 465 } |
| 465 return scopeChain; | 466 return scopeChain; |
| 466 } | 467 } |
| 467 | 468 |
| 468 function lazyScopeTypes() | 469 function lazyDetails() |
| 469 { | 470 { |
| 470 if (!scopeChain) | 471 if (!details) { |
| 471 lazyScopeChain(); | 472 var scopeObjects = lazyScopeChain(); |
| 472 return scopeTypes; | 473 var script = ensureFuncMirror().script(); |
| 473 } | 474 var scopes = []; |
| 474 | 475 for (var i = 0; i < scopeObjects.length; ++i) { |
| 475 function lazyScopeNames() | 476 var scope = { |
| 476 { | 477 "type": scopeTypes[i], |
| 477 if (!scopeChain) | 478 "object": scopeObjects[i], |
| 478 lazyScopeChain(); | 479 }; |
| 479 return scopeNames; | 480 if (scopeNames[i]) |
| 480 } | 481 scope.name = scopeNames[i]; |
| 481 | 482 if (scopeStartLocations[i]) |
| 482 function lazyScopeStartLocations() | 483 scope.startLocation = scopeStartLocations[i]; |
| 483 { | 484 if (scopeEndLocations[i]) |
| 484 if (!scopeChain) | 485 scope.endLocation = scopeEndLocations[i]; |
| 485 lazyScopeChain(); | 486 scopes.push(scope); |
| 486 | 487 } |
| 487 return scopeStartLocations; | 488 details = { |
| 488 } | 489 "functionName": ensureFuncMirror().debugName(), |
| 489 | 490 "location": { |
| 490 function lazyScopeEndLocations() | 491 "lineNumber": line(), |
| 491 { | 492 "columnNumber": column(), |
| 492 if (!scopeChain) | 493 "scriptId": String(script.id()) |
| 493 lazyScopeChain(); | 494 }, |
| 494 | 495 "this": thisObject, |
| 495 return scopeEndLocations; | 496 "scopeChain": scopes |
| 497 }; |
| 498 var functionLocation = ensureFuncMirror().sourceLocation(); |
| 499 if (functionLocation) { |
| 500 details.functionLocation = { |
| 501 "lineNumber": functionLocation.line, |
| 502 "columnNumber": functionLocation.column, |
| 503 "scriptId": String(script.id()) |
| 504 }; |
| 505 } |
| 506 if (isAtReturn) |
| 507 details.returnValue = returnValue; |
| 508 } |
| 509 return details; |
| 496 } | 510 } |
| 497 | 511 |
| 498 function ensureFuncMirror() | 512 function ensureFuncMirror() |
| 499 { | 513 { |
| 500 if (!funcMirror) { | 514 if (!funcMirror) { |
| 501 funcMirror = MakeMirror(funcObject); | 515 funcMirror = MakeMirror(funcObject); |
| 502 if (!funcMirror.isFunction()) | 516 if (!funcMirror.isFunction()) |
| 503 funcMirror = new UnresolvedFunctionMirror(funcObject); | 517 funcMirror = new UnresolvedFunctionMirror(funcObject); |
| 504 } | 518 } |
| 505 return funcMirror; | 519 return funcMirror; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 526 { | 540 { |
| 527 return ensureLocation().column; | 541 return ensureLocation().column; |
| 528 } | 542 } |
| 529 | 543 |
| 530 function sourceID() | 544 function sourceID() |
| 531 { | 545 { |
| 532 var script = ensureFuncMirror().script(); | 546 var script = ensureFuncMirror().script(); |
| 533 return script && script.id(); | 547 return script && script.id(); |
| 534 } | 548 } |
| 535 | 549 |
| 536 function scriptName() | |
| 537 { | |
| 538 var script = ensureFuncMirror().script(); | |
| 539 return script && script.name(); | |
| 540 } | |
| 541 | |
| 542 function functionName() | |
| 543 { | |
| 544 return ensureFuncMirror().debugName(); | |
| 545 } | |
| 546 | |
| 547 function functionLine() | |
| 548 { | |
| 549 var location = ensureFuncMirror().sourceLocation(); | |
| 550 return location ? location.line : 0; | |
| 551 } | |
| 552 | |
| 553 function functionColumn() | |
| 554 { | |
| 555 var location = ensureFuncMirror().sourceLocation(); | |
| 556 return location ? location.column : 0; | |
| 557 } | |
| 558 | |
| 559 function evaluate(expression) | 550 function evaluate(expression) |
| 560 { | 551 { |
| 561 return frameMirror.evaluate(expression, false).value(); | 552 return frameMirror.evaluate(expression, false).value(); |
| 562 } | 553 } |
| 563 | 554 |
| 564 function restart() | 555 function restart() |
| 565 { | 556 { |
| 566 return frameMirror.restart(); | 557 return frameMirror.restart(); |
| 567 } | 558 } |
| 568 | 559 |
| 569 function setVariableValue(scopeNumber, variableName, newValue) | 560 function setVariableValue(scopeNumber, variableName, newValue) |
| 570 { | 561 { |
| 571 return DebuggerScript._setScopeVariableValue(frameMirror, scopeNumber, v
ariableName, newValue); | 562 return DebuggerScript._setScopeVariableValue(frameMirror, scopeNumber, v
ariableName, newValue); |
| 572 } | 563 } |
| 573 | 564 |
| 574 function stepInPositions() | |
| 575 { | |
| 576 var stepInPositionsV8 = frameMirror.stepInPositions(); | |
| 577 var stepInPositionsProtocol; | |
| 578 if (stepInPositionsV8) { | |
| 579 stepInPositionsProtocol = []; | |
| 580 var script = ensureFuncMirror().script(); | |
| 581 if (script) { | |
| 582 var scriptId = String(script.id()); | |
| 583 for (var i = 0; i < stepInPositionsV8.length; i++) { | |
| 584 var item = { | |
| 585 scriptId: scriptId, | |
| 586 lineNumber: stepInPositionsV8[i].position.line, | |
| 587 columnNumber: stepInPositionsV8[i].position.column | |
| 588 }; | |
| 589 stepInPositionsProtocol.push(item); | |
| 590 } | |
| 591 } | |
| 592 } | |
| 593 return JSON.stringify(stepInPositionsProtocol); | |
| 594 } | |
| 595 | |
| 596 return { | 565 return { |
| 597 "sourceID": sourceID, | 566 "sourceID": sourceID, |
| 598 "line": line, | 567 "line": line, |
| 599 "column": column, | 568 "column": column, |
| 600 "scriptName": scriptName, | |
| 601 "functionName": functionName, | |
| 602 "functionLine": functionLine, | |
| 603 "functionColumn": functionColumn, | |
| 604 "thisObject": thisObject, | 569 "thisObject": thisObject, |
| 605 "scopeChain": lazyScopeChain, | |
| 606 "scopeType": lazyScopeTypes, | |
| 607 "scopeName": lazyScopeNames, | |
| 608 "scopeStartLocation": lazyScopeStartLocations, | |
| 609 "scopeEndLocation": lazyScopeEndLocations, | |
| 610 "evaluate": evaluate, | 570 "evaluate": evaluate, |
| 611 "caller": callerFrame, | 571 "caller": callerFrame, |
| 612 "restart": restart, | 572 "restart": restart, |
| 613 "setVariableValue": setVariableValue, | 573 "setVariableValue": setVariableValue, |
| 614 "stepInPositions": stepInPositions, | |
| 615 "isAtReturn": isAtReturn, | 574 "isAtReturn": isAtReturn, |
| 616 "returnValue": returnValue | 575 "details": lazyDetails |
| 617 }; | 576 }; |
| 618 } | 577 } |
| 619 | 578 |
| 620 DebuggerScript._buildScopeObject = function(scopeType, scopeObject) | 579 DebuggerScript._buildScopeObject = function(scopeType, scopeObject) |
| 621 { | 580 { |
| 622 var result; | 581 var result; |
| 623 switch (scopeType) { | 582 switch (scopeType) { |
| 624 case ScopeType.Local: | 583 case ScopeType.Local: |
| 625 case ScopeType.Closure: | 584 case ScopeType.Closure: |
| 626 case ScopeType.Catch: | 585 case ScopeType.Catch: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 "parentPromise": eventData.parentPromise().value(), | 617 "parentPromise": eventData.parentPromise().value(), |
| 659 "status": eventData.status() | 618 "status": eventData.status() |
| 660 }; | 619 }; |
| 661 } | 620 } |
| 662 | 621 |
| 663 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr
ors in the cache we disable it. | 622 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr
ors in the cache we disable it. |
| 664 ToggleMirrorCache(false); | 623 ToggleMirrorCache(false); |
| 665 | 624 |
| 666 return DebuggerScript; | 625 return DebuggerScript; |
| 667 })(); | 626 })(); |
| OLD | NEW |