Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 553afa9

Browse filesBrowse files
targosMylesBorins
authored andcommitted
deps: V8: cherry-pick ed40ab1
Original commit message: [regexp] Fix the order of named captures on the groups object Named capture properties on the groups object should be ordered by the capture index (and not alpha-sorted). This was accidentally broken in https://crrev.com/c/1687413. Bug: v8:9822,v8:9423 Change-Id: Iac6f866f077a1b7ce557ba47e8ba5d7e7014b3ce Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1864829 Auto-Submit: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Peter Marshall <petermarshall@chromium.org> Commit-Queue: Peter Marshall <petermarshall@chromium.org> Cr-Commit-Position: refs/heads/master@{#64306} Refs: v8/v8@ed40ab1 Fixes: #29878 Backport-PR-URL: #30109 PR-URL: #30064 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
1 parent f364b50 commit 553afa9
Copy full SHA for 553afa9

File tree

Expand file treeCollapse file tree

4 files changed

+34
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+34
-4
lines changed
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.12',
41+
'v8_embedder_string': '-node.13',
4242

4343
##### V8 defaults for Node.js #####
4444

Collapse file

‎deps/v8/src/regexp/regexp-ast.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/regexp/regexp-ast.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ class RegExpCapture final : public RegExpTree {
477477
int max_match() override { return body_->max_match(); }
478478
RegExpTree* body() { return body_; }
479479
void set_body(RegExpTree* body) { body_ = body; }
480-
int index() { return index_; }
480+
int index() const { return index_; }
481481
const ZoneVector<uc16>* name() const { return name_; }
482482
void set_name(const ZoneVector<uc16>* name) { name_ = name; }
483483
static int StartRegister(int index) { return index * 2; }
Collapse file

‎deps/v8/src/regexp/regexp-parser.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/regexp/regexp-parser.cc
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,18 +984,39 @@ RegExpCapture* RegExpParser::GetCapture(int index) {
984984
return captures_->at(index - 1);
985985
}
986986

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+
987999
Handle<FixedArray> RegExpParser::CreateCaptureNameMap() {
9881000
if (named_captures_ == nullptr || named_captures_->empty()) {
9891001
return Handle<FixedArray>();
9901002
}
9911003

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+
9921013
Factory* factory = isolate()->factory();
9931014

994-
int len = static_cast<int>(named_captures_->size()) * 2;
1015+
int len = static_cast<int>(sorted_named_captures.size()) * 2;
9951016
Handle<FixedArray> array = factory->NewFixedArray(len);
9961017

9971018
int i = 0;
998-
for (const auto& capture : *named_captures_) {
1019+
for (const auto& capture : sorted_named_captures) {
9991020
Vector<const uc16> capture_name(capture->name()->data(),
10001021
capture->name()->size());
10011022
// CSA code in ConstructNewResultFromMatchInfo requires these strings to be
Collapse file

‎deps/v8/test/mjsunit/harmony/regexp-named-captures.js‎

Copy file name to clipboardExpand all lines: deps/v8/test/mjsunit/harmony/regexp-named-captures.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ function toSlowMode(re) {
419419
assertEquals("cd", "abcd".replace(re, "$<$1>"));
420420
}
421421

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+
422431
// Tests for 'groups' semantics on the regexp result object.
423432
// https://crbug.com/v8/7192
424433

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.