| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
| 9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { | 485 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { |
| 486 if (subject->HasOnlyOneByteChars() && replacement->HasOnlyOneByteChars()) { | 486 if (subject->HasOnlyOneByteChars() && replacement->HasOnlyOneByteChars()) { |
| 487 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( | 487 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( |
| 488 isolate, subject, regexp, replacement, last_match_info); | 488 isolate, subject, regexp, replacement, last_match_info); |
| 489 } else { | 489 } else { |
| 490 return StringReplaceGlobalAtomRegExpWithString<SeqTwoByteString>( | 490 return StringReplaceGlobalAtomRegExpWithString<SeqTwoByteString>( |
| 491 isolate, subject, regexp, replacement, last_match_info); | 491 isolate, subject, regexp, replacement, last_match_info); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 | 494 |
| 495 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); | 495 RegExpImpl::GlobalCache global_cache(regexp, subject, isolate); |
| 496 if (global_cache.HasException()) return isolate->heap()->exception(); | 496 if (global_cache.HasException()) return isolate->heap()->exception(); |
| 497 | 497 |
| 498 int32_t* current_match = global_cache.FetchNext(); | 498 int32_t* current_match = global_cache.FetchNext(); |
| 499 if (current_match == NULL) { | 499 if (current_match == NULL) { |
| 500 if (global_cache.HasException()) return isolate->heap()->exception(); | 500 if (global_cache.HasException()) return isolate->heap()->exception(); |
| 501 return *subject; | 501 return *subject; |
| 502 } | 502 } |
| 503 | 503 |
| 504 // Guessing the number of parts that the final result string is built | 504 // Guessing the number of parts that the final result string is built |
| 505 // from. Global regexps can match any number of times, so we guess | 505 // from. Global regexps can match any number of times, so we guess |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 Handle<String> empty_string = isolate->factory()->empty_string(); | 561 Handle<String> empty_string = isolate->factory()->empty_string(); |
| 562 if (subject->IsOneByteRepresentation()) { | 562 if (subject->IsOneByteRepresentation()) { |
| 563 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( | 563 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( |
| 564 isolate, subject, regexp, empty_string, last_match_info); | 564 isolate, subject, regexp, empty_string, last_match_info); |
| 565 } else { | 565 } else { |
| 566 return StringReplaceGlobalAtomRegExpWithString<SeqTwoByteString>( | 566 return StringReplaceGlobalAtomRegExpWithString<SeqTwoByteString>( |
| 567 isolate, subject, regexp, empty_string, last_match_info); | 567 isolate, subject, regexp, empty_string, last_match_info); |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 | 570 |
| 571 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); | 571 RegExpImpl::GlobalCache global_cache(regexp, subject, isolate); |
| 572 if (global_cache.HasException()) return isolate->heap()->exception(); | 572 if (global_cache.HasException()) return isolate->heap()->exception(); |
| 573 | 573 |
| 574 int32_t* current_match = global_cache.FetchNext(); | 574 int32_t* current_match = global_cache.FetchNext(); |
| 575 if (current_match == NULL) { | 575 if (current_match == NULL) { |
| 576 if (global_cache.HasException()) return isolate->heap()->exception(); | 576 if (global_cache.HasException()) return isolate->heap()->exception(); |
| 577 return *subject; | 577 return *subject; |
| 578 } | 578 } |
| 579 | 579 |
| 580 int start = current_match[0]; | 580 int start = current_match[0]; |
| 581 int end = current_match[1]; | 581 int end = current_match[1]; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 Handle<FixedArray>(FixedArray::cast(cached_answer)); | 869 Handle<FixedArray>(FixedArray::cast(cached_answer)); |
| 870 // The cache FixedArray is a COW-array and can therefore be reused. | 870 // The cache FixedArray is a COW-array and can therefore be reused. |
| 871 JSArray::SetContent(result_array, cached_fixed_array); | 871 JSArray::SetContent(result_array, cached_fixed_array); |
| 872 RegExpImpl::SetLastMatchInfo(last_match_array, subject, capture_count, | 872 RegExpImpl::SetLastMatchInfo(last_match_array, subject, capture_count, |
| 873 last_match); | 873 last_match); |
| 874 DeleteArray(last_match); | 874 DeleteArray(last_match); |
| 875 return *result_array; | 875 return *result_array; |
| 876 } | 876 } |
| 877 } | 877 } |
| 878 | 878 |
| 879 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); | 879 RegExpImpl::GlobalCache global_cache(regexp, subject, isolate); |
| 880 if (global_cache.HasException()) return isolate->heap()->exception(); | 880 if (global_cache.HasException()) return isolate->heap()->exception(); |
| 881 | 881 |
| 882 // Ensured in Runtime_RegExpExecMultiple. | 882 // Ensured in Runtime_RegExpExecMultiple. |
| 883 DCHECK(result_array->HasFastObjectElements()); | 883 DCHECK(result_array->HasFastObjectElements()); |
| 884 Handle<FixedArray> result_elements( | 884 Handle<FixedArray> result_elements( |
| 885 FixedArray::cast(result_array->elements())); | 885 FixedArray::cast(result_array->elements())); |
| 886 if (result_elements->length() < 16) { | 886 if (result_elements->length() < 16) { |
| 887 result_elements = isolate->factory()->NewFixedArrayWithHoles(16); | 887 result_elements = isolate->factory()->NewFixedArrayWithHoles(16); |
| 888 } | 888 } |
| 889 | 889 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 | 1022 |
| 1023 | 1023 |
| 1024 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1024 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
| 1025 SealHandleScope shs(isolate); | 1025 SealHandleScope shs(isolate); |
| 1026 DCHECK(args.length() == 1); | 1026 DCHECK(args.length() == 1); |
| 1027 CONVERT_ARG_CHECKED(Object, obj, 0); | 1027 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 1028 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1028 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
| 1029 } | 1029 } |
| 1030 } // namespace internal | 1030 } // namespace internal |
| 1031 } // namespace v8 | 1031 } // namespace v8 |
| OLD | NEW |