string.js (1711B)
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 DevToolsServer, 8 } = require("resource://devtools/server/devtools-server.js"); 9 const { 10 longStringSpec, 11 SimpleStringFront, 12 } = require("resource://devtools/shared/specs/string.js"); 13 const { 14 FrontClassWithSpec, 15 registerFront, 16 } = require("resource://devtools/shared/protocol.js"); 17 18 class LongStringFront extends FrontClassWithSpec(longStringSpec) { 19 destroy() { 20 this.initial = null; 21 this.length = null; 22 this.strPromise = null; 23 super.destroy(); 24 } 25 26 form(data) { 27 this.actorID = data.actor; 28 this.initial = data.initial; 29 this.length = data.length; 30 31 this._grip = data; 32 } 33 34 // We expose the grip so consumers (e.g. ObjectInspector) that handle webconsole 35 // evaluations (which can return primitive, object fronts or longString front), 36 // can directly call this without further check. 37 getGrip() { 38 return this._grip; 39 } 40 41 string() { 42 if (!this.strPromise) { 43 const promiseRest = thusFar => { 44 if (thusFar.length === this.length) { 45 return Promise.resolve(thusFar); 46 } 47 return this.substring( 48 thusFar.length, 49 thusFar.length + DevToolsServer.LONG_STRING_READ_LENGTH 50 ).then(next => promiseRest(thusFar + next)); 51 }; 52 53 this.strPromise = promiseRest(this.initial); 54 } 55 return this.strPromise; 56 } 57 } 58 59 exports.LongStringFront = LongStringFront; 60 registerFront(LongStringFront); 61 exports.SimpleStringFront = SimpleStringFront; 62 registerFront(SimpleStringFront);