OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2959 int pattern_length = pat->length(); | 2959 int pattern_length = pat->length(); |
2960 if (pattern_length == 0) return start_index; | 2960 if (pattern_length == 0) return start_index; |
2961 | 2961 |
2962 int subject_length = sub->length(); | 2962 int subject_length = sub->length(); |
2963 if (start_index + pattern_length > subject_length) return -1; | 2963 if (start_index + pattern_length > subject_length) return -1; |
2964 | 2964 |
2965 if (!sub->IsFlat()) FlattenString(sub); | 2965 if (!sub->IsFlat()) FlattenString(sub); |
2966 if (!pat->IsFlat()) FlattenString(pat); | 2966 if (!pat->IsFlat()) FlattenString(pat); |
2967 | 2967 |
2968 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid | 2968 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
2969 // Extract flattened substrings of cons strings before determining asciiness. | |
2970 String* seq_sub = *sub; | |
2971 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); | |
2972 String* seq_pat = *pat; | |
2973 if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first(); | |
2974 | 2969 |
2975 // dispatch on type of strings | 2970 // dispatch on type of strings |
2976 if (seq_pat->IsAsciiRepresentation()) { | 2971 if (pat->IsAsciiRepresentationUnderneath()) { |
2977 Vector<const char> pat_vector = seq_pat->ToAsciiVector(); | 2972 Vector<const char> pat_vector = pat->ToAsciiVector(); |
2978 if (seq_sub->IsAsciiRepresentation()) { | 2973 if (sub->IsAsciiRepresentationUnderneath()) { |
2979 return SearchString(isolate, | 2974 return SearchString(isolate, |
2980 seq_sub->ToAsciiVector(), | 2975 sub->ToAsciiVector(), |
2981 pat_vector, | 2976 pat_vector, |
2982 start_index); | 2977 start_index); |
2983 } | 2978 } |
2984 return SearchString(isolate, | 2979 return SearchString(isolate, |
2985 seq_sub->ToUC16Vector(), | 2980 sub->ToUC16Vector(), |
2986 pat_vector, | 2981 pat_vector, |
2987 start_index); | 2982 start_index); |
2988 } | 2983 } |
2989 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector(); | 2984 Vector<const uc16> pat_vector = pat->ToUC16Vector(); |
2990 if (seq_sub->IsAsciiRepresentation()) { | 2985 if (sub->IsAsciiRepresentationUnderneath()) { |
2991 return SearchString(isolate, | 2986 return SearchString(isolate, |
2992 seq_sub->ToAsciiVector(), | 2987 sub->ToAsciiVector(), |
2993 pat_vector, | 2988 pat_vector, |
2994 start_index); | 2989 start_index); |
2995 } | 2990 } |
2996 return SearchString(isolate, | 2991 return SearchString(isolate, |
2997 seq_sub->ToUC16Vector(), | 2992 sub->ToUC16Vector(), |
2998 pat_vector, | 2993 pat_vector, |
2999 start_index); | 2994 start_index); |
3000 } | 2995 } |
3001 | 2996 |
3002 | 2997 |
3003 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringIndexOf) { | 2998 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringIndexOf) { |
3004 HandleScope scope(isolate); // create a new handle scope | 2999 HandleScope scope(isolate); // create a new handle scope |
3005 ASSERT(args.length() == 3); | 3000 ASSERT(args.length() == 3); |
3006 | 3001 |
3007 CONVERT_ARG_CHECKED(String, sub, 0); | 3002 CONVERT_ARG_CHECKED(String, sub, 0); |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3572 // No matches at all, return failure or exception result directly. | 3567 // No matches at all, return failure or exception result directly. |
3573 return result; | 3568 return result; |
3574 } | 3569 } |
3575 | 3570 |
3576 | 3571 |
3577 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { | 3572 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { |
3578 ASSERT(args.length() == 4); | 3573 ASSERT(args.length() == 4); |
3579 HandleScope handles(isolate); | 3574 HandleScope handles(isolate); |
3580 | 3575 |
3581 CONVERT_ARG_CHECKED(String, subject, 1); | 3576 CONVERT_ARG_CHECKED(String, subject, 1); |
3582 if (!subject->IsFlat()) { FlattenString(subject); } | 3577 if (!subject->IsFlat()) FlattenString(subject); |
3583 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); | 3578 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); |
3584 CONVERT_ARG_CHECKED(JSArray, last_match_info, 2); | 3579 CONVERT_ARG_CHECKED(JSArray, last_match_info, 2); |
3585 CONVERT_ARG_CHECKED(JSArray, result_array, 3); | 3580 CONVERT_ARG_CHECKED(JSArray, result_array, 3); |
3586 | 3581 |
3587 ASSERT(last_match_info->HasFastElements()); | 3582 ASSERT(last_match_info->HasFastElements()); |
3588 ASSERT(regexp->GetFlags().is_global()); | 3583 ASSERT(regexp->GetFlags().is_global()); |
3589 Handle<FixedArray> result_elements; | 3584 Handle<FixedArray> result_elements; |
3590 if (result_array->HasFastElements()) { | 3585 if (result_array->HasFastElements()) { |
3591 result_elements = | 3586 result_elements = |
3592 Handle<FixedArray>(FixedArray::cast(result_array->elements())); | 3587 Handle<FixedArray>(FixedArray::cast(result_array->elements())); |
(...skipping 9156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12749 } else { | 12744 } else { |
12750 // Handle last resort GC and make sure to allow future allocations | 12745 // Handle last resort GC and make sure to allow future allocations |
12751 // to grow the heap without causing GCs (if possible). | 12746 // to grow the heap without causing GCs (if possible). |
12752 isolate->counters()->gc_last_resort_from_js()->Increment(); | 12747 isolate->counters()->gc_last_resort_from_js()->Increment(); |
12753 isolate->heap()->CollectAllGarbage(false); | 12748 isolate->heap()->CollectAllGarbage(false); |
12754 } | 12749 } |
12755 } | 12750 } |
12756 | 12751 |
12757 | 12752 |
12758 } } // namespace v8::internal | 12753 } } // namespace v8::internal |
OLD | NEW |