11cb0ef41Sopenharmony_ci// Copyright 2013 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Redistribution and use in source and binary forms, with or without
31cb0ef41Sopenharmony_ci// modification, are permitted provided that the following conditions are
41cb0ef41Sopenharmony_ci// met:
51cb0ef41Sopenharmony_ci//
61cb0ef41Sopenharmony_ci//     * Redistributions of source code must retain the above copyright
71cb0ef41Sopenharmony_ci//       notice, this list of conditions and the following disclaimer.
81cb0ef41Sopenharmony_ci//     * Redistributions in binary form must reproduce the above
91cb0ef41Sopenharmony_ci//       copyright notice, this list of conditions and the following
101cb0ef41Sopenharmony_ci//       disclaimer in the documentation and/or other materials provided
111cb0ef41Sopenharmony_ci//       with the distribution.
121cb0ef41Sopenharmony_ci//     * Neither the name of Google Inc. nor the names of its
131cb0ef41Sopenharmony_ci//       contributors may be used to endorse or promote products derived
141cb0ef41Sopenharmony_ci//       from this software without specific prior written permission.
151cb0ef41Sopenharmony_ci//
161cb0ef41Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171cb0ef41Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181cb0ef41Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191cb0ef41Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201cb0ef41Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211cb0ef41Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221cb0ef41Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231cb0ef41Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241cb0ef41Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251cb0ef41Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261cb0ef41Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci// This is a copy from blink dev tools, see:
291cb0ef41Sopenharmony_ci// http://src.chromium.org/viewvc/blink/trunk/Source/devtools/front_end/SourceMap.js
301cb0ef41Sopenharmony_ci// revision: 153407
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci// Added to make the file work without dev tools
331cb0ef41Sopenharmony_ciexport const WebInspector = {};
341cb0ef41Sopenharmony_ciWebInspector.ParsedURL = {};
351cb0ef41Sopenharmony_ciWebInspector.ParsedURL.completeURL = function(){};
361cb0ef41Sopenharmony_ci// start of original file content
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci/*
391cb0ef41Sopenharmony_ci * Copyright (C) 2012 Google Inc. All rights reserved.
401cb0ef41Sopenharmony_ci *
411cb0ef41Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
421cb0ef41Sopenharmony_ci * modification, are permitted provided that the following conditions are
431cb0ef41Sopenharmony_ci * met:
441cb0ef41Sopenharmony_ci *
451cb0ef41Sopenharmony_ci *     * Redistributions of source code must retain the above copyright
461cb0ef41Sopenharmony_ci * notice, this list of conditions and the following disclaimer.
471cb0ef41Sopenharmony_ci *     * Redistributions in binary form must reproduce the above
481cb0ef41Sopenharmony_ci * copyright notice, this list of conditions and the following disclaimer
491cb0ef41Sopenharmony_ci * in the documentation and/or other materials provided with the
501cb0ef41Sopenharmony_ci * distribution.
511cb0ef41Sopenharmony_ci *     * Neither the name of Google Inc. nor the names of its
521cb0ef41Sopenharmony_ci * contributors may be used to endorse or promote products derived from
531cb0ef41Sopenharmony_ci * this software without specific prior written permission.
541cb0ef41Sopenharmony_ci *
551cb0ef41Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
561cb0ef41Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
571cb0ef41Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
581cb0ef41Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
591cb0ef41Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
601cb0ef41Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
611cb0ef41Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
621cb0ef41Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
631cb0ef41Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
641cb0ef41Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
651cb0ef41Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
661cb0ef41Sopenharmony_ci */
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci/**
691cb0ef41Sopenharmony_ci * Implements Source Map V3 model. See http://code.google.com/p/closure-compiler/wiki/SourceMaps
701cb0ef41Sopenharmony_ci * for format description.
711cb0ef41Sopenharmony_ci * @constructor
721cb0ef41Sopenharmony_ci * @param {string} sourceMappingURL
731cb0ef41Sopenharmony_ci * @param {SourceMapV3} payload
741cb0ef41Sopenharmony_ci */
751cb0ef41Sopenharmony_ciWebInspector.SourceMap = function(sourceMappingURL, payload)
761cb0ef41Sopenharmony_ci{
771cb0ef41Sopenharmony_ci    if (!WebInspector.SourceMap.prototype._base64Map) {
781cb0ef41Sopenharmony_ci        const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
791cb0ef41Sopenharmony_ci        WebInspector.SourceMap.prototype._base64Map = {};
801cb0ef41Sopenharmony_ci        for (let i = 0; i < base64Digits.length; ++i)
811cb0ef41Sopenharmony_ci            WebInspector.SourceMap.prototype._base64Map[base64Digits.charAt(i)] = i;
821cb0ef41Sopenharmony_ci    }
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ci    this._sourceMappingURL = sourceMappingURL;
851cb0ef41Sopenharmony_ci    this._reverseMappingsBySourceURL = {};
861cb0ef41Sopenharmony_ci    this._mappings = [];
871cb0ef41Sopenharmony_ci    this._sources = {};
881cb0ef41Sopenharmony_ci    this._sourceContentByURL = {};
891cb0ef41Sopenharmony_ci    this._parseMappingPayload(payload);
901cb0ef41Sopenharmony_ci}
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci/**
931cb0ef41Sopenharmony_ci * @param {string} sourceMapURL
941cb0ef41Sopenharmony_ci * @param {string} compiledURL
951cb0ef41Sopenharmony_ci * @param {function(WebInspector.SourceMap)} callback
961cb0ef41Sopenharmony_ci */
971cb0ef41Sopenharmony_ciWebInspector.SourceMap.load = function(sourceMapURL, compiledURL, callback)
981cb0ef41Sopenharmony_ci{
991cb0ef41Sopenharmony_ci    NetworkAgent.loadResourceForFrontend(WebInspector.resourceTreeModel.mainFrame.id, sourceMapURL, undefined, contentLoaded.bind(this));
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci    /**
1021cb0ef41Sopenharmony_ci     * @param {?Protocol.Error} error
1031cb0ef41Sopenharmony_ci     * @param {number} statusCode
1041cb0ef41Sopenharmony_ci     * @param {NetworkAgent.Headers} headers
1051cb0ef41Sopenharmony_ci     * @param {string} content
1061cb0ef41Sopenharmony_ci     */
1071cb0ef41Sopenharmony_ci    function contentLoaded(error, statusCode, headers, content)
1081cb0ef41Sopenharmony_ci    {
1091cb0ef41Sopenharmony_ci        if (error || !content || statusCode >= 400) {
1101cb0ef41Sopenharmony_ci            console.error(`Could not load content for ${sourceMapURL} : ${error || (`HTTP status code: ${statusCode}`)}`);
1111cb0ef41Sopenharmony_ci            callback(null);
1121cb0ef41Sopenharmony_ci            return;
1131cb0ef41Sopenharmony_ci        }
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci        if (content.slice(0, 3) === ")]}")
1161cb0ef41Sopenharmony_ci            content = content.substring(content.indexOf('\n'));
1171cb0ef41Sopenharmony_ci        try {
1181cb0ef41Sopenharmony_ci            const payload = /** @type {SourceMapV3} */ (JSON.parse(content));
1191cb0ef41Sopenharmony_ci            const baseURL = sourceMapURL.startsWith("data:") ? compiledURL : sourceMapURL;
1201cb0ef41Sopenharmony_ci            callback(new WebInspector.SourceMap(baseURL, payload));
1211cb0ef41Sopenharmony_ci        } catch(e) {
1221cb0ef41Sopenharmony_ci            console.error(e.message);
1231cb0ef41Sopenharmony_ci            callback(null);
1241cb0ef41Sopenharmony_ci        }
1251cb0ef41Sopenharmony_ci    }
1261cb0ef41Sopenharmony_ci}
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ciWebInspector.SourceMap.prototype = {
1291cb0ef41Sopenharmony_ci    /**
1301cb0ef41Sopenharmony_ci     * @return {Array.<string>}
1311cb0ef41Sopenharmony_ci     */
1321cb0ef41Sopenharmony_ci    sources()
1331cb0ef41Sopenharmony_ci    {
1341cb0ef41Sopenharmony_ci        return Object.keys(this._sources);
1351cb0ef41Sopenharmony_ci    },
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci    /**
1381cb0ef41Sopenharmony_ci     * @param {string} sourceURL
1391cb0ef41Sopenharmony_ci     * @return {string|undefined}
1401cb0ef41Sopenharmony_ci     */
1411cb0ef41Sopenharmony_ci    sourceContent(sourceURL)
1421cb0ef41Sopenharmony_ci    {
1431cb0ef41Sopenharmony_ci        return this._sourceContentByURL[sourceURL];
1441cb0ef41Sopenharmony_ci    },
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci    /**
1471cb0ef41Sopenharmony_ci     * @param {string} sourceURL
1481cb0ef41Sopenharmony_ci     * @param {WebInspector.ResourceType} contentType
1491cb0ef41Sopenharmony_ci     * @return {WebInspector.ContentProvider}
1501cb0ef41Sopenharmony_ci     */
1511cb0ef41Sopenharmony_ci    sourceContentProvider(sourceURL, contentType)
1521cb0ef41Sopenharmony_ci    {
1531cb0ef41Sopenharmony_ci        const lastIndexOfDot = sourceURL.lastIndexOf(".");
1541cb0ef41Sopenharmony_ci        const extension = lastIndexOfDot !== -1 ? sourceURL.substr(lastIndexOfDot + 1) : "";
1551cb0ef41Sopenharmony_ci        const mimeType = WebInspector.ResourceType.mimeTypesForExtensions[extension.toLowerCase()];
1561cb0ef41Sopenharmony_ci        const sourceContent = this.sourceContent(sourceURL);
1571cb0ef41Sopenharmony_ci        if (sourceContent)
1581cb0ef41Sopenharmony_ci            return new WebInspector.StaticContentProvider(contentType, sourceContent, mimeType);
1591cb0ef41Sopenharmony_ci        return new WebInspector.CompilerSourceMappingContentProvider(sourceURL, contentType, mimeType);
1601cb0ef41Sopenharmony_ci    },
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci    /**
1631cb0ef41Sopenharmony_ci     * @param {SourceMapV3} mappingPayload
1641cb0ef41Sopenharmony_ci     */
1651cb0ef41Sopenharmony_ci    _parseMappingPayload(mappingPayload)
1661cb0ef41Sopenharmony_ci    {
1671cb0ef41Sopenharmony_ci        if (mappingPayload.sections)
1681cb0ef41Sopenharmony_ci            this._parseSections(mappingPayload.sections);
1691cb0ef41Sopenharmony_ci        else
1701cb0ef41Sopenharmony_ci            this._parseMap(mappingPayload, 0, 0);
1711cb0ef41Sopenharmony_ci    },
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ci    /**
1741cb0ef41Sopenharmony_ci     * @param {Array.<SourceMapV3.Section>} sections
1751cb0ef41Sopenharmony_ci     */
1761cb0ef41Sopenharmony_ci    _parseSections(sections)
1771cb0ef41Sopenharmony_ci    {
1781cb0ef41Sopenharmony_ci        for (let i = 0; i < sections.length; ++i) {
1791cb0ef41Sopenharmony_ci            const section = sections[i];
1801cb0ef41Sopenharmony_ci            this._parseMap(section.map, section.offset.line, section.offset.column);
1811cb0ef41Sopenharmony_ci        }
1821cb0ef41Sopenharmony_ci    },
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci    /**
1851cb0ef41Sopenharmony_ci     * @param {number} lineNumber in compiled resource
1861cb0ef41Sopenharmony_ci     * @param {number} columnNumber in compiled resource
1871cb0ef41Sopenharmony_ci     * @return {?Array}
1881cb0ef41Sopenharmony_ci     */
1891cb0ef41Sopenharmony_ci    findEntry(lineNumber, columnNumber)
1901cb0ef41Sopenharmony_ci    {
1911cb0ef41Sopenharmony_ci        let first = 0;
1921cb0ef41Sopenharmony_ci        let count = this._mappings.length;
1931cb0ef41Sopenharmony_ci        while (count > 1) {
1941cb0ef41Sopenharmony_ci          const step = count >> 1;
1951cb0ef41Sopenharmony_ci          const middle = first + step;
1961cb0ef41Sopenharmony_ci          const mapping = this._mappings[middle];
1971cb0ef41Sopenharmony_ci          if (lineNumber < mapping[0] || (lineNumber === mapping[0] && columnNumber < mapping[1]))
1981cb0ef41Sopenharmony_ci              count = step;
1991cb0ef41Sopenharmony_ci          else {
2001cb0ef41Sopenharmony_ci              first = middle;
2011cb0ef41Sopenharmony_ci              count -= step;
2021cb0ef41Sopenharmony_ci          }
2031cb0ef41Sopenharmony_ci        }
2041cb0ef41Sopenharmony_ci        const entry = this._mappings[first];
2051cb0ef41Sopenharmony_ci        if (!first && entry && (lineNumber < entry[0] || (lineNumber === entry[0] && columnNumber < entry[1])))
2061cb0ef41Sopenharmony_ci            return null;
2071cb0ef41Sopenharmony_ci        return entry;
2081cb0ef41Sopenharmony_ci    },
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ci    /**
2111cb0ef41Sopenharmony_ci     * @param {string} sourceURL of the originating resource
2121cb0ef41Sopenharmony_ci     * @param {number} lineNumber in the originating resource
2131cb0ef41Sopenharmony_ci     * @return {Array}
2141cb0ef41Sopenharmony_ci     */
2151cb0ef41Sopenharmony_ci    findEntryReversed(sourceURL, lineNumber)
2161cb0ef41Sopenharmony_ci    {
2171cb0ef41Sopenharmony_ci        const mappings = this._reverseMappingsBySourceURL[sourceURL];
2181cb0ef41Sopenharmony_ci        for ( ; lineNumber < mappings.length; ++lineNumber) {
2191cb0ef41Sopenharmony_ci            const mapping = mappings[lineNumber];
2201cb0ef41Sopenharmony_ci            if (mapping)
2211cb0ef41Sopenharmony_ci                return mapping;
2221cb0ef41Sopenharmony_ci        }
2231cb0ef41Sopenharmony_ci        return this._mappings[0];
2241cb0ef41Sopenharmony_ci    },
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ci    /**
2271cb0ef41Sopenharmony_ci     * @override
2281cb0ef41Sopenharmony_ci     */
2291cb0ef41Sopenharmony_ci    _parseMap(map, lineNumber, columnNumber)
2301cb0ef41Sopenharmony_ci    {
2311cb0ef41Sopenharmony_ci        let sourceIndex = 0;
2321cb0ef41Sopenharmony_ci        let sourceLineNumber = 0;
2331cb0ef41Sopenharmony_ci        let sourceColumnNumber = 0;
2341cb0ef41Sopenharmony_ci        let nameIndex = 0;
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ci        const sources = [];
2371cb0ef41Sopenharmony_ci        const originalToCanonicalURLMap = {};
2381cb0ef41Sopenharmony_ci        for (let i = 0; i < map.sources.length; ++i) {
2391cb0ef41Sopenharmony_ci            const originalSourceURL = map.sources[i];
2401cb0ef41Sopenharmony_ci            let sourceRoot = map.sourceRoot || "";
2411cb0ef41Sopenharmony_ci            if (sourceRoot && !sourceRoot.endsWith("/")) sourceRoot += "/";
2421cb0ef41Sopenharmony_ci            const href = sourceRoot + originalSourceURL;
2431cb0ef41Sopenharmony_ci            const url = WebInspector.ParsedURL.completeURL(this._sourceMappingURL, href) || href;
2441cb0ef41Sopenharmony_ci            originalToCanonicalURLMap[originalSourceURL] = url;
2451cb0ef41Sopenharmony_ci            sources.push(url);
2461cb0ef41Sopenharmony_ci            this._sources[url] = true;
2471cb0ef41Sopenharmony_ci
2481cb0ef41Sopenharmony_ci            if (map.sourcesContent && map.sourcesContent[i]) {
2491cb0ef41Sopenharmony_ci                this._sourceContentByURL[url] = map.sourcesContent[i];
2501cb0ef41Sopenharmony_ci            }
2511cb0ef41Sopenharmony_ci        }
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_ci        const stringCharIterator = new WebInspector.SourceMap.StringCharIterator(map.mappings);
2541cb0ef41Sopenharmony_ci        let sourceURL = sources[sourceIndex];
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_ci        while (true) {
2571cb0ef41Sopenharmony_ci            if (stringCharIterator.peek() === ",")
2581cb0ef41Sopenharmony_ci                stringCharIterator.next();
2591cb0ef41Sopenharmony_ci            else {
2601cb0ef41Sopenharmony_ci                while (stringCharIterator.peek() === ";") {
2611cb0ef41Sopenharmony_ci                    lineNumber += 1;
2621cb0ef41Sopenharmony_ci                    columnNumber = 0;
2631cb0ef41Sopenharmony_ci                    stringCharIterator.next();
2641cb0ef41Sopenharmony_ci                }
2651cb0ef41Sopenharmony_ci                if (!stringCharIterator.hasNext())
2661cb0ef41Sopenharmony_ci                    break;
2671cb0ef41Sopenharmony_ci            }
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_ci            columnNumber += this._decodeVLQ(stringCharIterator);
2701cb0ef41Sopenharmony_ci            if (this._isSeparator(stringCharIterator.peek())) {
2711cb0ef41Sopenharmony_ci                this._mappings.push([lineNumber, columnNumber]);
2721cb0ef41Sopenharmony_ci                continue;
2731cb0ef41Sopenharmony_ci            }
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_ci            const sourceIndexDelta = this._decodeVLQ(stringCharIterator);
2761cb0ef41Sopenharmony_ci            if (sourceIndexDelta) {
2771cb0ef41Sopenharmony_ci                sourceIndex += sourceIndexDelta;
2781cb0ef41Sopenharmony_ci                sourceURL = sources[sourceIndex];
2791cb0ef41Sopenharmony_ci            }
2801cb0ef41Sopenharmony_ci            sourceLineNumber += this._decodeVLQ(stringCharIterator);
2811cb0ef41Sopenharmony_ci            sourceColumnNumber += this._decodeVLQ(stringCharIterator);
2821cb0ef41Sopenharmony_ci            if (!this._isSeparator(stringCharIterator.peek()))
2831cb0ef41Sopenharmony_ci                nameIndex += this._decodeVLQ(stringCharIterator);
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ci            this._mappings.push([lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber]);
2861cb0ef41Sopenharmony_ci        }
2871cb0ef41Sopenharmony_ci
2881cb0ef41Sopenharmony_ci        for (let i = 0; i < this._mappings.length; ++i) {
2891cb0ef41Sopenharmony_ci            const mapping = this._mappings[i];
2901cb0ef41Sopenharmony_ci            const url = mapping[2];
2911cb0ef41Sopenharmony_ci            if (!url) continue;
2921cb0ef41Sopenharmony_ci            if (!this._reverseMappingsBySourceURL[url]) {
2931cb0ef41Sopenharmony_ci                this._reverseMappingsBySourceURL[url] = [];
2941cb0ef41Sopenharmony_ci            }
2951cb0ef41Sopenharmony_ci            const reverseMappings = this._reverseMappingsBySourceURL[url];
2961cb0ef41Sopenharmony_ci            const sourceLine = mapping[3];
2971cb0ef41Sopenharmony_ci            if (!reverseMappings[sourceLine]) {
2981cb0ef41Sopenharmony_ci                reverseMappings[sourceLine] = [mapping[0], mapping[1]];
2991cb0ef41Sopenharmony_ci            }
3001cb0ef41Sopenharmony_ci        }
3011cb0ef41Sopenharmony_ci    },
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ci    /**
3041cb0ef41Sopenharmony_ci     * @param {string} char
3051cb0ef41Sopenharmony_ci     * @return {boolean}
3061cb0ef41Sopenharmony_ci     */
3071cb0ef41Sopenharmony_ci    _isSeparator(char)
3081cb0ef41Sopenharmony_ci    {
3091cb0ef41Sopenharmony_ci        return char === "," || char === ";";
3101cb0ef41Sopenharmony_ci    },
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci    /**
3131cb0ef41Sopenharmony_ci     * @param {WebInspector.SourceMap.StringCharIterator} stringCharIterator
3141cb0ef41Sopenharmony_ci     * @return {number}
3151cb0ef41Sopenharmony_ci     */
3161cb0ef41Sopenharmony_ci    _decodeVLQ(stringCharIterator)
3171cb0ef41Sopenharmony_ci    {
3181cb0ef41Sopenharmony_ci        // Read unsigned value.
3191cb0ef41Sopenharmony_ci        let result = 0;
3201cb0ef41Sopenharmony_ci        let shift = 0;
3211cb0ef41Sopenharmony_ci        let digit;
3221cb0ef41Sopenharmony_ci        do {
3231cb0ef41Sopenharmony_ci            digit = this._base64Map[stringCharIterator.next()];
3241cb0ef41Sopenharmony_ci            result += (digit & this._VLQ_BASE_MASK) << shift;
3251cb0ef41Sopenharmony_ci            shift += this._VLQ_BASE_SHIFT;
3261cb0ef41Sopenharmony_ci        } while (digit & this._VLQ_CONTINUATION_MASK);
3271cb0ef41Sopenharmony_ci
3281cb0ef41Sopenharmony_ci        // Fix the sign.
3291cb0ef41Sopenharmony_ci        const negate = result & 1;
3301cb0ef41Sopenharmony_ci        // Use unsigned right shift, so that the 32nd bit is properly shifted
3311cb0ef41Sopenharmony_ci        // to the 31st, and the 32nd becomes unset.
3321cb0ef41Sopenharmony_ci        result >>>= 1;
3331cb0ef41Sopenharmony_ci        if (negate) {
3341cb0ef41Sopenharmony_ci          // We need to OR 0x80000000 here to ensure the 32nd bit (the sign bit
3351cb0ef41Sopenharmony_ci          // in a 32bit int) is always set for negative numbers. If `result`
3361cb0ef41Sopenharmony_ci          // were 1, (meaning `negate` is true and all other bits were zeros),
3371cb0ef41Sopenharmony_ci          // `result` would now be 0. But -0 doesn't flip the 32nd bit as
3381cb0ef41Sopenharmony_ci          // intended. All other numbers will successfully set the 32nd bit
3391cb0ef41Sopenharmony_ci          // without issue, so doing this is a noop for them.
3401cb0ef41Sopenharmony_ci          return -result | 0x80000000;
3411cb0ef41Sopenharmony_ci        }
3421cb0ef41Sopenharmony_ci        return result;
3431cb0ef41Sopenharmony_ci    },
3441cb0ef41Sopenharmony_ci
3451cb0ef41Sopenharmony_ci    _VLQ_BASE_SHIFT: 5,
3461cb0ef41Sopenharmony_ci    _VLQ_BASE_MASK: (1 << 5) - 1,
3471cb0ef41Sopenharmony_ci    _VLQ_CONTINUATION_MASK: 1 << 5
3481cb0ef41Sopenharmony_ci}
3491cb0ef41Sopenharmony_ci
3501cb0ef41Sopenharmony_ci/**
3511cb0ef41Sopenharmony_ci * @constructor
3521cb0ef41Sopenharmony_ci * @param {string} string
3531cb0ef41Sopenharmony_ci */
3541cb0ef41Sopenharmony_ciWebInspector.SourceMap.StringCharIterator = function(string)
3551cb0ef41Sopenharmony_ci{
3561cb0ef41Sopenharmony_ci    this._string = string;
3571cb0ef41Sopenharmony_ci    this._position = 0;
3581cb0ef41Sopenharmony_ci}
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ciWebInspector.SourceMap.StringCharIterator.prototype = {
3611cb0ef41Sopenharmony_ci    /**
3621cb0ef41Sopenharmony_ci     * @return {string}
3631cb0ef41Sopenharmony_ci     */
3641cb0ef41Sopenharmony_ci    next()
3651cb0ef41Sopenharmony_ci    {
3661cb0ef41Sopenharmony_ci        return this._string.charAt(this._position++);
3671cb0ef41Sopenharmony_ci    },
3681cb0ef41Sopenharmony_ci
3691cb0ef41Sopenharmony_ci    /**
3701cb0ef41Sopenharmony_ci     * @return {string}
3711cb0ef41Sopenharmony_ci     */
3721cb0ef41Sopenharmony_ci    peek()
3731cb0ef41Sopenharmony_ci    {
3741cb0ef41Sopenharmony_ci        return this._string.charAt(this._position);
3751cb0ef41Sopenharmony_ci    },
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ci    /**
3781cb0ef41Sopenharmony_ci     * @return {boolean}
3791cb0ef41Sopenharmony_ci     */
3801cb0ef41Sopenharmony_ci    hasNext()
3811cb0ef41Sopenharmony_ci    {
3821cb0ef41Sopenharmony_ci        return this._position < this._string.length;
3831cb0ef41Sopenharmony_ci    }
3841cb0ef41Sopenharmony_ci}
385