Back out 8ae5fce0f19b.

This commit is contained in:
Chris Leary 2010-11-09 10:12:53 -08:00
parent 0cc4fbc8f7
commit 8a45dd1cea
5 changed files with 93 additions and 90 deletions

View File

@ -1,43 +0,0 @@
// Check that builtin character classes within ranges produce syntax
// errors.
function isRegExpSyntaxError(pattern) {
try {
var re = new RegExp(pattern);
} catch (e) {
if (e instanceof SyntaxError)
return true;
}
return false;
}
function testRangeSyntax(end1, end2, shouldFail) {
var makePattern = function(e1, e2) {
var pattern = '[' + e1 + '-' + e2 + ']';
print(uneval(pattern));
return pattern;
};
assertEq(isRegExpSyntaxError(makePattern(end1, end2)), shouldFail);
assertEq(isRegExpSyntaxError(makePattern(end2, end1)), shouldFail);
}
function checkRangeValid(end1, end2) {
testRangeSyntax(end1, end2, false);
}
function checkRangeInvalid(end1, end2) {
testRangeSyntax(end1, end2, true);
}
checkRangeInvalid('C', '\\s');
checkRangeInvalid('C', '\\d');
checkRangeInvalid('C', '\\W');
checkRangeInvalid('C', '\\W');
checkRangeValid('C', '');
checkRangeValid('C', 'C');
checkRangeInvalid('\\s', '\\s');
checkRangeInvalid('\\W', '\\s');
checkRangeValid('\\b', '\\b');
checkRangeValid('\\B', '\\B');
checkRangeInvalid('\\w', '\\B');
checkRangeInvalid('\\w', '\\b');

View File

@ -58,8 +58,6 @@
#include "jsobjinlines.h"
#include "jsregexpinlines.h"
#include "yarr/RegexParser.h"
#ifdef JS_TRACER
#include "jstracer.h"
using namespace avmplus;
@ -173,12 +171,26 @@ js_ObjectIsRegExp(JSObject *obj)
void
RegExp::handleYarrError(JSContext *cx, int error)
{
/* Hack: duplicated from yarr/yarr/RegexParser.h */
enum ErrorCode {
NoError,
PatternTooLarge,
QuantifierOutOfOrder,
QuantifierWithoutAtom,
MissingParentheses,
ParenthesesUnmatched,
ParenthesesTypeInvalid, /* "(?" with bad next char or end of pattern. */
CharacterClassUnmatched,
CharacterClassOutOfOrder,
QuantifierTooLarge,
EscapeUnterminated
};
switch (error) {
case JSC::Yarr::NoError:
case NoError:
JS_NOT_REACHED("Precondition violation: an error must have occurred.");
return;
#define COMPILE_EMSG(__code, __msg) \
case JSC::Yarr::__code: \
case __code: \
JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, __msg); \
return
COMPILE_EMSG(PatternTooLarge, JSMSG_REGEXP_TOO_COMPLEX);
@ -186,10 +198,9 @@ RegExp::handleYarrError(JSContext *cx, int error)
COMPILE_EMSG(QuantifierWithoutAtom, JSMSG_BAD_QUANTIFIER);
COMPILE_EMSG(MissingParentheses, JSMSG_MISSING_PAREN);
COMPILE_EMSG(ParenthesesUnmatched, JSMSG_UNMATCHED_RIGHT_PAREN);
COMPILE_EMSG(ParenthesesTypeInvalid, JSMSG_BAD_QUANTIFIER); /* "(?" with bad next char */
COMPILE_EMSG(ParenthesesTypeInvalid, JSMSG_BAD_QUANTIFIER);
COMPILE_EMSG(CharacterClassUnmatched, JSMSG_BAD_CLASS_RANGE);
COMPILE_EMSG(CharacterClassOutOfOrder, JSMSG_BAD_CLASS_RANGE);
COMPILE_EMSG(CharacterClassRangeSingleChar, JSMSG_BAD_CLASS_RANGE);
COMPILE_EMSG(EscapeUnterminated, JSMSG_TRAILING_SLASH);
COMPILE_EMSG(QuantifierTooLarge, JSMSG_BAD_QUANTIFIER);
#undef COMPILE_EMSG

View File

@ -53,6 +53,7 @@ script regress-375642.js
script regress-375651.js
script regress-375711.js
script regress-375715-01-n.js
script regress-375715-02.js
script regress-375715-03.js
script regress-375715-04.js
script regress-436700.js

View File

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Jesse Ruderman
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//-----------------------------------------------------------------------------
var BUGNUMBER = 375715;
var summary = 'Do not assert: (c2 <= cs->length) && (c1 <= c2)';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
/[\s-:]/;
reportCompare(expect, actual, summary + '/[\s-:]/');
exitFunc ('test');
}

