Changeset 215852 in webkit


Ignore:
Timestamp:
Apr 26, 2017 7:28:39 PM (7 years ago)
Author:
sbarati@apple.com
Message:

ASSERTION FAILED: inIndex != notFound in JSC::invalidParameterInSourceAppender()
https://bugs.webkit.org/show_bug.cgi?id=170924
<rdar://problem/31721052>

Reviewed by Mark Lam.

JSTests:

  • stress/error-message-for-function-base-not-found.js: Added.

(assert):
(throw.new.Error):

  • stress/error-messages-for-in-operator-should-not-crash.js: Added.

(catch):

LayoutTests/imported/w3c:

  • web-platform-tests/css-timing-1/cubic-bezier-timing-functions-output-expected.txt:
  • web-platform-tests/css-timing-1/frames-timing-functions-output-expected.txt:
  • web-platform-tests/css-timing-1/step-timing-functions-output-expected.txt:

Source/JavaScriptCore:

The error message handler for "in" was searching for the literal
string "in". However, our parser incorrectly allows escaped characters
to be part of keywords. So this is parsed as "in" in JSC: "i\u006E".
It should not be parsed that way. I opened https://bugs.webkit.org/show_bug.cgi?id=171310
to address this issue.

Regardless, the error message handlers should handle unexpected text gracefully.
All functions that try to augment error messages with the goal of
providing a more textual context for the error message should use
the original error message instead of crashing when they detect
unexpected text.

This patch also changes the already buggy code that tries to find
the base of a function call. That could would fail for code like this:
"zoo.bar("/abc\)*/");". See https://bugs.webkit.org/show_bug.cgi?id=146304
It would think that the base is "z". However, the algorithm that tries
to find the base can often tell when it fails, and when it does, it should
happily return the approximate text error message instead of thinking
that the base is "z".

  • runtime/ExceptionHelpers.cpp:

(JSC::functionCallBase):
(JSC::notAFunctionSourceAppender):
(JSC::invalidParameterInSourceAppender):

