Index: src/jsregexp.cc |
diff --git a/src/jsregexp.cc b/src/jsregexp.cc |
index 3e9c5eab9a51a3a8595106c795b73fbd8825b662..9f98782bbc19a375fec4a903040711a7b19b3760 100644 |
--- a/src/jsregexp.cc |
+++ b/src/jsregexp.cc |
@@ -356,7 +356,16 @@ int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
if (!subject->IsFlat()) { |
FlattenString(subject); |
} |
- bool is_ascii = subject->IsAsciiRepresentation(); |
+ // Check the asciiness of the underlying storage. |
+ bool is_ascii; |
+ { |
+ AssertNoAllocation no_gc; |
+ String* sequential_string = *subject; |
+ if (subject->IsConsString()) { |
+ sequential_string = ConsString::cast(*subject)->first(); |
+ } |
+ is_ascii = sequential_string->IsAsciiRepresentation(); |
+ } |
if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
return -1; |
} |
@@ -381,6 +390,11 @@ RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> regexp, |
ASSERT(index <= subject->length()); |
ASSERT(subject->IsFlat()); |
+ // A flat ASCII string might have a two-byte first part. |
+ if (subject->IsConsString()) { |
+ subject = Handle<String>(ConsString::cast(*subject)->first()); |
+ } |
+ |
#ifndef V8_INTERPRETED_REGEXP |
ASSERT(output.length() >= |
(IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
@@ -407,7 +421,7 @@ RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> regexp, |
// If result is RETRY, the string has changed representation, and we |
// must restart from scratch. |
// In this case, it means we must make sure we are prepared to handle |
- // the, potentially, differen subject (the string can switch between |
+ // the, potentially, different subject (the string can switch between |
// being internal and external, and even between being ASCII and UC16, |
// but the characters are always the same). |
IrregexpPrepare(regexp, subject); |