Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / devtools / client / shared / string-utils.js
blob327d3588c6e0b51c709563b437ccac3d78c31ccb
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";
6 const {
7   LongStringFront,
8 } = require("resource://devtools/client/fronts/string.js");
10 /**
11  * Fetches the full text of a LongString.
12  *
13  * @param {DevToolsClient} client
14  * @param {object|string} stringGrip: A long string grip. If the param is a simple string,
15  *                                    it will be returned as is.
16  * @return {Promise<String>} The full string content.
17  */
18 async function getLongStringFullText(client, stringGrip) {
19   if (typeof stringGrip !== "object" || stringGrip.type !== "longString") {
20     return stringGrip;
21   }
23   const { initial, length } = stringGrip;
24   const longStringFront = new LongStringFront(
25     client
26     // this.commands.targetCommand.targetFront
27   );
28   longStringFront.form(stringGrip);
29   // The front has to be managed to be able to call the actor method.
30   longStringFront.manage(longStringFront);
32   const response = await longStringFront.substring(initial.length, length);
33   const payload = initial + response;
35   longStringFront.destroy();
37   return payload;
40 exports.getLongStringFullText = getLongStringFullText;