frame.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. const { ActorPool } = require("devtools/server/actors/common");
  7. const { createValueGrip } = require("devtools/server/actors/object");
  8. const { ActorClassWithSpec } = require("devtools/shared/protocol");
  9. const { frameSpec } = require("devtools/shared/specs/frame");
  10. /**
  11. * An actor for a specified stack frame.
  12. */
  13. let FrameActor = ActorClassWithSpec(frameSpec, {
  14. /**
  15. * Creates the Frame actor.
  16. *
  17. * @param frame Debugger.Frame
  18. * The debuggee frame.
  19. * @param threadActor ThreadActor
  20. * The parent thread actor for this frame.
  21. */
  22. initialize: function (frame, threadActor) {
  23. this.frame = frame;
  24. this.threadActor = threadActor;
  25. },
  26. /**
  27. * A pool that contains frame-lifetime objects, like the environment.
  28. */
  29. _frameLifetimePool: null,
  30. get frameLifetimePool() {
  31. if (!this._frameLifetimePool) {
  32. this._frameLifetimePool = new ActorPool(this.conn);
  33. this.conn.addActorPool(this._frameLifetimePool);
  34. }
  35. return this._frameLifetimePool;
  36. },
  37. /**
  38. * Finalization handler that is called when the actor is being evicted from
  39. * the pool.
  40. */
  41. disconnect: function () {
  42. this.conn.removeActorPool(this._frameLifetimePool);
  43. this._frameLifetimePool = null;
  44. },
  45. /**
  46. * Returns a frame form for use in a protocol message.
  47. */
  48. form: function () {
  49. let threadActor = this.threadActor;
  50. let form = { actor: this.actorID,
  51. type: this.frame.type };
  52. if (this.frame.type === "call") {
  53. form.callee = createValueGrip(this.frame.callee, threadActor._pausePool,
  54. threadActor.objectGrip);
  55. }
  56. if (this.frame.environment) {
  57. let envActor = threadActor.createEnvironmentActor(
  58. this.frame.environment,
  59. this.frameLifetimePool
  60. );
  61. form.environment = envActor.form();
  62. }
  63. form.this = createValueGrip(this.frame.this, threadActor._pausePool,
  64. threadActor.objectGrip);
  65. form.arguments = this._args();
  66. if (this.frame.script) {
  67. var generatedLocation = this.threadActor.sources.getFrameLocation(this.frame);
  68. form.where = {
  69. source: generatedLocation.generatedSourceActor.form(),
  70. line: generatedLocation.generatedLine,
  71. column: generatedLocation.generatedColumn
  72. };
  73. }
  74. if (!this.frame.older) {
  75. form.oldest = true;
  76. }
  77. return form;
  78. },
  79. _args: function () {
  80. if (!this.frame.arguments) {
  81. return [];
  82. }
  83. return this.frame.arguments.map(arg => createValueGrip(arg,
  84. this.threadActor._pausePool, this.threadActor.objectGrip));
  85. }
  86. });
  87. exports.FrameActor = FrameActor;