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

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

Issue 2630233003: [regexp] Create property on result for each named capture (Closed)
Patch Set: Rebase 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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 return name; 763 return name;
764 } 764 }
765 765
766 bool RegExpParser::CreateNamedCaptureAtIndex(const ZoneVector<uc16>* name, 766 bool RegExpParser::CreateNamedCaptureAtIndex(const ZoneVector<uc16>* name,
767 int index) { 767 int index) {
768 DCHECK(FLAG_harmony_regexp_named_captures); 768 DCHECK(FLAG_harmony_regexp_named_captures);
769 DCHECK(unicode()); 769 DCHECK(unicode());
770 DCHECK(0 < index && index <= captures_started_); 770 DCHECK(0 < index && index <= captures_started_);
771 DCHECK_NOT_NULL(name); 771 DCHECK_NOT_NULL(name);
772 772
773 // Disallow captures named '__proto__'.
774 static const char16_t proto_string[] = u"__proto__";
Dan Ehrenberg 2017/01/20 18:23:46 Sorry I didn't post this comment earlier, but: If
775 if (name->size() == arraysize(proto_string) - 1) {
776 if (std::equal(name->begin(), name->end(), &proto_string[0])) {
777 ReportError(CStrVector("Illegal capture group name"));
778 return false;
779 }
780 }
781
773 if (named_captures_ == nullptr) { 782 if (named_captures_ == nullptr) {
774 named_captures_ = new (zone()) ZoneList<RegExpCapture*>(1, zone()); 783 named_captures_ = new (zone()) ZoneList<RegExpCapture*>(1, zone());
775 } else { 784 } else {
776 // Check for duplicates and bail if we find any. 785 // Check for duplicates and bail if we find any.
777 for (const auto& named_capture : *named_captures_) { 786 for (const auto& named_capture : *named_captures_) {
778 if (*named_capture->name() == *name) { 787 if (*named_capture->name() == *name) {
779 ReportError(CStrVector("Duplicate capture group name")); 788 ReportError(CStrVector("Duplicate capture group name"));
780 return false; 789 return false;
781 } 790 }
782 } 791 }
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 return false; 1802 return false;
1794 } 1803 }
1795 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), 1804 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom),
1796 zone()); 1805 zone());
1797 LAST(ADD_TERM); 1806 LAST(ADD_TERM);
1798 return true; 1807 return true;
1799 } 1808 }
1800 1809
1801 } // namespace internal 1810 } // namespace internal
1802 } // namespace v8 1811 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698