Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: src/regexp/regexp-parser.cc

Issue 2630233003: [regexp] Create property on result for each named capture (Closed)
Patch Set: Remove unused CaptureNameMapOffset Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/regexp-parser.h" 5 #include "src/regexp/regexp-parser.h"
6 6
7 #include "src/char-predicates-inl.h" 7 #include "src/char-predicates-inl.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 return name; 761 return name;
762 } 762 }
763 763
764 bool RegExpParser::CreateNamedCaptureAtIndex(const ZoneVector<uc16>* name, 764 bool RegExpParser::CreateNamedCaptureAtIndex(const ZoneVector<uc16>* name,
765 int index) { 765 int index) {
766 DCHECK(FLAG_harmony_regexp_named_captures); 766 DCHECK(FLAG_harmony_regexp_named_captures);
767 DCHECK(unicode()); 767 DCHECK(unicode());
768 DCHECK(0 < index && index <= captures_started_); 768 DCHECK(0 < index && index <= captures_started_);
769 DCHECK_NOT_NULL(name); 769 DCHECK_NOT_NULL(name);
770 770
771 static std::vector<uc16> illegal_names[] = {
772 {
773 'i', 'n', 'd', 'e', 'x',
Yang 2017/01/18 13:25:36 Is it possible to use wide string literals here? h
jgruber 2017/01/19 15:59:12 I didn't find a way to do that for this use case.
774 },
775 {
776 'i', 'n', 'p', 'u', 't',
777 },
778 {
779 'l', 'e', 'n', 'g', 't', 'h',
780 },
781 };
782
783 for (const auto& illegal_name : illegal_names) {
784 if (name->size() != illegal_name.size()) continue;
785 if (std::equal(name->begin(), name->end(), illegal_name.begin())) {
786 ReportError(CStrVector("Illegal capture group name"));
787 return false;
788 }
789 }
790
771 if (named_captures_ == nullptr) { 791 if (named_captures_ == nullptr) {
772 named_captures_ = new (zone()) ZoneList<RegExpCapture*>(1, zone()); 792 named_captures_ = new (zone()) ZoneList<RegExpCapture*>(1, zone());
773 } else { 793 } else {
774 // Check for duplicates and bail if we find any. 794 // Check for duplicates and bail if we find any.
775 for (const auto& named_capture : *named_captures_) { 795 for (const auto& named_capture : *named_captures_) {
776 if (*named_capture->name() == *name) { 796 if (*named_capture->name() == *name) {
777 ReportError(CStrVector("Duplicate capture group name")); 797 ReportError(CStrVector("Duplicate capture group name"));
778 return false; 798 return false;
779 } 799 }
780 } 800 }
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 return false; 1811 return false;
1792 } 1812 }
1793 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), 1813 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom),
1794 zone()); 1814 zone());
1795 LAST(ADD_TERM); 1815 LAST(ADD_TERM);
1796 return true; 1816 return true;
1797 } 1817 }
1798 1818
1799 } // namespace internal 1819 } // namespace internal
1800 } // namespace v8 1820 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698