| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 flags, | 522 flags, |
| 523 capture_count); | 523 capture_count); |
| 524 } | 524 } |
| 525 | 525 |
| 526 | 526 |
| 527 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, | 527 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
| 528 Handle<String> subject) { | 528 Handle<String> subject) { |
| 529 if (!subject->IsFlat()) FlattenString(subject); | 529 if (!subject->IsFlat()) FlattenString(subject); |
| 530 | 530 |
| 531 // Check the asciiness of the underlying storage. | 531 // Check the asciiness of the underlying storage. |
| 532 bool is_ascii = subject->IsAsciiRepresentationUnderneath(); | 532 bool is_ascii = subject->IsOneByteRepresentationUnderneath(); |
| 533 if (!EnsureCompiledIrregexp(regexp, subject, is_ascii)) return -1; | 533 if (!EnsureCompiledIrregexp(regexp, subject, is_ascii)) return -1; |
| 534 | 534 |
| 535 #ifdef V8_INTERPRETED_REGEXP | 535 #ifdef V8_INTERPRETED_REGEXP |
| 536 // Byte-code regexp needs space allocated for all its registers. | 536 // Byte-code regexp needs space allocated for all its registers. |
| 537 // The result captures are copied to the start of the registers array | 537 // The result captures are copied to the start of the registers array |
| 538 // if the match succeeds. This way those registers are not clobbered | 538 // if the match succeeds. This way those registers are not clobbered |
| 539 // when we set the last match info from last successful match. | 539 // when we set the last match info from last successful match. |
| 540 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())) + | 540 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())) + |
| 541 (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; | 541 (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; |
| 542 #else // V8_INTERPRETED_REGEXP | 542 #else // V8_INTERPRETED_REGEXP |
| (...skipping 10 matching lines...) Expand all Loading... |
| 553 int32_t* output, | 553 int32_t* output, |
| 554 int output_size) { | 554 int output_size) { |
| 555 Isolate* isolate = regexp->GetIsolate(); | 555 Isolate* isolate = regexp->GetIsolate(); |
| 556 | 556 |
| 557 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate); | 557 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate); |
| 558 | 558 |
| 559 ASSERT(index >= 0); | 559 ASSERT(index >= 0); |
| 560 ASSERT(index <= subject->length()); | 560 ASSERT(index <= subject->length()); |
| 561 ASSERT(subject->IsFlat()); | 561 ASSERT(subject->IsFlat()); |
| 562 | 562 |
| 563 bool is_ascii = subject->IsAsciiRepresentationUnderneath(); | 563 bool is_ascii = subject->IsOneByteRepresentationUnderneath(); |
| 564 | 564 |
| 565 #ifndef V8_INTERPRETED_REGEXP | 565 #ifndef V8_INTERPRETED_REGEXP |
| 566 ASSERT(output_size >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); | 566 ASSERT(output_size >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
| 567 do { | 567 do { |
| 568 EnsureCompiledIrregexp(regexp, subject, is_ascii); | 568 EnsureCompiledIrregexp(regexp, subject, is_ascii); |
| 569 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); | 569 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); |
| 570 // The stack is used to allocate registers for the compiled regexp code. | 570 // The stack is used to allocate registers for the compiled regexp code. |
| 571 // This means that in case of failure, the output registers array is left | 571 // This means that in case of failure, the output registers array is left |
| 572 // untouched and contains the capture results from the previous successful | 572 // untouched and contains the capture results from the previous successful |
| 573 // match. We can use that to set the last match info lazily. | 573 // match. We can use that to set the last match info lazily. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 589 == RE_EXCEPTION); | 589 == RE_EXCEPTION); |
| 590 return static_cast<IrregexpResult>(res); | 590 return static_cast<IrregexpResult>(res); |
| 591 } | 591 } |
| 592 // If result is RETRY, the string has changed representation, and we | 592 // If result is RETRY, the string has changed representation, and we |
| 593 // must restart from scratch. | 593 // must restart from scratch. |
| 594 // In this case, it means we must make sure we are prepared to handle | 594 // In this case, it means we must make sure we are prepared to handle |
| 595 // the, potentially, different subject (the string can switch between | 595 // the, potentially, different subject (the string can switch between |
| 596 // being internal and external, and even between being ASCII and UC16, | 596 // being internal and external, and even between being ASCII and UC16, |
| 597 // but the characters are always the same). | 597 // but the characters are always the same). |
| 598 IrregexpPrepare(regexp, subject); | 598 IrregexpPrepare(regexp, subject); |
| 599 is_ascii = subject->IsAsciiRepresentationUnderneath(); | 599 is_ascii = subject->IsOneByteRepresentationUnderneath(); |
| 600 } while (true); | 600 } while (true); |
| 601 UNREACHABLE(); | 601 UNREACHABLE(); |
| 602 return RE_EXCEPTION; | 602 return RE_EXCEPTION; |
| 603 #else // V8_INTERPRETED_REGEXP | 603 #else // V8_INTERPRETED_REGEXP |
| 604 | 604 |
| 605 ASSERT(output_size >= IrregexpNumberOfRegisters(*irregexp)); | 605 ASSERT(output_size >= IrregexpNumberOfRegisters(*irregexp)); |
| 606 // We must have done EnsureCompiledIrregexp, so we can get the number of | 606 // We must have done EnsureCompiledIrregexp, so we can get the number of |
| 607 // registers. | 607 // registers. |
| 608 int number_of_capture_registers = | 608 int number_of_capture_registers = |
| 609 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; | 609 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; |
| (...skipping 5549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6159 } | 6159 } |
| 6160 | 6160 |
| 6161 return compiler.Assemble(¯o_assembler, | 6161 return compiler.Assemble(¯o_assembler, |
| 6162 node, | 6162 node, |
| 6163 data->capture_count, | 6163 data->capture_count, |
| 6164 pattern); | 6164 pattern); |
| 6165 } | 6165 } |
| 6166 | 6166 |
| 6167 | 6167 |
| 6168 }} // namespace v8::internal | 6168 }} // namespace v8::internal |
| OLD | NEW |