LayoutTests:

  • js/let-syntax-expected.txt:
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r215843 r215852  
     12017-04-26  Saam Barati  <sbarati@apple.com>
     2
     3        ASSERTION FAILED: inIndex != notFound in JSC::invalidParameterInSourceAppender()
     4        https://bugs.webkit.org/show_bug.cgi?id=170924
     5        <rdar://problem/31721052>
     6
     7        Reviewed by Mark Lam.
     8
     9        * stress/error-message-for-function-base-not-found.js: Added.
     10        (assert):
     11        (throw.new.Error):
     12        * stress/error-messages-for-in-operator-should-not-crash.js: Added.
     13        (catch):
     14
    1152017-04-26  Keith Miller  <keith_miller@apple.com>
    216
  • trunk/JSTests/stress/destructuring-assignment-accepts-iterables.js

    r185791 r215852  
    123123        }
    124124    };
    125 }, "TypeError: [a, b, c] is not a function. (In '[a, b, c]', '[a, b, c]' is undefined)");
     125}, "TypeError: undefined is not a function (near '...[a, b, c]...')");
    126126
    127127shouldThrow(function () {
     
    131131        }
    132132    };
    133 }, "TypeError: [a, b, c] is not a function. (In '[a, b, c]', '[a, b, c]' is undefined)");
     133}, "TypeError: undefined is not a function (near '...[a, b, c]...')");
    134134
    135135shouldThrow(function () {
  • trunk/LayoutTests/ChangeLog

    r215850 r215852  
     12017-04-26  Saam Barati  <sbarati@apple.com>
     2
     3        ASSERTION FAILED: inIndex != notFound in JSC::invalidParameterInSourceAppender()
     4        https://bugs.webkit.org/show_bug.cgi?id=170924
     5        <rdar://problem/31721052>
     6
     7        Reviewed by Mark Lam.
     8
     9        * js/let-syntax-expected.txt:
     10
    1112017-04-26  Joanmarie Diggs  <jdiggs@igalia.com>
    212
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r215842 r215852  
     12017-04-26  Saam Barati  <sbarati@apple.com>
     2
     3        ASSERTION FAILED: inIndex != notFound in JSC::invalidParameterInSourceAppender()
     4        https://bugs.webkit.org/show_bug.cgi?id=170924
     5        <rdar://problem/31721052>
     6
     7        Reviewed by Mark Lam.
     8
     9        * web-platform-tests/css-timing-1/cubic-bezier-timing-functions-output-expected.txt:
     10        * web-platform-tests/css-timing-1/frames-timing-functions-output-expected.txt:
     11        * web-platform-tests/css-timing-1/step-timing-functions-output-expected.txt:
     12
    1132017-04-26  Ryan Haddad  <ryanhaddad@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css-timing-1/cubic-bezier-timing-functions-output-expected.txt

    r215164 r215852  
    11
    2 FAIL cubic-bezier easing with input progress greater than 1 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    3 FAIL cubic-bezier easing with input progress greater than 1 and where the tangent on the upper boundary is infinity target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    4 FAIL cubic-bezier easing with input progress less than 0 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    5 FAIL cubic-bezier easing with input progress less than 0 and where the tangent on the lower boundary is infinity target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
     2FAIL cubic-bezier easing with input progress greater than 1 undefined is not a function (near '...target.animate...')
     3FAIL cubic-bezier easing with input progress greater than 1 and where the tangent on the upper boundary is infinity undefined is not a function (near '...target.animate...')
     4FAIL cubic-bezier easing with input progress less than 0 undefined is not a function (near '...target.animate...')
     5FAIL cubic-bezier easing with input progress less than 0 and where the tangent on the lower boundary is infinity undefined is not a function (near '...target.animate...')
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css-timing-1/frames-timing-functions-output-expected.txt

    r215164 r215852  
    55FAIL The number of frames is correctly reflected in the frames timing function output assert_equals: expected "0px" but got "auto"
    66FAIL The number of frames is correctly reflected in the frames timing function output on CSS Transitions assert_equals: expected "0px" but got "auto"
    7 FAIL frames easing with input progress greater than 1 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    8 FAIL frames easing with input progress greater than 1.5 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    9 FAIL frames easing with input progress less than 0 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
     7FAIL frames easing with input progress greater than 1 undefined is not a function (near '...target.animate...')
     8FAIL frames easing with input progress greater than 1.5 undefined is not a function (near '...target.animate...')
     9FAIL frames easing with input progress less than 0 undefined is not a function (near '...target.animate...')
    1010
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css-timing-1/step-timing-functions-output-expected.txt

    r215164 r215852  
    11
    2 FAIL step-start easing with input progress greater than 1 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    3 FAIL step-end easing with input progress greater than 1 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    4 FAIL step-end easing with input progress greater than 2 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    5 FAIL step-start easing with input progress less than 0 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    6 FAIL step-start easing with input progress less than -1 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
    7 FAIL step-end easing with input progress less than 0 target.animate is not a function. (In 'target.animate', 'target.animate' is undefined)
     2FAIL step-start easing with input progress greater than 1 undefined is not a function (near '...target.animate...')
     3FAIL step-end easing with input progress greater than 1 undefined is not a function (near '...target.animate...')
     4FAIL step-end easing with input progress greater than 2 undefined is not a function (near '...target.animate...')
     5FAIL step-start easing with input progress less than 0 undefined is not a function (near '...target.animate...')
     6FAIL step-start easing with input progress less than -1 undefined is not a function (near '...target.animate...')
     7FAIL step-end easing with input progress less than 0 undefined is not a function (near '...target.animate...')
    88
  • trunk/LayoutTests/js/let-syntax-expected.txt

    r215682 r215852  
    405405SyntaxError: Cannot use abbreviated destructuring syntax for keyword 'let'.
    406406PASS Has syntax error: ''use strict'; var {let} = 40;'
    407 TypeError: [let] is not a function. (In '[let]', '[let]' is undefined)
     407TypeError: undefined is not a function (near '...[let]...')
    408408PASS Does not have syntax error: 'var [let] = 40;'
    409409SyntaxError: Cannot use 'let' as a variable name in strict mode.
  • trunk/Source/JavaScriptCore/ChangeLog

    r215843 r215852  
     12017-04-26  Saam Barati  <sbarati@apple.com>
     2
     3        ASSERTION FAILED: inIndex != notFound in JSC::invalidParameterInSourceAppender()
     4        https://bugs.webkit.org/show_bug.cgi?id=170924
     5        <rdar://problem/31721052>
     6
     7        Reviewed by Mark Lam.
     8
     9        The error message handler for "in" was searching for the literal
     10        string "in". However, our parser incorrectly allows escaped characters
     11        to be part of keywords. So this is parsed as "in" in JSC: "i\u006E".
     12        It should not be parsed that way. I opened https://bugs.webkit.org/show_bug.cgi?id=171310
     13        to address this issue.
     14       
     15        Regardless, the error message handlers should handle unexpected text gracefully.
     16        All functions that try to augment error messages with the goal of
     17        providing a more textual context for the error message should use
     18        the original error message instead of crashing when they detect
     19        unexpected text.
     20       
     21        This patch also changes the already buggy code that tries to find
     22        the base of a function call. That could would fail for code like this:
     23        "zoo.bar("/abc\)*/");". See https://bugs.webkit.org/show_bug.cgi?id=146304
     24        It would think that the base is "z". However, the algorithm that tries
     25        to find the base can often tell when it fails, and when it does, it should
     26        happily return the approximate text error message instead of thinking
     27        that the base is "z".
     28
     29        * runtime/ExceptionHelpers.cpp:
     30        (JSC::functionCallBase):
     31        (JSC::notAFunctionSourceAppender):
     32        (JSC::invalidParameterInSourceAppender):
     33
    1342017-04-26  Keith Miller  <keith_miller@apple.com>
    235
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp

    r215402 r215852  
    128128        // will not inlcude the text in between these parentheses, it will just be the desired
    129129        // text that precedes the parentheses.
    130         return sourceText;
     130        return String();
    131131    }
    132132
     
    136136    // Note that we're scanning text right to left instead of the more common left to right,
    137137    // so syntax detection is backwards.
    138     while (parenStack > 0) {
     138    while (parenStack && idx) {
    139139        UChar curChar = sourceText[idx];
    140         if (isInMultiLineComment)  {
    141             if (idx > 0 && curChar == '*' && sourceText[idx - 1] == '/') {
     140        if (isInMultiLineComment) {
     141            if (curChar == '*' && sourceText[idx - 1] == '/') {
    142142                isInMultiLineComment = false;
    143                 idx -= 1;
     143                --idx;
    144144            }
    145145        } else if (curChar == '(')
    146             parenStack -= 1;
     146            --parenStack;
    147147        else if (curChar == ')')
    148             parenStack += 1;
    149         else if (idx > 0 && curChar == '/' && sourceText[idx - 1] == '*') {
     148            ++parenStack;
     149        else if (curChar == '/' && sourceText[idx - 1] == '*') {
    150150            isInMultiLineComment = true;
    151             idx -= 1;
     151            --idx;
    152152        }
    153153
    154         if (!idx)
    155             break;
    156 
    157         idx -= 1;
     154        if (idx)
     155            --idx;
     156    }
     157
     158    if (parenStack) {
     159        // As noted in the FIXME at the top of this function, there are bugs
     160        // in the above string processing. This algorithm is mostly best effort
     161        // and it works for most JS text in practice. However, if we determine
     162        // that the algorithm failed, we should just return the empty value.
     163        return String();
    158164    }
    159165
     
    178184
    179185    String base = functionCallBase(sourceText);
     186    if (!base)
     187        return defaultApproximateSourceError(originalMessage, sourceText);
    180188    StringBuilder builder;
    181189    builder.append(base);
     
    206214    ASSERT(occurrence == ErrorInstance::FoundExactSource);
    207215    auto inIndex = sourceText.reverseFind("in");
    208     RELEASE_ASSERT(inIndex != notFound);
     216    if (inIndex == notFound) {
     217        // This should basically never happen, since JS code must use the literal
     218        // text "in" for the `in` operation. However, if we fail to find "in"
     219        // for any reason, just fail gracefully.
     220        return originalMessage;
     221    }
    209222    if (sourceText.find("in") != inIndex)
    210223        return makeString(originalMessage, " (evaluating '", sourceText, "')");
Note: See TracChangeset for help on using the changeset viewer.