| Index: src/parser.cc
|
| diff --git a/src/parser.cc b/src/parser.cc
|
| index e34854fe7adacd564655429abd05a62caa2d4b20..81b1ca41d8d6bae2ea3a99eba2dae413ded30a9a 100644
|
| --- a/src/parser.cc
|
| +++ b/src/parser.cc
|
| @@ -4479,7 +4479,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
|
| case 'u': {
|
| Advance(2);
|
| uc32 value;
|
| - if (ParseHexEscape(4, &value)) {
|
| + if (ParseUnicodeEscape(&value)) {
|
| builder->AddCharacter(value);
|
| } else {
|
| builder->AddCharacter('u');
|
| @@ -4732,11 +4732,10 @@ uc32 RegExpParser::ParseOctalLiteral() {
|
| }
|
|
|
|
|
| -bool RegExpParser::ParseHexEscape(int length, uc32 *value) {
|
| +bool RegExpParser::ParseHexEscape(int length, uc32* value) {
|
| int start = position();
|
| uc32 val = 0;
|
| - bool done = false;
|
| - for (int i = 0; !done; i++) {
|
| + for (int i = 0; i < length; ++i) {
|
| uc32 c = current();
|
| int d = HexValue(c);
|
| if (d < 0) {
|
| @@ -4745,8 +4744,48 @@ bool RegExpParser::ParseHexEscape(int length, uc32 *value) {
|
| }
|
| val = val * 16 + d;
|
| Advance();
|
| - if (i == length - 1) {
|
| - done = true;
|
| + }
|
| + *value = val;
|
| + return true;
|
| +}
|
| +
|
| +
|
| +bool RegExpParser::ParseUnicodeEscape(uc32* value) {
|
| + if (current() == '{') {
|
| + int start = position();
|
| + Advance();
|
| + if (ParseUnlimitedLengthHexEscape(0x10ffff, value)) {
|
| + if (current() == '}') {
|
| + Advance();
|
| + return true;
|
| + }
|
| + Reset(start);
|
| + return false;
|
| + }
|
| + // Parsing the hex number failed.
|
| + Reset(start);
|
| + return false;
|
| + }
|
| + // \u but no {
|
| + return ParseHexEscape(4, value);
|
| +}
|
| +
|
| +
|
| +bool RegExpParser::ParseUnlimitedLengthHexEscape(int max_value, uc32* value) {
|
| + int start = position();
|
| + uc32 val = 0;
|
| + int d = HexValue(current());
|
| + if (d < 0) {
|
| + Reset(start);
|
| + return false;
|
| + }
|
| + while (d >= 0) {
|
| + val = val * 16 + d;
|
| + Advance();
|
| + d = HexValue(current());
|
| + if (val > max_value) {
|
| + Reset(start);
|
| + return false;
|
| }
|
| }
|
| *value = val;
|
| @@ -4815,11 +4854,12 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
|
| case 'u': {
|
| Advance();
|
| uc32 value;
|
| - if (ParseHexEscape(4, &value)) {
|
| + if (ParseUnicodeEscape(&value)) {
|
| + fprintf(stderr, "worked; returning code point %d\n", value);
|
| return value;
|
| }
|
| - // If \u is not followed by a four-digit hexadecimal, treat it
|
| - // as an identity escape.
|
| + // If \u is not followed by a legal hex decimal sequence, treat it as an
|
| + // identity escape.
|
| return 'u';
|
| }
|
| default: {
|
|
|