+ unsigned sourceLength = sourceText.length();
+ unsigned idx = sourceLength - 1;
+ if (sourceLength < 2 || sourceText[idx] != ')') {
+ // For function calls that have many new lines in between their open parenthesis
+ // and their closing parenthesis, the text range passed into the message appender
+ // will not inlcude the text in between these parentheses, it will just be the desired
+ // text that precedes the parentheses.
+ return sourceText;
+ }
+
+ unsigned parenStack = 1;
+ bool isInMultiLineComment = false;
+ idx -= 1;
+ // Note that we're scanning text right to left instead of the more common left to right,
+ // so syntax detection is backwards.
+ while (parenStack > 0) {
+ UChar curChar = sourceText[idx];
+ if (isInMultiLineComment) {
+ if (idx > 0 && curChar == '*' && sourceText[idx - 1] == '/') {
+ isInMultiLineComment = false;
+ idx -= 1;
+ }
+ } else if (curChar == '(')
+ parenStack -= 1;
+ else if (curChar == ')')
+ parenStack += 1;
+ else if (idx > 0 && curChar == '/' && sourceText[idx - 1] == '*') {
+ isInMultiLineComment = true;
+ idx -= 1;
+ }
+
+ if (!idx)
+ break;
+
+ idx -= 1;
+ }
+
+ return sourceText.left(idx + 1);
+}
+
+static String notAFunctionSourceAppender(const String& originalMessage, const String& sourceText, RuntimeType type, ErrorInstance::SourceTextWhereErrorOccurred occurrence)