Skip to content

Commit

Permalink
Backed out changeset 2516d38fcdfa (bug 1617562) for causing leaks on …
Browse files Browse the repository at this point in the history
…jsdate.cpp. CLOSED TREE
  • Loading branch information
ncsoregi committed Nov 7, 2023
1 parent 28fa3a7 commit 0f55032
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 196 deletions.
5 changes: 2 additions & 3 deletions devtools/shared/natural-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const startsWithNullRx = /^\0/;
const endsWithNullRx = /\0$/;
const whitespaceRx = /\s+/g;
const startsWithZeroRx = /^0/;
const versionRx = /^([\w-]+-)?\d+\.\d+\.\d+$/;

/**
* Sort numbers, strings, IP Addresses, Dates, Filenames, version numbers etc.
Expand Down Expand Up @@ -66,9 +65,9 @@ function naturalSort(a = "", b = "", sessionString, insensitive = false) {

// Hex or date detection.
const aHexOrDate =
parseInt(a.match(hexRx), 16) || (!versionRx.test(a) && Date.parse(a));
parseInt(a.match(hexRx), 16) || (aChunks.length > 3 && Date.parse(a));
const bHexOrDate =
parseInt(b.match(hexRx), 16) || (!versionRx.test(b) && Date.parse(b));
parseInt(b.match(hexRx), 16) || (bChunks.length > 3 && Date.parse(b));

if (
(aHexOrDate || bHexOrDate) &&
Expand Down
42 changes: 0 additions & 42 deletions devtools/shared/tests/xpcshell/test_natural-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,48 +281,6 @@ function run_test() {
],
"string first"
);
runTest(
[
"1.1.3",
"a-release-1.1.3",
"b-release-1.1.3",
"1.2.3",
"a-release-1.2.3",
"b-release-1.2.3",
"1.1.4",
"a-release-1.1.4",
"b-release-1.1.4",
"1.1.1",
"a-release-1.1.1",
"b-release-1.1.1",
"1.0.5",
"a-release-1.0.5",
"b-release-1.0.5",
],
[
"1.0.5",
"1.1.1",
"1.1.3",
"1.1.4",
"1.2.3",
"a-release-1.0.5",
"a-release-1.1.1",
"a-release-1.1.3",
"a-release-1.1.4",
"a-release-1.2.3",
"b-release-1.0.5",
"b-release-1.1.1",
"b-release-1.1.3",
"b-release-1.1.4",
"b-release-1.2.3",
],
"string first, different names"
);
runTest(
["zstring", "astring", "release-1.1.3"],
["astring", "release-1.1.3", "zstring"],
"string first, mixed with regular strings"
);
});

test("numerics", function () {
Expand Down
73 changes: 14 additions & 59 deletions js/src/jsdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,6 @@ static constexpr const char* const months_names[] = {
"january", "february", "march", "april", "may", "june",
"july", "august", "september", "october", "november", "december",
};
// The shortest month is "may".
static constexpr size_t ShortestMonthNameLength = 3;

/*
* Try to parse the following date formats:
Expand All @@ -1156,14 +1154,13 @@ template <typename CharT>
static bool TryParseDashedDatePrefix(const CharT* s, size_t length,
size_t* indexOut, int* yearOut,
int* monOut, int* mdayOut) {
size_t i = *indexOut;
size_t i = 0;

size_t pre = i;
size_t mday;
if (!ParseDigitsNOrLess(6, &mday, s, &i, length)) {
return false;
}
size_t mdayDigits = i - pre;
size_t mdayDigits = i;

if (i >= length || s[i] != '-') {
return false;
Expand All @@ -1177,6 +1174,8 @@ static bool TryParseDashedDatePrefix(const CharT* s, size_t length,
}
}

// The shortest month is "may".
static constexpr size_t ShortestMonthNameLength = 3;
if (i - start < ShortestMonthNameLength) {
return false;
}
Expand All @@ -1200,7 +1199,7 @@ static bool TryParseDashedDatePrefix(const CharT* s, size_t length,
}
++i;

pre = i;
size_t pre = i;
size_t year;
if (!ParseDigitsNOrLess(6, &year, s, &i, length)) {
return false;
Expand Down Expand Up @@ -1250,7 +1249,7 @@ template <typename CharT>
static bool TryParseDashedNumericDatePrefix(const CharT* s, size_t length,
size_t* indexOut, int* yearOut,
int* monOut, int* mdayOut) {
size_t i = *indexOut;
size_t i = 0;

size_t first;
if (!ParseDigitsNOrLess(6, &first, s, &i, length)) {
Expand Down Expand Up @@ -1381,61 +1380,16 @@ constexpr size_t MinKeywordLength(const CharsAndAction (&keywords)[N]) {
template <typename CharT>
static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
size_t length, ClippedTime* result) {
if (length == 0) {
return false;
}

if (ParseISOStyleDate(forceUTC, s, length, result)) {
return true;
}

size_t index = 0;
int mon = -1;
bool seenMonthName = false;

// Before we begin, we need to scrub any words from the beginning of the
// string that are not a month name
for (; index < length; ++index) {
int c = s[index];

if (strchr(" ,.-/", c)) {
continue;
}
if (!IsAsciiAlpha(c)) {
break;
}

size_t start = index;
while (index < length) {
++index;
if (!IsAsciiAlpha(s[index])) {
break;
}
}

if (index - start < ShortestMonthNameLength) {
// If it's too short, it's definitely not a month name, ignore it
continue;
}

for (size_t m = 0; m < std::size(months_names); ++m) {
// If the field isn't a prefix of the month (an exact match is *not*
// required), try the next one.
if (IsPrefixOfKeyword(s + start, index - start, months_names[m])) {
// Use numeric value.
mon = m + 1;
seenMonthName = true;
break;
}
}
if (seenMonthName) {
// If we've found the month name, we're done with this loop, otherwise we
// move on to the next word
break;
}
if (length == 0) {
return false;
}

int year = -1;
int mon = -1;
int mday = -1;
int hour = -1;
int min = -1;
Expand All @@ -1447,11 +1401,14 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
int prevc = 0;

bool seenPlusMinus = false;
bool seenMonthName = false;
bool seenFullYear = false;
bool negativeYear = false;
// Includes "GMT", "UTC", "UT", and "Z" timezone keywords
bool seenGmtAbbr = false;

size_t index = 0;

// Try parsing the leading dashed-date.
//
// If successfully parsed, index is updated to the end of the date part,
Expand Down Expand Up @@ -1729,9 +1686,7 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
// date component and set the month here.
if (action <= 12) {
if (seenMonthName) {
// Overwrite the previous month name
mon = action;
break;
return false;
}

seenMonthName = true;
Expand Down Expand Up @@ -1766,7 +1721,7 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
break;
}

if (k == size_t(-1) && (!seenMonthName || mday != -1)) {
if (k == size_t(-1)) {
return false;
}

Expand Down
92 changes: 0 additions & 92 deletions js/src/tests/non262/Date/parse-day-of-week.js

This file was deleted.

0 comments on commit 0f55032

Please sign in to comment.