Author: christian.plesner.han...@gmail.com Date: Tue Mar 10 04:32:19 2009 New Revision: 1473
Modified: branches/bleeding_edge/src/messages.js branches/bleeding_edge/src/parser.cc branches/bleeding_edge/src/regexp-delay.js branches/bleeding_edge/test/cctest/test-regexp.cc Log: Made the Error prototype into an error. Allow \c at the end of regexps. Throw a type error when calling regexp methods on non-regexps. Modified: branches/bleeding_edge/src/messages.js ============================================================================== --- branches/bleeding_edge/src/messages.js (original) +++ branches/bleeding_edge/src/messages.js Tue Mar 10 04:32:19 2009 @@ -628,8 +628,17 @@ %SetProperty(global, name, f, DONT_ENUM); this['$' + name] = f; // Configure the error function. - // prototype of 'Error' must be as default: new Object(). - if (name != 'Error') %FunctionSetPrototype(f, new $Error()); + if (name == 'Error') { + // The prototype of the Error object must itself be an error. + // However, it can't be an instance of the Error object because + // it hasn't been properly configured yet. Instead we create a + // special not-a-true-error-but-close-enough object. + function ErrorPrototype() {} + %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); + %FunctionSetPrototype(f, new ErrorPrototype()); + } else { + %FunctionSetPrototype(f, new $Error()); + } %FunctionSetInstanceClassName(f, 'Error'); %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); f.prototype.name = name; Modified: branches/bleeding_edge/src/parser.cc ============================================================================== --- branches/bleeding_edge/src/parser.cc (original) +++ branches/bleeding_edge/src/parser.cc Tue Mar 10 04:32:19 2009 @@ -4177,10 +4177,8 @@ STATIC_CHECK(('a' ^ 'A') == 0x20); uc32 RegExpParser::ParseControlLetterEscape() { - if (!has_more()) { - ReportError(CStrVector("\\c at end of pattern")); - return '\0'; - } + if (!has_more()) + return 'c'; uc32 letter = current() & ~(0x20); // Collapse upper and lower case letters. if (letter < 'A' || 'Z' < letter) { // Non-spec error-correction: "\c" followed by non-control letter is Modified: branches/bleeding_edge/src/regexp-delay.js ============================================================================== --- branches/bleeding_edge/src/regexp-delay.js (original) +++ branches/bleeding_edge/src/regexp-delay.js Tue Mar 10 04:32:19 2009 @@ -160,6 +160,9 @@ function RegExpExec(string) { + if (!IS_REGEXP(this)) { + throw MakeTypeError('method_called_on_incompatible', ['RegExp.prototype.exec', this]); + } if (%_ArgumentsLength() == 0) { if (IS_UNDEFINED(regExpInput)) { throw MakeError('no_input_to_regexp', [this]); Modified: branches/bleeding_edge/test/cctest/test-regexp.cc ============================================================================== --- branches/bleeding_edge/test/cctest/test-regexp.cc (original) +++ branches/bleeding_edge/test/cctest/test-regexp.cc Tue Mar 10 04:32:19 2009 @@ -214,6 +214,7 @@ CHECK_PARSE_EQ("\\x34", "'\x34'"); CHECK_PARSE_EQ("\\x60", "'\x60'"); CHECK_PARSE_EQ("\\x3z", "'x3z'"); + CHECK_PARSE_EQ("\\c", "'c'"); CHECK_PARSE_EQ("\\u0034", "'\x34'"); CHECK_PARSE_EQ("\\u003z", "'u003z'"); CHECK_PARSE_EQ("foo[z]*", "(: 'foo' (# 0 - g [z]))"); @@ -363,8 +364,6 @@ const char* kUnterminatedCharacterClass = "Unterminated character class"; ExpectError("[", kUnterminatedCharacterClass); ExpectError("[a-", kUnterminatedCharacterClass); - const char* kEndControl = "\\c at end of pattern"; - ExpectError("\\c", kEndControl); const char* kNothingToRepeat = "Nothing to repeat"; ExpectError("*", kNothingToRepeat); ExpectError("?", kNothingToRepeat); --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list v8-dev@googlegroups.com http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---