⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 202933 in webkit


Ignore:
Timestamp:
Jul 7, 2016, 2:28:08 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector, regression: JS/JSON pretty-printing sporadically broken in STP8
https://bugs.webkit.org/show_bug.cgi?id=159511
<rdar://problem/27218435>

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2016-07-07
Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

  • UserInterface/Workers/Formatter/FormatterWorker.js:

(FormatterWorker.prototype.formatJavaScript):
Attempt to format invalid JSON that can be evaluated to an object.

LayoutTests:

  • inspector/formatting/formatting-json-expected.txt: Added.
  • inspector/formatting/formatting-json.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r202931 r202933  
     12016-07-07  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector, regression: JS/JSON pretty-printing sporadically broken in STP8
     4        https://bugs.webkit.org/show_bug.cgi?id=159511
     5        <rdar://problem/27218435>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * inspector/formatting/formatting-json-expected.txt: Added.
     10        * inspector/formatting/formatting-json.html: Added.
     11
    1122016-07-07  Antti Koivisto  <antti@apple.com>
    213
  • trunk/LayoutTests/inspector/formatting/formatting-javascript-expected.txt

    r199838 r202933  
    1 Test JavaScript formatting tests.
     1Test JavaScript formatting.
    22
    33
  • trunk/LayoutTests/inspector/formatting/formatting-javascript.html

    r199838 r202933  
    4343</head>
    4444<body onload="runTest()">
    45 <p>Test JavaScript formatting tests.</p>
     45<p>Test JavaScript formatting.</p>
    4646</body>
    4747</html>
  • trunk/Source/WebInspectorUI/ChangeLog

    r202932 r202933  
     12016-07-07  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector, regression: JS/JSON pretty-printing sporadically broken in STP8
     4        https://bugs.webkit.org/show_bug.cgi?id=159511
     5        <rdar://problem/27218435>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * UserInterface/Workers/Formatter/FormatterWorker.js:
     10        (FormatterWorker.prototype.formatJavaScript):
     11        Attempt to format invalid JSON that can be evaluated to an object.
     12
    1132016-07-07  Timothy Hatcher  <timothy@apple.com>
    214
  • trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterWorker.js

    r199168 r202933  
    4343    formatJavaScript(sourceText, indentString, includeSourceMapData)
    4444    {
     45        // Format a JavaScript program.
    4546        let formatter = new EsprimaFormatter(sourceText, indentString);
    4647        if (formatter.success) {
     
    5758        }
    5859
     60        // Format valid JSON.
    5961        // The formatter could fail if this was just a JSON string. So try a JSON.parse and stringify.
    6062        // This will produce empty source map data, but it is not code, so it is not as important.
     
    6668            return result;
    6769        } catch (e) {}
     70
     71        // Format invalid JSON.
     72        // Some applications do not use JSON.parse but eval on JSON content. That is more permissive
     73        // so try to format invalid JSON. Again no source map data since it is not code.
     74        if (/^\s*\{/.test(sourceText)) {
     75            let invalidJSONFormatter = new EsprimaFormatter("(" + sourceText + ")", indentString);
     76            if (invalidJSONFormatter.success) {
     77                let formattedTextWithParens = invalidJSONFormatter.formattedText;
     78                let result = {formattedText: formattedTextWithParens.substring(1, formattedTextWithParens.length - 2)}; // Remove "(" and ")\n".
     79                if (includeSourceMapData)
     80                    result.sourceMapData = {mapping: {original: [], formatted: []}, originalLineEndings:[], formattedLineEndings: []};
     81                return result;
     82            }
     83        }
    6884
    6985        return {formattedText: null};
Note: See TracChangeset for help on using the changeset viewer.