| OLD | NEW |
| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 300 } |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 | 303 |
| 304 int end = value + needle_length; | 304 int end = value + needle_length; |
| 305 | 305 |
| 306 // Create an array that looks like the static last_match_info array | 306 // Create an array that looks like the static last_match_info array |
| 307 // that is attached to the global RegExp object. We will be returning | 307 // that is attached to the global RegExp object. We will be returning |
| 308 // an array of these. | 308 // an array of these. |
| 309 Handle<FixedArray> array = Factory::NewFixedArray(kFirstCapture + 2); | 309 Handle<FixedArray> array = Factory::NewFixedArray(kFirstCapture + 2); |
| 310 SetLastCaptureCount(*array, 2); |
| 311 // Ignore subject and input fields. |
| 310 SetCapture(*array, 0, value); | 312 SetCapture(*array, 0, value); |
| 311 SetCapture(*array, 1, end); | 313 SetCapture(*array, 1, end); |
| 312 SetLastCaptureCount(*array, 2); | |
| 313 Handle<JSArray> pair = Factory::NewJSArrayWithElements(array); | 314 Handle<JSArray> pair = Factory::NewJSArrayWithElements(array); |
| 314 SetElement(result, match_count, pair); | 315 SetElement(result, match_count, pair); |
| 315 match_count++; | 316 match_count++; |
| 316 index = end; | 317 index = end; |
| 317 if (needle_length == 0) index++; | 318 if (needle_length == 0) index++; |
| 318 last_value = value; | 319 last_value = value; |
| 319 } | 320 } |
| 320 return result; | 321 return result; |
| 321 } | 322 } |
| 322 | 323 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 555 |
| 555 if (matches.is_null()) { | 556 if (matches.is_null()) { |
| 556 ASSERT(Top::has_pending_exception()); | 557 ASSERT(Top::has_pending_exception()); |
| 557 return matches; | 558 return matches; |
| 558 } | 559 } |
| 559 | 560 |
| 560 if (matches->IsJSArray()) { | 561 if (matches->IsJSArray()) { |
| 561 // Create an array that looks like the static last_match_info array | 562 // Create an array that looks like the static last_match_info array |
| 562 // that is attached to the global RegExp object. We will be returning | 563 // that is attached to the global RegExp object. We will be returning |
| 563 // an array of these. | 564 // an array of these. |
| 564 Handle<FixedArray> matches_array(JSArray::cast(*matches)->elements()); | 565 int match_length = kFirstCapture + number_of_capture_registers; |
| 565 Handle<JSArray> latest_match = | 566 Handle<JSArray> latest_match = |
| 566 Factory::NewJSArray(kFirstCapture + number_of_capture_registers); | 567 Factory::NewJSArray(match_length); |
| 567 Handle<FixedArray> latest_match_array(latest_match->elements()); | |
| 568 | 568 |
| 569 for (int i = 0; i < number_of_capture_registers; i++) { | 569 AssertNoAllocation no_allocation; |
| 570 SetCapture(*latest_match_array, i, GetCapture(*matches_array, i)); | 570 FixedArray* match_array = JSArray::cast(*matches)->elements(); |
| 571 } | 571 match_array->CopyTo(0, |
| 572 SetLastCaptureCount(*latest_match_array, number_of_capture_registers); | 572 latest_match->elements(), |
| 573 | 573 0, |
| 574 match_length); |
| 574 SetElement(result, result_length, latest_match); | 575 SetElement(result, result_length, latest_match); |
| 575 result_length++; | 576 result_length++; |
| 576 previous_index = GetCapture(*matches_array, 1); | 577 previous_index = GetCapture(match_array, 1); |
| 577 if (GetCapture(*matches_array, 0) == previous_index) | 578 if (GetCapture(match_array, 0) == previous_index) { |
| 578 previous_index++; | 579 previous_index++; |
| 579 | 580 } |
| 580 } else { | 581 } else { |
| 581 ASSERT(matches->IsNull()); | 582 ASSERT(matches->IsNull()); |
| 582 return result; | 583 return result; |
| 583 } | 584 } |
| 584 } | 585 } |
| 585 } | 586 } |
| 586 } | 587 } |
| 587 | 588 |
| 588 | 589 |
| 589 Handle<Object> RegExpImpl::IrregexpExecOnce(Handle<FixedArray> regexp, | 590 Handle<Object> RegExpImpl::IrregexpExecOnce(Handle<FixedArray> regexp, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 subject, | 630 subject, |
| 630 offsets_vector, | 631 offsets_vector, |
| 631 previous_index); | 632 previous_index); |
| 632 } | 633 } |
| 633 | 634 |
| 634 if (!rc) { | 635 if (!rc) { |
| 635 return Factory::null_value(); | 636 return Factory::null_value(); |
| 636 } | 637 } |
| 637 | 638 |
| 638 FixedArray* array = last_match_info->elements(); | 639 FixedArray* array = last_match_info->elements(); |
| 639 // Clear previous input/string values to avoid potential memory leak. | |
| 640 SetLastSubject(array, Heap::empty_string()); | |
| 641 SetLastInput(array, Heap::empty_string()); | |
| 642 ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead); | 640 ASSERT(array->length() >= number_of_capture_registers + kLastMatchOverhead); |
| 643 // The captures come in (start, end+1) pairs. | 641 // The captures come in (start, end+1) pairs. |
| 644 for (int i = 0; i < number_of_capture_registers; i += 2) { | 642 SetLastCaptureCount(array, number_of_capture_registers); |
| 643 SetLastSubject(array, *original_subject); |
| 644 SetLastInput(array, *original_subject); |
| 645 for (int i = 0; i < number_of_capture_registers; i+=2) { |
| 645 SetCapture(array, i, offsets_vector[i]); | 646 SetCapture(array, i, offsets_vector[i]); |
| 646 SetCapture(array, i + 1, offsets_vector[i + 1]); | 647 SetCapture(array, i + 1, offsets_vector[i + 1]); |
| 647 } | 648 } |
| 648 SetLastCaptureCount(array, number_of_capture_registers); | |
| 649 SetLastSubject(array, *original_subject); | |
| 650 SetLastInput(array, *original_subject); | |
| 651 return last_match_info; | 649 return last_match_info; |
| 652 } | 650 } |
| 653 | 651 |
| 654 | 652 |
| 655 // ------------------------------------------------------------------- | 653 // ------------------------------------------------------------------- |
| 656 // Implementation of the Irregexp regular expression engine. | 654 // Implementation of the Irregexp regular expression engine. |
| 657 // | 655 // |
| 658 // The Irregexp regular expression engine is intended to be a complete | 656 // The Irregexp regular expression engine is intended to be a complete |
| 659 // implementation of ECMAScript regular expressions. It generates either | 657 // implementation of ECMAScript regular expressions. It generates either |
| 660 // bytecodes or native code. | 658 // bytecodes or native code. |
| (...skipping 3958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4619 EmbeddedVector<byte, 1024> codes; | 4617 EmbeddedVector<byte, 1024> codes; |
| 4620 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 4618 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
| 4621 return compiler.Assemble(¯o_assembler, | 4619 return compiler.Assemble(¯o_assembler, |
| 4622 node, | 4620 node, |
| 4623 data->capture_count, | 4621 data->capture_count, |
| 4624 pattern); | 4622 pattern); |
| 4625 } | 4623 } |
| 4626 | 4624 |
| 4627 | 4625 |
| 4628 }} // namespace v8::internal | 4626 }} // namespace v8::internal |
| OLD | NEW |