| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, | 366 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
| 367 Handle<String> subject, | 367 Handle<String> subject, |
| 368 Handle<Object> index) { | 368 Handle<Object> index) { |
| 369 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); | 369 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); |
| 370 | 370 |
| 371 uint32_t start_index; | 371 uint32_t start_index; |
| 372 if (!Array::IndexFromObject(*index, &start_index)) { | 372 if (!Array::IndexFromObject(*index, &start_index)) { |
| 373 return Handle<Smi>(Smi::FromInt(-1)); | 373 return Handle<Smi>(Smi::FromInt(-1)); |
| 374 } | 374 } |
| 375 | 375 |
| 376 LOG(RegExpExecEvent(re, start_index, subject)); | |
| 377 int value = Runtime::StringMatch(subject, needle, start_index); | 376 int value = Runtime::StringMatch(subject, needle, start_index); |
| 378 if (value == -1) return Factory::null_value(); | 377 if (value == -1) return Factory::null_value(); |
| 379 | 378 |
| 380 Handle<FixedArray> array = Factory::NewFixedArray(2); | 379 Handle<FixedArray> array = Factory::NewFixedArray(2); |
| 381 array->set(0, Smi::FromInt(value)); | 380 array->set(0, Smi::FromInt(value)); |
| 382 array->set(1, Smi::FromInt(value + needle->length())); | 381 array->set(1, Smi::FromInt(value + needle->length())); |
| 383 return Factory::NewJSArrayWithElements(array); | 382 return Factory::NewJSArrayWithElements(array); |
| 384 } | 383 } |
| 385 | 384 |
| 386 | 385 |
| 387 Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, | 386 Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, |
| 388 Handle<String> subject) { | 387 Handle<String> subject) { |
| 389 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); | 388 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); |
| 390 Handle<JSArray> result = Factory::NewJSArray(1); | 389 Handle<JSArray> result = Factory::NewJSArray(1); |
| 391 int index = 0; | 390 int index = 0; |
| 392 int match_count = 0; | 391 int match_count = 0; |
| 393 int subject_length = subject->length(); | 392 int subject_length = subject->length(); |
| 394 int needle_length = needle->length(); | 393 int needle_length = needle->length(); |
| 395 while (true) { | 394 while (true) { |
| 396 LOG(RegExpExecEvent(re, index, subject)); | |
| 397 int value = -1; | 395 int value = -1; |
| 398 if (index + needle_length <= subject_length) { | 396 if (index + needle_length <= subject_length) { |
| 399 value = Runtime::StringMatch(subject, needle, index); | 397 value = Runtime::StringMatch(subject, needle, index); |
| 400 } | 398 } |
| 401 if (value == -1) break; | 399 if (value == -1) break; |
| 402 HandleScope scope; | 400 HandleScope scope; |
| 403 int end = value + needle_length; | 401 int end = value + needle_length; |
| 404 | 402 |
| 405 Handle<FixedArray> array = Factory::NewFixedArray(2); | 403 Handle<FixedArray> array = Factory::NewFixedArray(2); |
| 406 array->set(0, Smi::FromInt(value)); | 404 array->set(0, Smi::FromInt(value)); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 int* offsets_vector, | 566 int* offsets_vector, |
| 569 int offsets_vector_length) { | 567 int offsets_vector_length) { |
| 570 int rc; | 568 int rc; |
| 571 { | 569 { |
| 572 AssertNoAllocation a; | 570 AssertNoAllocation a; |
| 573 ByteArray* internal = JscreInternal(regexp); | 571 ByteArray* internal = JscreInternal(regexp); |
| 574 const v8::jscre::JscreRegExp* js_regexp = | 572 const v8::jscre::JscreRegExp* js_regexp = |
| 575 reinterpret_cast<v8::jscre::JscreRegExp*>( | 573 reinterpret_cast<v8::jscre::JscreRegExp*>( |
| 576 internal->GetDataStartAddress()); | 574 internal->GetDataStartAddress()); |
| 577 | 575 |
| 578 LOG(RegExpExecEvent(regexp, previous_index, subject)); | |
| 579 | |
| 580 rc = v8::jscre::jsRegExpExecute(js_regexp, | 576 rc = v8::jscre::jsRegExpExecute(js_regexp, |
| 581 two_byte_subject, | 577 two_byte_subject, |
| 582 subject->length(), | 578 subject->length(), |
| 583 previous_index, | 579 previous_index, |
| 584 offsets_vector, | 580 offsets_vector, |
| 585 offsets_vector_length); | 581 offsets_vector_length); |
| 586 } | 582 } |
| 587 | 583 |
| 588 // The KJS JavaScript engine returns null (ie, a failed match) when | 584 // The KJS JavaScript engine returns null (ie, a failed match) when |
| 589 // JSRE's internal match limit is exceeded. We duplicate that behavior here. | 585 // JSRE's internal match limit is exceeded. We duplicate that behavior here. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 780 |
| 785 int previous_index = static_cast<int>(DoubleToInteger(index->Number())); | 781 int previous_index = static_cast<int>(DoubleToInteger(index->Number())); |
| 786 | 782 |
| 787 #ifdef DEBUG | 783 #ifdef DEBUG |
| 788 if (FLAG_trace_regexp_bytecodes) { | 784 if (FLAG_trace_regexp_bytecodes) { |
| 789 String* pattern = regexp->Pattern(); | 785 String* pattern = regexp->Pattern(); |
| 790 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); | 786 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); |
| 791 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); | 787 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); |
| 792 } | 788 } |
| 793 #endif | 789 #endif |
| 794 LOG(RegExpExecEvent(regexp, previous_index, subject)); | |
| 795 | 790 |
| 796 if (!subject->IsFlat(StringShape(*subject))) { | 791 if (!subject->IsFlat(StringShape(*subject))) { |
| 797 FlattenString(subject); | 792 FlattenString(subject); |
| 798 } | 793 } |
| 799 | 794 |
| 800 return IrregexpExecOnce(irregexp, | 795 return IrregexpExecOnce(irregexp, |
| 801 num_captures, | 796 num_captures, |
| 802 subject, | 797 subject, |
| 803 previous_index, | 798 previous_index, |
| 804 offsets.vector(), | 799 offsets.vector(), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 matches = Factory::null_value(); | 833 matches = Factory::null_value(); |
| 839 return result; | 834 return result; |
| 840 } else { | 835 } else { |
| 841 #ifdef DEBUG | 836 #ifdef DEBUG |
| 842 if (FLAG_trace_regexp_bytecodes) { | 837 if (FLAG_trace_regexp_bytecodes) { |
| 843 String* pattern = regexp->Pattern(); | 838 String* pattern = regexp->Pattern(); |
| 844 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); | 839 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); |
| 845 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); | 840 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); |
| 846 } | 841 } |
| 847 #endif | 842 #endif |
| 848 LOG(RegExpExecEvent(regexp, previous_index, subject)); | |
| 849 matches = IrregexpExecOnce(irregexp, | 843 matches = IrregexpExecOnce(irregexp, |
| 850 IrregexpNumberOfCaptures(irregexp), | 844 IrregexpNumberOfCaptures(irregexp), |
| 851 subject, | 845 subject, |
| 852 previous_index, | 846 previous_index, |
| 853 offsets.vector(), | 847 offsets.vector(), |
| 854 offsets.length()); | 848 offsets.length()); |
| 855 | 849 |
| 856 if (matches->IsJSArray()) { | 850 if (matches->IsJSArray()) { |
| 857 SetElement(result, i, matches); | 851 SetElement(result, i, matches); |
| 858 i++; | 852 i++; |
| (...skipping 3534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4393 EmbeddedVector<byte, 1024> codes; | 4387 EmbeddedVector<byte, 1024> codes; |
| 4394 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 4388 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
| 4395 return compiler.Assemble(¯o_assembler, | 4389 return compiler.Assemble(¯o_assembler, |
| 4396 node, | 4390 node, |
| 4397 data->capture_count, | 4391 data->capture_count, |
| 4398 pattern); | 4392 pattern); |
| 4399 } | 4393 } |
| 4400 | 4394 |
| 4401 | 4395 |
| 4402 }} // namespace v8::internal | 4396 }} // namespace v8::internal |
| OLD | NEW |