View File

@ -39,22 +39,6 @@ enum BuiltInCharacterClassID {
NewlineClassID
};
enum ErrorCode {
NoError,
PatternTooLarge,
QuantifierOutOfOrder,
QuantifierWithoutAtom,
MissingParentheses,
ParenthesesUnmatched,
ParenthesesTypeInvalid,
CharacterClassUnmatched,
CharacterClassOutOfOrder,
CharacterClassRangeSingleChar,
EscapeUnterminated,
QuantifierTooLarge,
NumberOfErrorCodes
};
// The Parser class should not be used directly - only via the Yarr::parse() method.
template<class Delegate>
class Parser {
@ -62,6 +46,21 @@ private:
template<class FriendDelegate>
friend int parse(FriendDelegate& delegate, const UString& pattern, unsigned backReferenceLimit);
enum ErrorCode {
NoError,
PatternTooLarge,
QuantifierOutOfOrder,
QuantifierWithoutAtom,
MissingParentheses,
ParenthesesUnmatched,
ParenthesesTypeInvalid,
CharacterClassUnmatched,
CharacterClassOutOfOrder,
EscapeUnterminated,
QuantifierTooLarge,
NumberOfErrorCodes
};
/*
* CharacterClassParserDelegate:
*
@ -77,7 +76,6 @@ private:
: m_delegate(delegate)
, m_err(err)
, m_state(empty)
, m_sawCharacterClass(false)
{
}
@ -109,14 +107,6 @@ private:
break;
case cachedCharacter:
// This guard handles things like /[\s-d]/.
if ((m_character == '-') && m_sawCharacterClass) {
m_err = CharacterClassRangeSingleChar;
m_state = empty;
break;
}
m_sawCharacterClass = false;
if (ch == '-')
m_state = cachedCharacterHyphen;
else {
@ -148,7 +138,6 @@ private:
flush();
atomPatternCharacterUnescaped(ch);
m_sawCharacterClass = false;
}
/*
@ -158,20 +147,8 @@ private:
*/
void atomBuiltInCharacterClass(BuiltInCharacterClassID classID, bool invert)
{
// The first part of this guard handles things like /[a-\d]/ and the
// second part handles things like /[\w-\s]/.
if (m_state == cachedCharacterHyphen ||
(m_sawCharacterClass && (m_state == cachedCharacter) && m_character == '-')) {
// If the RHS of a range does not contain exacly one character then a SyntaxError
// must be thrown.
// Assumes none of the built in character classes contain a single character.
m_err = CharacterClassRangeSingleChar;
m_state = empty;
return;
}
flush();
m_delegate.atomCharacterClassBuiltIn(classID, invert);
m_sawCharacterClass = true;
}
/*
@ -207,8 +184,6 @@ private:
cachedCharacter,
cachedCharacterHyphen
} m_state;
// Used to verify that there is not a character class on the LHS of a range.
bool m_sawCharacterClass;
UChar m_character;
};
@ -429,7 +404,7 @@ private:
/*
* parseCharacterClass():
*
* Helper for parseTokens(); calls directly and indirectly (via parseCharacterClassEscape)
* Helper for parseTokens(); calls dirctly and indirectly (via parseCharacterClassEscape)
* to an instance of CharacterClassParserDelegate, to describe the character class to the
* delegate.
*/