| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f364b50 commit 553afa9
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ | |||
| 38 | 38 | ||
| 39 | 39 | # Reset this number to 0 on major V8 upgrades. | |
| 40 | 40 | # Increment by one for each non-official patch applied to deps/v8. | |
| 41 | - 'v8_embedder_string': '-node.12', | ||
| 41 | + 'v8_embedder_string': '-node.13', | ||
| 42 | 42 | ||
| 43 | 43 | ##### V8 defaults for Node.js ##### | |
| 44 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -477,7 +477,7 @@ class RegExpCapture final : public RegExpTree { | |||
| 477 | 477 | int max_match() override { return body_->max_match(); } | |
| 478 | 478 | RegExpTree* body() { return body_; } | |
| 479 | 479 | void set_body(RegExpTree* body) { body_ = body; } | |
| 480 | - int index() { return index_; } | ||
| 480 | + int index() const { return index_; } | ||
| 481 | 481 | const ZoneVector<uc16>* name() const { return name_; } | |
| 482 | 482 | void set_name(const ZoneVector<uc16>* name) { name_ = name; } | |
| 483 | 483 | static int StartRegister(int index) { return index * 2; } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -984,18 +984,39 @@ RegExpCapture* RegExpParser::GetCapture(int index) { | |||
| 984 | 984 | return captures_->at(index - 1); | |
| 985 | 985 | } | |
| 986 | 986 | ||
| 987 | + namespace { | ||
| 988 | + | ||
| 989 | + struct RegExpCaptureIndexLess { | ||
| 990 | + bool operator()(const RegExpCapture* lhs, const RegExpCapture* rhs) const { | ||
| 991 | + DCHECK_NOT_NULL(lhs); | ||
| 992 | + DCHECK_NOT_NULL(rhs); | ||
| 993 | + return lhs->index() < rhs->index(); | ||
| 994 | + } | ||
| 995 | + }; | ||
| 996 | + | ||
| 997 | + } // namespace | ||
| 998 | + | ||
| 987 | 999 | Handle<FixedArray> RegExpParser::CreateCaptureNameMap() { | |
| 988 | 1000 | if (named_captures_ == nullptr || named_captures_->empty()) { | |
| 989 | 1001 | return Handle<FixedArray>(); | |
| 990 | 1002 | } | |
| 991 | 1003 | ||
| 1004 | + // Named captures are sorted by name (because the set is used to ensure | ||
| 1005 | + // name uniqueness). But the capture name map must to be sorted by index. | ||
| 1006 | + | ||
| 1007 | + ZoneVector<RegExpCapture*> sorted_named_captures( | ||
| 1008 | + named_captures_->begin(), named_captures_->end(), zone()); | ||
| 1009 | + std::sort(sorted_named_captures.begin(), sorted_named_captures.end(), | ||
| 1010 | + RegExpCaptureIndexLess{}); | ||
| 1011 | + DCHECK_EQ(sorted_named_captures.size(), named_captures_->size()); | ||
| 1012 | + | ||
| 992 | 1013 | Factory* factory = isolate()->factory(); | |
| 993 | 1014 | ||
| 994 | - int len = static_cast<int>(named_captures_->size()) * 2; | ||
| 1015 | + int len = static_cast<int>(sorted_named_captures.size()) * 2; | ||
| 995 | 1016 | Handle<FixedArray> array = factory->NewFixedArray(len); | |
| 996 | 1017 | ||
| 997 | 1018 | int i = 0; | |
| 998 | - for (const auto& capture : *named_captures_) { | ||
| 1019 | + for (const auto& capture : sorted_named_captures) { | ||
| 999 | 1020 | Vector<const uc16> capture_name(capture->name()->data(), | |
| 1000 | 1021 | capture->name()->size()); | |
| 1001 | 1022 | // CSA code in ConstructNewResultFromMatchInfo requires these strings to be | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -419,6 +419,15 @@ function toSlowMode(re) { | |||
| 419 | 419 | assertEquals("cd", "abcd".replace(re, "$<$1>")); | |
| 420 | 420 | } | |
| 421 | 421 | ||
| 422 | + // Named captures are ordered by capture index on the groups object. | ||
| 423 | + // https://crbug.com/v8/9822 | ||
| 424 | + | ||
| 425 | + { | ||
| 426 | + const r = /(?<BKey>.+)\s(?<AKey>.+)/; | ||
| 427 | + const s = 'example string'; | ||
| 428 | + assertArrayEquals(["BKey", "AKey"], Object.keys(r.exec(s).groups)); | ||
| 429 | + } | ||
| 430 | + | ||
| 422 | 431 | // Tests for 'groups' semantics on the regexp result object. | |
| 423 | 432 | // https://crbug.com/v8/7192 | |
| 424 | 433 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments