Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: src/runtime.cc

Issue 2868046: Fix crash: handle all flat string types in regexp replace. (Closed)
Patch Set: Review fixes Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/string-replace-with-empty.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index e3a150d907419a10273d1cd8923d6566e1973811..f81bb8627f9f16b0ef3d8006cec5d668757cf0ff 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -2284,8 +2284,9 @@ static Object* StringReplaceRegExpWithString(String* subject,
return *(builder.ToString());
}
+
template <typename ResultSeqString>
-static Object* StringReplaceRegExpWithEmptyString(ResultSeqString* subject,
+static Object* StringReplaceRegExpWithEmptyString(String* subject,
JSRegExp* regexp,
JSArray* last_match_info) {
ASSERT(subject->IsFlat());
@@ -2320,9 +2321,8 @@ static Object* StringReplaceRegExpWithEmptyString(ResultSeqString* subject,
if (new_length == 0) {
return Heap::empty_string();
}
- // TODO(sandholm) try to use types statically to determine this.
Handle<ResultSeqString> answer;
- if (subject_handle->IsAsciiRepresentation()) {
+ if (ResultSeqString::kHasAsciiEncoding) {
answer =
Handle<ResultSeqString>::cast(Factory::NewRawAsciiString(new_length));
} else {
@@ -2440,14 +2440,12 @@ static Object* Runtime_StringReplaceRegExpWithString(Arguments args) {
ASSERT(last_match_info->HasFastElements());
if (replacement->length() == 0) {
- if (subject->IsAsciiRepresentation()) {
- return StringReplaceRegExpWithEmptyString(SeqAsciiString::cast(subject),
- regexp,
- last_match_info);
+ if (subject->IsAsciiRepresentation() || subject->HasOnlyAsciiChars()) {
Lasse Reichstein 2010/07/06 12:09:36 Does subject->IsAsciiRepresentation() imply subjec
Vitaly Repeshko 2010/07/06 12:22:39 Done.
+ return StringReplaceRegExpWithEmptyString<SeqAsciiString>(
+ subject, regexp, last_match_info);
} else {
- return StringReplaceRegExpWithEmptyString(SeqTwoByteString::cast(subject),
- regexp,
- last_match_info);
+ return StringReplaceRegExpWithEmptyString<SeqTwoByteString>(
+ subject, regexp, last_match_info);
}
}
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/string-replace-with-empty.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698