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/. */
7 const { sourceSpec
} = require("resource://devtools/shared/specs/source.js");
11 } = require("resource://devtools/shared/protocol.js");
14 } = require("resource://devtools/client/fronts/array-buffer.js");
17 * A SourceFront provides a way to access the source text of a script.
19 * @param client DevToolsClient
20 * The DevTools Client instance.
22 * The form sent across the remote debugging protocol.
24 class SourceFront
extends FrontClassWithSpec(sourceSpec
) {
25 constructor(client
, form
) {
29 // this is here for the time being, until the source front is managed
30 // via protocol.js marshalling
31 this.actorID
= form
.actor
;
47 // Alias for source.blackbox to avoid changing protocol.js packets
49 return this.blackbox(range
);
52 // Alias for source.unblackbox to avoid changing protocol.js packets
54 return this.unblackbox();
58 * Get a Front for either an ArrayBuffer or LongString
59 * for this SourceFront's source.
62 const response
= await
super.source();
63 return this._onSourceResponse(response
);
66 _onSourceResponse(response
) {
67 const { contentType
, source
} = response
;
68 if (source
instanceof ArrayBufferFront
) {
69 return source
.slice(0, source
.length
).then(function (resp
) {
73 // Keeping str as a string, ArrayBuffer/Uint8Array will not survive
74 // setIn/mergeIn operations.
75 const str
= atob(resp
.encoded
);
79 toString
: () => "[wasm]",
87 return source
.substring(0, source
.length
).then(function (resp
) {
101 exports
.SourceFront
= SourceFront
;
102 registerFront(SourceFront
);