string-utils.js (1291B)
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 6 const { 7 LongStringFront, 8 } = require("resource://devtools/client/fronts/string.js"); 9 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 } 22 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); 31 32 const response = await longStringFront.substring(initial.length, length); 33 const payload = initial + response; 34 35 longStringFront.destroy(); 36 37 return payload; 38 } 39 40 exports.getLongStringFullText = getLongStringFullText;