Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: V8: cherry-pick cced52a97ee9 #40656

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

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

##### V8 defaults for Node.js #####

Expand Down
3 changes: 3 additions & 0 deletions deps/v8/src/date/dateparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class DateParser : public AllStatic {
int ReadUnsignedNumeral() {
int n = 0;
int i = 0;
// First, skip leading zeros
while (ch_ == '0') Next();
// And then, do the conversion
while (IsAsciiDigit()) {
if (i < kMaxSignificantDigits) n = n * 10 + ch_ - '0';
i++;
Expand Down
54 changes: 54 additions & 0 deletions deps/v8/test/mjsunit/regress/regress-12256.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

const dates = [{ year: '2021', month: '10', day: '22', hour: '10', minute: '12', second: '32' },
{ year: '2021', month: '8', day: '3', hour: '9', minute: '9', second: '6' }];

for (let date of dates) {
const { year, month, day, hour, minute, second } = date;
const s0 = `${year}-${month}-${day} ${hour}:${minute}:${second}Z`;

// V8 reads at most kMaxSignificantDigits (9) to build the value of a numeral,
// so let's test up to 9 leading zeros.

// For years
for (let i = 1; i < 10; i++) {
const s1 = `${'0'.repeat(i) + year}-${month}-${day} ${hour}:${minute}:${second}Z`;
assertTrue(new Date(s0).getTime() == new Date(s1).getTime());
}

// For months
for (let i = 1; i < 10; i++) {
const s1 = `${year}-${'0'.repeat(i) + month}-${day} ${hour}:${minute}:${second}Z`;
assertTrue(new Date(s0).getTime() == new Date(s1).getTime());
}

// For days
for (let i = 1; i < 10; i++) {
const s1 = `${year}-${month}-${'0'.repeat(i) + day} ${hour}:${minute}:${second}Z`;
assertTrue(new Date(s0).getTime() == new Date(s1).getTime());
}

// For hours
for (let i = 1; i < 10; i++) {
const s1 = `${year}-${month}-${day} ${'0'.repeat(i) + hour}:${minute}:${second}Z`;
assertTrue(new Date(s0).getTime() == new Date(s1).getTime());
}

// For minutes
for (let i = 1; i < 10; i++) {
const s1 = `${year}-${month}-${day} ${hour}:${'0'.repeat(i) + minute}:${second}Z`;
assertTrue(new Date(s0).getTime() == new Date(s1).getTime());
}

// For seconds
for (let i = 1; i < 10; i++) {
const s1 = `${year}-${month}-${day} ${hour}:${minute}:${'0'.repeat(i) + second}Z`;
assertTrue(new Date(s0).getTime() == new Date(s1).getTime());
}

// With same input date string,
// Date() and Date.parse() should return the same date
assertTrue(new Date(s0).getTime() == Date.parse(s0));
}