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

Side by Side Diff: src/runtime.cc

Issue 1565004: Fix bug in string replace with nonparticipating captures. (Closed)
Patch Set: Untabified. Created 10 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/string-replace.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 { 3350 {
3351 // Avoid accumulating new handles inside loop. 3351 // Avoid accumulating new handles inside loop.
3352 HandleScope temp_scope; 3352 HandleScope temp_scope;
3353 // Arguments array to replace function is match, captures, index and 3353 // Arguments array to replace function is match, captures, index and
3354 // subject, i.e., 3 + capture count in total. 3354 // subject, i.e., 3 + capture count in total.
3355 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count); 3355 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count);
3356 elements->set(0, *Factory::NewSubString(subject, 3356 elements->set(0, *Factory::NewSubString(subject,
3357 match_start, 3357 match_start,
3358 match_end)); 3358 match_end));
3359 for (int i = 1; i <= capture_count; i++) { 3359 for (int i = 1; i <= capture_count; i++) {
3360 Handle<String> substring = 3360 int start = register_vector[i * 2];
3361 Factory::NewSubString(subject, 3361 if (start >= 0) {
3362 register_vector[i * 2], 3362 int end = register_vector[i * 2 + 1];
3363 register_vector[i * 2 + 1]); 3363 ASSERT(start <= end);
3364 elements->set(i, *substring); 3364 Handle<String> substring = Factory::NewSubString(subject, start, end );
3365 elements->set(i, *substring);
3366 } else {
3367 ASSERT(register_vector[i * 2 + 1] < 0);
3368 elements->set(i, Heap::undefined_value());
3369 }
3365 } 3370 }
3366 elements->set(capture_count + 1, Smi::FromInt(match_start)); 3371 elements->set(capture_count + 1, Smi::FromInt(match_start));
3367 elements->set(capture_count + 2, *subject); 3372 elements->set(capture_count + 2, *subject);
3368 builder->Add(*Factory::NewJSArrayWithElements(elements)); 3373 builder->Add(*Factory::NewJSArrayWithElements(elements));
3369 } 3374 }
3370 // Swap register vectors, so the last successful match is in 3375 // Swap register vectors, so the last successful match is in
3371 // prev_register_vector. 3376 // prev_register_vector.
3372 Vector<int> tmp = prev_register_vector; 3377 Vector<int> tmp = prev_register_vector;
3373 prev_register_vector = register_vector; 3378 prev_register_vector = register_vector;
3374 register_vector = tmp; 3379 register_vector = tmp;
(...skipping 6657 matching lines...) Expand 10 before | Expand all | Expand 10 after
10032 } else { 10037 } else {
10033 // Handle last resort GC and make sure to allow future allocations 10038 // Handle last resort GC and make sure to allow future allocations
10034 // to grow the heap without causing GCs (if possible). 10039 // to grow the heap without causing GCs (if possible).
10035 Counters::gc_last_resort_from_js.Increment(); 10040 Counters::gc_last_resort_from_js.Increment();
10036 Heap::CollectAllGarbage(false); 10041 Heap::CollectAllGarbage(false);
10037 } 10042 }
10038 } 10043 }
10039 10044
10040 10045
10041 } } // namespace v8::internal 10046 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/string-replace.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698