string.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const {DebuggerServer} = require("devtools/server/main");
  6. const promise = require("promise");
  7. const {longStringSpec, SimpleStringFront} = require("devtools/shared/specs/string");
  8. const protocol = require("devtools/shared/protocol");
  9. const LongStringFront = protocol.FrontClassWithSpec(longStringSpec, {
  10. initialize: function (client) {
  11. protocol.Front.prototype.initialize.call(this, client);
  12. },
  13. destroy: function () {
  14. this.initial = null;
  15. this.length = null;
  16. this.strPromise = null;
  17. protocol.Front.prototype.destroy.call(this);
  18. },
  19. form: function (form) {
  20. this.actorID = form.actor;
  21. this.initial = form.initial;
  22. this.length = form.length;
  23. },
  24. string: function () {
  25. if (!this.strPromise) {
  26. let promiseRest = (thusFar) => {
  27. if (thusFar.length === this.length) {
  28. return promise.resolve(thusFar);
  29. }
  30. return this.substring(thusFar.length,
  31. thusFar.length + DebuggerServer.LONG_STRING_READ_LENGTH)
  32. .then((next) => promiseRest(thusFar + next));
  33. };
  34. this.strPromise = promiseRest(this.initial);
  35. }
  36. return this.strPromise;
  37. }
  38. });
  39. exports.LongStringFront = LongStringFront;
  40. exports.SimpleStringFront = SimpleStringFront;