OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/regexp/jsregexp.h" | 5 #include "src/regexp/jsregexp.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 re->GetIsolate()->factory()->SetRegExpIrregexpData(re, | 444 re->GetIsolate()->factory()->SetRegExpIrregexpData(re, |
445 JSRegExp::IRREGEXP, | 445 JSRegExp::IRREGEXP, |
446 pattern, | 446 pattern, |
447 flags, | 447 flags, |
448 capture_count); | 448 capture_count); |
449 } | 449 } |
450 | 450 |
451 | 451 |
452 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, | 452 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
453 Handle<String> subject) { | 453 Handle<String> subject) { |
454 subject = String::Flatten(subject); | 454 DCHECK(subject->IsFlat()); |
455 | 455 |
456 // Check representation of the underlying storage. | 456 // Check representation of the underlying storage. |
457 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); | 457 bool is_one_byte = subject->IsOneByteRepresentationUnderneath(); |
458 if (!EnsureCompiledIrregexp(regexp, subject, is_one_byte)) return -1; | 458 if (!EnsureCompiledIrregexp(regexp, subject, is_one_byte)) return -1; |
459 | 459 |
460 #ifdef V8_INTERPRETED_REGEXP | 460 #ifdef V8_INTERPRETED_REGEXP |
461 // Byte-code regexp needs space allocated for all its registers. | 461 // Byte-code regexp needs space allocated for all its registers. |
462 // The result captures are copied to the start of the registers array | 462 // The result captures are copied to the start of the registers array |
463 // if the match succeeds. This way those registers are not clobbered | 463 // if the match succeeds. This way those registers are not clobbered |
464 // when we set the last match info from last successful match. | 464 // when we set the last match info from last successful match. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 return result; | 558 return result; |
559 #endif // V8_INTERPRETED_REGEXP | 559 #endif // V8_INTERPRETED_REGEXP |
560 } | 560 } |
561 | 561 |
562 MaybeHandle<Object> RegExpImpl::IrregexpExec( | 562 MaybeHandle<Object> RegExpImpl::IrregexpExec( |
563 Handle<JSRegExp> regexp, Handle<String> subject, int previous_index, | 563 Handle<JSRegExp> regexp, Handle<String> subject, int previous_index, |
564 Handle<RegExpMatchInfo> last_match_info) { | 564 Handle<RegExpMatchInfo> last_match_info) { |
565 Isolate* isolate = regexp->GetIsolate(); | 565 Isolate* isolate = regexp->GetIsolate(); |
566 DCHECK_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); | 566 DCHECK_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); |
567 | 567 |
| 568 subject = String::Flatten(subject); |
| 569 |
568 // Prepare space for the return values. | 570 // Prepare space for the return values. |
569 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG) | 571 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG) |
570 if (FLAG_trace_regexp_bytecodes) { | 572 if (FLAG_trace_regexp_bytecodes) { |
571 String* pattern = regexp->Pattern(); | 573 String* pattern = regexp->Pattern(); |
572 PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get()); | 574 PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get()); |
573 PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get()); | 575 PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get()); |
574 } | 576 } |
575 #endif | 577 #endif |
576 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); | 578 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); |
577 if (required_registers < 0) { | 579 if (required_registers < 0) { |
(...skipping 6284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6862 | 6864 |
6863 | 6865 |
6864 void RegExpResultsCache::Clear(FixedArray* cache) { | 6866 void RegExpResultsCache::Clear(FixedArray* cache) { |
6865 for (int i = 0; i < kRegExpResultsCacheSize; i++) { | 6867 for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
6866 cache->set(i, Smi::kZero); | 6868 cache->set(i, Smi::kZero); |
6867 } | 6869 } |
6868 } | 6870 } |
6869 | 6871 |
6870 } // namespace internal | 6872 } // namespace internal |
6871 } // namespace v8 | 6873 } // namespace v8 |
OLD | NEW |