| 172 | } |
| 173 | |
| 174 | ensureSourceMapCalculated(sourceMapFetchPrefix=undefined) { |
| 175 | if (this._sourceMapState !== "unknown") return; |
| 176 | |
| 177 | const sourceMapURLMatch = |
| 178 | this.source.match(/\/\/# sourceMappingURL=(.*)\n/); |
| 179 | if (!sourceMapURLMatch) { |
| 180 | this._sourceMapState = "none"; |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | this._sourceMapState = "loading"; |
| 185 | let sourceMapURL = sourceMapURLMatch[1]; |
| 186 | (async () => { |
| 187 | try { |
| 188 | let sourceMapPayload; |
| 189 | const options = { timeout: 15 }; |
| 190 | try { |
| 191 | sourceMapPayload = await fetch(sourceMapURL, options); |
| 192 | } catch (e) { |
| 193 | if (e instanceof TypeError && sourceMapFetchPrefix) { |
| 194 | // Try again with fetch prefix. |
| 195 | // TODO(leszeks): Remove the retry once the prefix is |
| 196 | // configurable. |
| 197 | sourceMapPayload = |
| 198 | await fetch(sourceMapFetchPrefix + sourceMapURL, options); |
| 199 | } else { |
| 200 | throw e; |
| 201 | } |
| 202 | } |
| 203 | sourceMapPayload = await sourceMapPayload.text(); |
| 204 | |
| 205 | if (sourceMapPayload.startsWith(')]}')) { |
| 206 | sourceMapPayload = |
| 207 | sourceMapPayload.substring(sourceMapPayload.indexOf('\n')); |
| 208 | } |
| 209 | sourceMapPayload = JSON.parse(sourceMapPayload); |
| 210 | const sourceMap = |
| 211 | new WebInspector.SourceMap(sourceMapURL, sourceMapPayload); |
| 212 | |
| 213 | const startLine = this.startLine; |
| 214 | for (const sourcePosition of this.sourcePositions) { |
| 215 | const line = sourcePosition.line - startLine; |
| 216 | const column = sourcePosition.column - 1; |
| 217 | const mapping = sourceMap.findEntry(line, column); |
| 218 | if (mapping) { |
| 219 | sourcePosition.originalPosition = { |
| 220 | source: new URL(mapping[2], sourceMapURL).href, |
| 221 | line: mapping[3] + 1, |
| 222 | column: mapping[4] + 1 |
| 223 | }; |
| 224 | } else { |
| 225 | sourcePosition.originalPosition = {source: null, line:0, column:0}; |
| 226 | } |
| 227 | } |
| 228 | this._sourceMapState = "loaded"; |
| 229 | } catch (e) { |
| 230 | console.error(e); |
| 231 | this._sourceMapState = "failed"; |