зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1591330 - Remove LongStringClient. r=jdescottes.
The LongStringClient is removed and we replace its usage with LongStringFront instead. This require a few variable/function renaming, as well as updating the mocks we use in node tests. Switch usage to LongStringFront instead. Differential Revision: https://phabricator.services.mozilla.com/D50579 --HG-- rename : devtools/client/debugger/packages/devtools-reps/src/object-inspector/tests/__mocks__/long-string-client.js => devtools/client/debugger/packages/devtools-reps/src/object-inspector/tests/__mocks__/string-front.js rename : devtools/client/debugger/packages/devtools-reps/src/object-inspector/tests/component/create-long-string-client.js => devtools/client/debugger/packages/devtools-reps/src/object-inspector/tests/component/create-long-string-front.js extra : moz-landing-system : lando
This commit is contained in:
Родитель
8920070ecb
Коммит
d6786a8b07
|
@ -2,16 +2,12 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
function LongStringClient(grip, overrides) {
|
||||
function LongStringFront(grip, overrides) {
|
||||
return {
|
||||
grip,
|
||||
substring: function() {
|
||||
return Promise.resolve({
|
||||
fullText: "",
|
||||
});
|
||||
},
|
||||
substring: async () => "",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = LongStringClient;
|
||||
module.exports = { LongStringFront };
|
|
@ -6,18 +6,18 @@
|
|||
|
||||
const { mountObjectInspector } = require("../test-utils");
|
||||
const ObjectFront = require("../__mocks__/object-front");
|
||||
const LongStringClient = require("../__mocks__/long-string-client");
|
||||
const { LongStringFront } = require("../__mocks__/string-front");
|
||||
|
||||
const repsPath = "../../../reps";
|
||||
const longStringStubs = require(`${repsPath}/stubs/long-string`);
|
||||
|
||||
function mount(props) {
|
||||
const substring = jest.fn(() => Promise.resolve({ fullText: "" }));
|
||||
const substring = jest.fn(() => Promise.resolve(""));
|
||||
|
||||
const client = {
|
||||
createObjectFront: grip => ObjectFront(grip),
|
||||
createLongStringClient: jest.fn(grip =>
|
||||
LongStringClient(grip, { substring })
|
||||
createLongStringFront: jest.fn(grip =>
|
||||
LongStringFront(grip, { substring })
|
||||
),
|
||||
};
|
||||
|
||||
|
@ -29,9 +29,9 @@ function mount(props) {
|
|||
return { ...obj, substring };
|
||||
}
|
||||
|
||||
describe("createLongStringClient", () => {
|
||||
describe("createLongStringFront", () => {
|
||||
it("is called with the expected object for longString node", () => {
|
||||
const stub = longStringStubs.get("testUnloadedFullText");
|
||||
const stub = longStringStubs.get("testMultiline");
|
||||
|
||||
const { client } = mount({
|
||||
autoExpandDepth: 1,
|
||||
|
@ -45,7 +45,7 @@ describe("createLongStringClient", () => {
|
|||
],
|
||||
});
|
||||
|
||||
expect(client.createLongStringClient.mock.calls[0][0]).toBe(stub);
|
||||
expect(client.createLongStringFront.mock.calls[0][0]).toBe(stub);
|
||||
});
|
||||
|
||||
describe("substring", () => {
|
||||
|
@ -64,8 +64,7 @@ describe("createLongStringClient", () => {
|
|||
],
|
||||
});
|
||||
|
||||
// Third argument is the callback which holds the string response.
|
||||
expect(substring.mock.calls[0]).toHaveLength(3);
|
||||
expect(substring.mock.calls[0]).toHaveLength(2);
|
||||
const [start, length] = substring.mock.calls[0];
|
||||
expect(start).toBe(stub.initial.length);
|
||||
expect(length).toBe(stub.length);
|
|
@ -48,7 +48,7 @@ function generateDefaults(overrides) {
|
|||
...overrides,
|
||||
};
|
||||
}
|
||||
const LongStringClientMock = require("../__mocks__/long-string-client");
|
||||
const { LongStringFront } = require("../__mocks__/string-front");
|
||||
|
||||
function mount(props, { initialState } = {}) {
|
||||
const client = {
|
||||
|
@ -59,12 +59,10 @@ function mount(props, { initialState } = {}) {
|
|||
Promise.resolve(gripRepStubs.get("testProxySlots")),
|
||||
}),
|
||||
|
||||
createLongStringClient: grip =>
|
||||
LongStringClientMock(grip, {
|
||||
substring: function(initiaLength, length, cb) {
|
||||
cb({
|
||||
substring: "<<<<",
|
||||
});
|
||||
createLongStringFront: grip =>
|
||||
LongStringFront(grip, {
|
||||
substring: async function(initiaLength, length) {
|
||||
return "<<<<";
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
const { mountObjectInspector } = require("../test-utils");
|
||||
const ObjectFront = require("../__mocks__/object-front");
|
||||
const LongStringClient = require("../__mocks__/long-string-client");
|
||||
const { LongStringFront } = require("../__mocks__/string-front");
|
||||
|
||||
const repsPath = "../../../reps";
|
||||
const longStringStubs = require(`${repsPath}/stubs/long-string`);
|
||||
|
@ -23,7 +23,7 @@ function mount(stub) {
|
|||
const { wrapper } = mountObjectInspector({
|
||||
client: {
|
||||
createObjectFront: grip => ObjectFront(grip),
|
||||
createLongStringClient: grip => LongStringClient(grip),
|
||||
createLongStringFront: grip => LongStringFront(grip),
|
||||
},
|
||||
props: {
|
||||
roots: [root],
|
||||
|
|
|
@ -77,7 +77,7 @@ export type ObjectFront = {
|
|||
getProxySlots: () => Promise<{ proxyTarget: Object, proxyHandler: Object }>,
|
||||
};
|
||||
|
||||
export type LongStringClient = {
|
||||
export type LongStringFront = {
|
||||
substring: (
|
||||
start: number,
|
||||
end: number,
|
||||
|
@ -91,7 +91,7 @@ export type LongStringClient = {
|
|||
|
||||
export type CreateObjectFront = RdpGrip => ObjectFront;
|
||||
|
||||
export type CreateLongStringClient = RdpGrip => LongStringClient;
|
||||
export type CreateLongStringFront = RdpGrip => LongStringFront;
|
||||
|
||||
export type CachedNodes = Map<Path, Array<Node>>;
|
||||
|
||||
|
@ -118,7 +118,7 @@ export type Props = {
|
|||
dimTopLevelWindow: boolean,
|
||||
releaseActor: string => void,
|
||||
createObjectFront: CreateObjectFront,
|
||||
createLongStringClient: CreateLongStringClient,
|
||||
createLongStringFront: CreateLongStringFront,
|
||||
onFocus: ?(Node) => any,
|
||||
onActivate: ?(Node) => any,
|
||||
onDoubleClick: ?(
|
||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
|||
ObjectFront,
|
||||
PropertiesIterator,
|
||||
Node,
|
||||
LongStringClient,
|
||||
LongStringFront,
|
||||
} from "../types";
|
||||
|
||||
const { getValue, nodeHasFullText } = require("../utils/node");
|
||||
|
@ -88,33 +88,25 @@ async function getPrototype(
|
|||
}
|
||||
|
||||
async function getFullText(
|
||||
longStringClient: LongStringClient,
|
||||
longStringFront: LongStringFront,
|
||||
item: Node
|
||||
): Promise<{ fullText?: string }> {
|
||||
const { initial, fullText, length } = getValue(item);
|
||||
|
||||
// Return fullText property if it exists so that it can be added to the
|
||||
// loadedProperties map.
|
||||
if (nodeHasFullText(item)) {
|
||||
return Promise.resolve({ fullText });
|
||||
return { fullText };
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
longStringClient.substring(initial.length, length, response => {
|
||||
if (response.error) {
|
||||
console.error(
|
||||
"LongStringClient.substring",
|
||||
`${response.error}: ${response.message}`
|
||||
);
|
||||
reject({});
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
fullText: initial + response.substring,
|
||||
});
|
||||
});
|
||||
});
|
||||
try {
|
||||
const substring = await longStringFront.substring(initial.length, length);
|
||||
return {
|
||||
fullText: initial + substring,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("LongStringFront.substring", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function getProxySlots(
|
||||
|
|
|
@ -30,7 +30,7 @@ const {
|
|||
} = require("./node");
|
||||
|
||||
import type {
|
||||
CreateLongStringClient,
|
||||
CreateLongStringFront,
|
||||
CreateObjectFront,
|
||||
GripProperties,
|
||||
LoadedProperties,
|
||||
|
@ -39,7 +39,7 @@ import type {
|
|||
|
||||
type Client = {
|
||||
createObjectFront: CreateObjectFront,
|
||||
createLongStringClient: CreateLongStringClient,
|
||||
createLongStringFront: CreateLongStringFront,
|
||||
};
|
||||
|
||||
function loadItemProperties(
|
||||
|
@ -90,7 +90,7 @@ function loadItemProperties(
|
|||
}
|
||||
|
||||
if (shouldLoadItemFullText(item, loadedProperties)) {
|
||||
promises.push(getFullText(client.createLongStringClient(value), item));
|
||||
promises.push(getFullText(client.createLongStringFront(value), item));
|
||||
}
|
||||
|
||||
if (shouldLoadItemProxySlots(item, loadedProperties)) {
|
||||
|
|
|
@ -15,7 +15,7 @@ module.exports = services =>
|
|||
// Needed for the ObjectInspector
|
||||
client: {
|
||||
createObjectFront: services && services.createObjectFront,
|
||||
createLongStringClient: services && services.createLongStringClient,
|
||||
createLongStringFront: services && services.createLongStringFront,
|
||||
releaseActor: services && services.releaseActor,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -3994,7 +3994,7 @@ function loadItemProperties(item, client, loadedProperties) {
|
|||
}
|
||||
|
||||
if (shouldLoadItemFullText(item, loadedProperties)) {
|
||||
promises.push(getFullText(client.createLongStringClient(value), item));
|
||||
promises.push(getFullText(client.createLongStringFront(value), item));
|
||||
}
|
||||
|
||||
if (shouldLoadItemProxySlots(item, loadedProperties)) {
|
||||
|
@ -4155,7 +4155,7 @@ async function getPrototype(objectFront) {
|
|||
return objectFront.getPrototype();
|
||||
}
|
||||
|
||||
async function getFullText(longStringClient, item) {
|
||||
async function getFullText(longStringFront, item) {
|
||||
const {
|
||||
initial,
|
||||
fullText,
|
||||
|
@ -4164,24 +4164,20 @@ async function getFullText(longStringClient, item) {
|
|||
// loadedProperties map.
|
||||
|
||||
if (nodeHasFullText(item)) {
|
||||
return Promise.resolve({
|
||||
return {
|
||||
fullText
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
longStringClient.substring(initial.length, length, response => {
|
||||
if (response.error) {
|
||||
console.error("LongStringClient.substring", `${response.error}: ${response.message}`);
|
||||
reject({});
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
fullText: initial + response.substring
|
||||
});
|
||||
});
|
||||
});
|
||||
try {
|
||||
const substring = await longStringFront.substring(initial.length, length);
|
||||
return {
|
||||
fullText: initial + substring
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("LongStringFront.substring", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function getProxySlots(objectFront) {
|
||||
|
|
|
@ -38,7 +38,7 @@ var L10N = new LocalizationHelper(DBG_STRINGS_URI);
|
|||
* @param object aOptions [optional]
|
||||
* Options for configuring the controller. Supported options:
|
||||
* - getObjectFront: @see this._setClientGetters
|
||||
* - getLongStringClient: @see this._setClientGetters
|
||||
* - getLongStringFront: @see this._setClientGetters
|
||||
* - getEnvironmentFront: @see this._setClientGetters
|
||||
* - releaseActor: @see this._setClientGetters
|
||||
* - overrideValueEvalMacro: @see _setEvaluationMacros
|
||||
|
@ -79,7 +79,7 @@ VariablesViewController.prototype = {
|
|||
* @param object aOptions
|
||||
* Options for getting the client grips. Supported options:
|
||||
* - getObjectFront: callback for creating an object grip front
|
||||
* - getLongStringClient: callback for creating a long string grip client
|
||||
* - getLongStringFront: callback for creating a long string front
|
||||
* - getEnvironmentFront: callback for creating an environment front
|
||||
* - releaseActor: callback for releasing an actor when it's no longer needed
|
||||
*/
|
||||
|
@ -87,8 +87,8 @@ VariablesViewController.prototype = {
|
|||
if (aOptions.getObjectFront) {
|
||||
this._getObjectFront = aOptions.getObjectFront;
|
||||
}
|
||||
if (aOptions.getLongStringClient) {
|
||||
this._getLongStringClient = aOptions.getLongStringClient;
|
||||
if (aOptions.getLongStringFront) {
|
||||
this._getLongStringFront = aOptions.getLongStringFront;
|
||||
}
|
||||
if (aOptions.getEnvironmentFront) {
|
||||
this._getEnvironmentFront = aOptions.getEnvironmentFront;
|
||||
|
@ -129,25 +129,18 @@ VariablesViewController.prototype = {
|
|||
* @return Promise
|
||||
* The promise that will be resolved when the string is retrieved.
|
||||
*/
|
||||
_populateFromLongString: function(aTarget, aGrip) {
|
||||
const deferred = defer();
|
||||
|
||||
_populateFromLongString: async function(aTarget, aGrip) {
|
||||
const from = aGrip.initial.length;
|
||||
const to = Math.min(aGrip.length, MAX_LONG_STRING_LENGTH);
|
||||
|
||||
this._getLongStringClient(aGrip).substring(from, to, aResponse => {
|
||||
// Stop tracking the actor because it's no longer needed.
|
||||
this.releaseActor(aGrip);
|
||||
const response = await this._getLongStringFront(aGrip).substring(from, to);
|
||||
// Stop tracking the actor because it's no longer needed.
|
||||
this.releaseActor(aGrip);
|
||||
|
||||
// Replace the preview with the full string and make it non-expandable.
|
||||
aTarget.onexpand = null;
|
||||
aTarget.setGrip(aGrip.initial + aResponse.substring);
|
||||
aTarget.hideArrow();
|
||||
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
// Replace the preview with the full string and make it non-expandable.
|
||||
aTarget.onexpand = null;
|
||||
aTarget.setGrip(aGrip.initial + response);
|
||||
aTarget.hideArrow();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"use strict";
|
||||
|
||||
const ObjectFront = require("devtools/shared/fronts/object");
|
||||
const LongStringClient = require("devtools/shared/client/long-string-client");
|
||||
|
||||
class ConsoleCommands {
|
||||
constructor({ debuggerClient, proxy, threadFront, currentTarget }) {
|
||||
|
@ -23,8 +22,8 @@ class ConsoleCommands {
|
|||
return new ObjectFront(this.debuggerClient, object);
|
||||
}
|
||||
|
||||
createLongStringClient(object) {
|
||||
return new LongStringClient(this.debuggerClient, object);
|
||||
createLongStringFront(object) {
|
||||
return this.proxy.webConsoleFront.longString(object);
|
||||
}
|
||||
|
||||
releaseActor(actor) {
|
||||
|
|
|
@ -113,7 +113,8 @@ requireHacker.global_hook("default", (path, module) => {
|
|||
getModule("devtools/client/webconsole/test/node/fixtures/PluralForm"),
|
||||
Services: () => `module.exports = require("devtools-services")`,
|
||||
"devtools/shared/fronts/object": () => `() => {}`,
|
||||
"devtools/shared/client/long-string-client": () => `() => {}`,
|
||||
"devtools/shared/fronts/string": () =>
|
||||
`() => ({LongStringFront: () => {}})`,
|
||||
"devtools/client/shared/components/SmartTrace": () => "{}",
|
||||
"devtools/client/netmonitor/src/components/TabboxPanel": () => "{}",
|
||||
"devtools/client/webconsole/utils/context-menu": () => "{}",
|
||||
|
|
|
@ -82,7 +82,7 @@ The response is parsed using DOM parser and displayed as an XML markup.
|
|||
[2] List of Image mime-types: `devtools/client/webconsole/old/net/utils/json`
|
||||
[3] List of XML/HTML mime-types: `devtools/client/webconsole/old/net/utils/net`
|
||||
|
||||
Response data are fetched using `LongStringClient`, so if data are bigger
|
||||
Response data are fetched using `LongStringFront`, so if data are bigger
|
||||
than defined limit (see `devtools/server/main.js - LONG_STRING_LENGTH)
|
||||
the user needs to manually require the rest (there is a link at the end
|
||||
of incomplete response body that allows this).
|
||||
|
|
|
@ -34,7 +34,7 @@ exports.LongStringActor = protocol.ActorClassWithSpec(longStringSpec, {
|
|||
},
|
||||
|
||||
substring: function(start, end) {
|
||||
return Promise.resolve(this.str.substring(start, end));
|
||||
return this.str.substring(start, end);
|
||||
},
|
||||
|
||||
release: function() {},
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
arg,
|
||||
DebuggerClient,
|
||||
} = require("devtools/shared/client/debugger-client");
|
||||
/**
|
||||
* A LongStringClient provides a way to access "very long" strings from the
|
||||
* debugger server.
|
||||
*
|
||||
* @param client DebuggerClient
|
||||
* The debugger client parent.
|
||||
* @param grip Object
|
||||
* A pause-lifetime long string grip returned by the protocol.
|
||||
*/
|
||||
function LongStringClient(client, grip) {
|
||||
this._grip = grip;
|
||||
this._client = client;
|
||||
this.request = this._client.request;
|
||||
}
|
||||
|
||||
LongStringClient.prototype = {
|
||||
get actor() {
|
||||
return this._grip.actor;
|
||||
},
|
||||
get length() {
|
||||
return this._grip.length;
|
||||
},
|
||||
get initial() {
|
||||
return this._grip.initial;
|
||||
},
|
||||
get _transport() {
|
||||
return this._client._transport;
|
||||
},
|
||||
|
||||
valid: true,
|
||||
|
||||
/**
|
||||
* Get the substring of this LongString from start to end.
|
||||
*
|
||||
* @param start Number
|
||||
* The starting index.
|
||||
* @param end Number
|
||||
* The ending index.
|
||||
* @param callback Function
|
||||
* The function called when we receive the substring.
|
||||
*/
|
||||
substring: DebuggerClient.requester({
|
||||
type: "substring",
|
||||
start: arg(0),
|
||||
end: arg(1),
|
||||
}),
|
||||
};
|
||||
|
||||
module.exports = LongStringClient;
|
|
@ -9,5 +9,4 @@ DevToolsModules(
|
|||
'constants.js',
|
||||
'debugger-client.js',
|
||||
'deprecated-thread-client.js',
|
||||
'long-string-client.js',
|
||||
)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
"use strict";
|
||||
|
||||
const { DebuggerServer } = require("devtools/server/debugger-server");
|
||||
const promise = require("promise");
|
||||
const {
|
||||
longStringSpec,
|
||||
SimpleStringFront,
|
||||
|
@ -32,7 +31,7 @@ class LongStringFront extends FrontClassWithSpec(longStringSpec) {
|
|||
if (!this.strPromise) {
|
||||
const promiseRest = thusFar => {
|
||||
if (thusFar.length === this.length) {
|
||||
return promise.resolve(thusFar);
|
||||
return Promise.resolve(thusFar);
|
||||
}
|
||||
return this.substring(
|
||||
thusFar.length,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"use strict";
|
||||
|
||||
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
const LongStringClient = require("devtools/shared/client/long-string-client");
|
||||
const { LongStringFront } = require("devtools/shared/fronts/string");
|
||||
const {
|
||||
FrontClassWithSpec,
|
||||
registerFront,
|
||||
|
@ -446,21 +446,64 @@ class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return an instance of LongStringClient for the given long string grip.
|
||||
* Return an instance of LongStringFront for the given long string grip.
|
||||
*
|
||||
* @param object grip
|
||||
* The long string grip returned by the protocol.
|
||||
* @return object
|
||||
* The LongStringClient for the given long string grip.
|
||||
* @return {LongStringFront} the front for the given long string grip.
|
||||
*/
|
||||
longString(grip) {
|
||||
if (grip.actor in this._longStrings) {
|
||||
return this._longStrings[grip.actor];
|
||||
}
|
||||
|
||||
const client = new LongStringClient(this._client, grip);
|
||||
this._longStrings[grip.actor] = client;
|
||||
return client;
|
||||
const front = new LongStringFront(this._client, this.targetFront, this);
|
||||
front.form(grip);
|
||||
this.manage(front);
|
||||
this._longStrings[grip.actor] = front;
|
||||
return front;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the full text of a LongString.
|
||||
*
|
||||
* @param object | string stringGrip
|
||||
* The long string grip containing the corresponding actor.
|
||||
* If you pass in a plain string (by accident or because you're lazy),
|
||||
* then a promise of the same string is simply returned.
|
||||
* @return object Promise
|
||||
* A promise that is resolved when the full string contents
|
||||
* are available, or rejected if something goes wrong.
|
||||
*/
|
||||
async getString(stringGrip) {
|
||||
// Make sure this is a long string.
|
||||
if (typeof stringGrip !== "object" || stringGrip.type !== "longString") {
|
||||
// Go home string, you're drunk.
|
||||
return stringGrip;
|
||||
}
|
||||
|
||||
// Fetch the long string only once.
|
||||
if (stringGrip._fullText) {
|
||||
return stringGrip._fullText;
|
||||
}
|
||||
|
||||
const { initial, length } = stringGrip;
|
||||
const longStringFront = this.longString(stringGrip);
|
||||
|
||||
try {
|
||||
const response = await longStringFront.substring(initial.length, length);
|
||||
return initial + response;
|
||||
} catch (e) {
|
||||
DevToolsUtils.reportException("getString", e.message);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
clearNetworkRequests() {
|
||||
// Prevent exception if the front has already been destroyed.
|
||||
if (this._networkRequests) {
|
||||
this._networkRequests.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -482,53 +525,6 @@ class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
|
|||
this._networkRequests = null;
|
||||
return super.destroy();
|
||||
}
|
||||
|
||||
clearNetworkRequests() {
|
||||
// Prevent exception if the front has already been destroyed.
|
||||
if (this._networkRequests) {
|
||||
this._networkRequests.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the full text of a LongString.
|
||||
*
|
||||
* @param object | string stringGrip
|
||||
* The long string grip containing the corresponding actor.
|
||||
* If you pass in a plain string (by accident or because you're lazy),
|
||||
* then a promise of the same string is simply returned.
|
||||
* @return object Promise
|
||||
* A promise that is resolved when the full string contents
|
||||
* are available, or rejected if something goes wrong.
|
||||
*/
|
||||
getString(stringGrip) {
|
||||
// Make sure this is a long string.
|
||||
if (typeof stringGrip !== "object" || stringGrip.type !== "longString") {
|
||||
// Go home string, you're drunk.
|
||||
return Promise.resolve(stringGrip);
|
||||
}
|
||||
|
||||
// Fetch the long string only once.
|
||||
if (stringGrip._fullText) {
|
||||
return stringGrip._fullText;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const { initial, length } = stringGrip;
|
||||
const longStringClient = this.longString(stringGrip);
|
||||
|
||||
longStringClient.substring(initial.length, length, response => {
|
||||
if (response.error) {
|
||||
DevToolsUtils.reportException(
|
||||
"getString",
|
||||
response.error + ": " + response.message
|
||||
);
|
||||
reject(response);
|
||||
}
|
||||
resolve(initial + response.substring);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.WebConsoleFront = WebConsoleFront;
|
||||
|
|
Загрузка…
Ссылка в новой задаче