[numbers] Rename ConversionFlags:NO_FLAG to NO_CONVERSION_FLAGS

This fixes a -Wshadow warning for NO_FLAG. The other option is to
make it an enum class, which makes test-conversions.cc a bit verbose.

Bug: v8:12244,v8:12245
Change-Id: I3ea429eb45e31b25d4c6658ceb86c33ba280ae51
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3274015
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77860}
This commit is contained in:
Ng Zhi An 2021-11-10 16:32:24 -08:00 committed by V8 LUCI CQ
parent fd8d03e88c
commit 4edbdee196
6 changed files with 55 additions and 48 deletions

View File

@ -965,9 +965,10 @@ Handle<Object> JsonParser<Char>::ParseJsonNumber() {
}
base::Vector<const Char> chars(start, cursor_ - start);
number = StringToDouble(chars,
NO_FLAGS, // Hex, octal or trailing junk.
std::numeric_limits<double>::quiet_NaN());
number =
StringToDouble(chars,
NO_CONVERSION_FLAGS, // Hex, octal or trailing junk.
std::numeric_limits<double>::quiet_NaN());
DCHECK(!std::isnan(number));
}

View File

@ -1477,7 +1477,7 @@ bool IsSpecialIndex(String string) {
}
// Slow path: test DoubleToString(StringToDouble(string)) == string.
base::Vector<const uint16_t> vector(buffer, length);
double d = StringToDouble(vector, NO_FLAGS);
double d = StringToDouble(vector, NO_CONVERSION_FLAGS);
if (std::isnan(d)) return false;
// Compute reverse string.
char reverse_buffer[kBufferSize + 1]; // Result will be /0 terminated.

View File

@ -79,7 +79,7 @@ inline uint64_t DoubleToUint64(double x);
// Enumeration for allowing octals and ignoring junk when converting
// strings to numbers.
enum ConversionFlags {
NO_FLAGS = 0,
NO_CONVERSION_FLAGS = 0,
ALLOW_HEX = 1,
ALLOW_OCTAL = 2,
ALLOW_IMPLICIT_OCTAL = 4,

View File

@ -2054,8 +2054,8 @@ TEST(InterpreterMixedComparisons) {
{kInternalizedStringConstant, kComputedString}) {
const char* lhs_cstr = inputs[i];
const char* rhs_cstr = inputs[j];
double lhs = StringToDouble(lhs_cstr, ConversionFlags::NO_FLAGS);
double rhs = StringToDouble(rhs_cstr, ConversionFlags::NO_FLAGS);
double lhs = StringToDouble(lhs_cstr, NO_CONVERSION_FLAGS);
double rhs = StringToDouble(rhs_cstr, NO_CONVERSION_FLAGS);
HandleAndZoneScope handles;
Isolate* isolate = handles.main_isolate();
Zone* zone = handles.main_zone();
@ -2156,8 +2156,8 @@ TEST(InterpreterStrictNotEqual) {
const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"};
for (size_t i = 0; i < arraysize(inputs); i++) {
for (size_t j = 0; j < arraysize(inputs); j++) {
double lhs = StringToDouble(inputs[i], ConversionFlags::NO_FLAGS);
double rhs = StringToDouble(inputs[j], ConversionFlags::NO_FLAGS);
double lhs = StringToDouble(inputs[i], NO_CONVERSION_FLAGS);
double rhs = StringToDouble(inputs[j], NO_CONVERSION_FLAGS);
Handle<Object> lhs_obj = factory->NewNumber(lhs);
Handle<Object> rhs_obj = factory->NewStringFromAsciiChecked(inputs[j]);

View File

@ -160,28 +160,28 @@ TEST(TrailingJunk) {
TEST(NonStrDecimalLiteral) {
CHECK(std::isnan(
StringToDouble(" ", NO_FLAGS, std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(
StringToDouble("", NO_FLAGS, std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(
StringToDouble(" ", NO_FLAGS, std::numeric_limits<double>::quiet_NaN())));
CHECK_EQ(0.0, StringToDouble("", NO_FLAGS));
CHECK_EQ(0.0, StringToDouble(" ", NO_FLAGS));
CHECK(std::isnan(StringToDouble(" ", NO_CONVERSION_FLAGS,
std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(StringToDouble("", NO_CONVERSION_FLAGS,
std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(StringToDouble(" ", NO_CONVERSION_FLAGS,
std::numeric_limits<double>::quiet_NaN())));
CHECK_EQ(0.0, StringToDouble("", NO_CONVERSION_FLAGS));
CHECK_EQ(0.0, StringToDouble(" ", NO_CONVERSION_FLAGS));
}
TEST(IntegerStrLiteral) {
CHECK_EQ(0.0, StringToDouble("0.0", NO_FLAGS));
CHECK_EQ(0.0, StringToDouble("0", NO_FLAGS));
CHECK_EQ(0.0, StringToDouble("00", NO_FLAGS));
CHECK_EQ(0.0, StringToDouble("000", NO_FLAGS));
CHECK_EQ(1.0, StringToDouble("1", NO_FLAGS));
CHECK_EQ(-1.0, StringToDouble("-1", NO_FLAGS));
CHECK_EQ(-1.0, StringToDouble(" -1 ", NO_FLAGS));
CHECK_EQ(1.0, StringToDouble(" +1 ", NO_FLAGS));
CHECK(std::isnan(StringToDouble(" - 1 ", NO_FLAGS)));
CHECK(std::isnan(StringToDouble(" + 1 ", NO_FLAGS)));
CHECK_EQ(0.0, StringToDouble("0.0", NO_CONVERSION_FLAGS));
CHECK_EQ(0.0, StringToDouble("0", NO_CONVERSION_FLAGS));
CHECK_EQ(0.0, StringToDouble("00", NO_CONVERSION_FLAGS));
CHECK_EQ(0.0, StringToDouble("000", NO_CONVERSION_FLAGS));
CHECK_EQ(1.0, StringToDouble("1", NO_CONVERSION_FLAGS));
CHECK_EQ(-1.0, StringToDouble("-1", NO_CONVERSION_FLAGS));
CHECK_EQ(-1.0, StringToDouble(" -1 ", NO_CONVERSION_FLAGS));
CHECK_EQ(1.0, StringToDouble(" +1 ", NO_CONVERSION_FLAGS));
CHECK(std::isnan(StringToDouble(" - 1 ", NO_CONVERSION_FLAGS)));
CHECK(std::isnan(StringToDouble(" + 1 ", NO_CONVERSION_FLAGS)));
CHECK_EQ(0.0, StringToDouble("0e0", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
CHECK_EQ(0.0, StringToDouble("0e1", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
@ -195,11 +195,11 @@ TEST(IntegerStrLiteral) {
TEST(LongNumberStr) {
CHECK_EQ(1e10, StringToDouble("1"
"0000000000",
NO_FLAGS));
NO_CONVERSION_FLAGS));
CHECK_EQ(1e20, StringToDouble("1"
"0000000000"
"0000000000",
NO_FLAGS));
NO_CONVERSION_FLAGS));
CHECK_EQ(1e60, StringToDouble("1"
"0000000000"
@ -208,21 +208,21 @@ TEST(LongNumberStr) {
"0000000000"
"0000000000"
"0000000000",
NO_FLAGS));
NO_CONVERSION_FLAGS));
CHECK_EQ(1e-2, StringToDouble("."
"0"
"1",
NO_FLAGS));
NO_CONVERSION_FLAGS));
CHECK_EQ(1e-11, StringToDouble("."
"0000000000"
"1",
NO_FLAGS));
NO_CONVERSION_FLAGS));
CHECK_EQ(1e-21, StringToDouble("."
"0000000000"
"0000000000"
"1",
NO_FLAGS));
NO_CONVERSION_FLAGS));
CHECK_EQ(1e-61, StringToDouble("."
"0000000000"
@ -232,16 +232,16 @@ TEST(LongNumberStr) {
"0000000000"
"0000000000"
"1",
NO_FLAGS));
NO_CONVERSION_FLAGS));
// x = 24414062505131248.0 and y = 24414062505131252.0 are representable in
// double. Check chat z = (x + y) / 2 is rounded to x...
CHECK_EQ(24414062505131248.0,
StringToDouble("24414062505131250.0", NO_FLAGS));
StringToDouble("24414062505131250.0", NO_CONVERSION_FLAGS));
// ... and z = (x + y) / 2 + delta is rounded to y.
CHECK_EQ(24414062505131252.0,
StringToDouble("24414062505131250.000000001", NO_FLAGS));
StringToDouble("24414062505131250.000000001", NO_CONVERSION_FLAGS));
}
@ -261,12 +261,14 @@ TEST(MaximumSignificantDigits) {
"847003580761626016356864581135848683152156368691976240370422601"
"6998291015625000000000000000000000000000000000e-308";
CHECK_EQ(4.4501477170144017780491e-308, StringToDouble(num, NO_FLAGS));
CHECK_EQ(4.4501477170144017780491e-308,
StringToDouble(num, NO_CONVERSION_FLAGS));
// Changes the result of strtod (at least in glibc implementation).
num[sizeof(num) - 8] = '1';
CHECK_EQ(4.4501477170144022721148e-308, StringToDouble(num, NO_FLAGS));
CHECK_EQ(4.4501477170144022721148e-308,
StringToDouble(num, NO_CONVERSION_FLAGS));
}
@ -287,29 +289,32 @@ TEST(MinimumExponent) {
"470035807616260163568645811358486831521563686919762403704226016"
"998291015625000000000000000000000000000000000e-1108";
CHECK_EQ(4.4501477170144017780491e-308, StringToDouble(num, NO_FLAGS));
CHECK_EQ(4.4501477170144017780491e-308,
StringToDouble(num, NO_CONVERSION_FLAGS));
// Changes the result of strtod (at least in glibc implementation).
num[sizeof(num) - 8] = '1';
CHECK_EQ(4.4501477170144022721148e-308, StringToDouble(num, NO_FLAGS));
CHECK_EQ(4.4501477170144022721148e-308,
StringToDouble(num, NO_CONVERSION_FLAGS));
}
TEST(MaximumExponent) {
char num[] = "0.16e309";
CHECK_EQ(1.59999999999999997765e+308, StringToDouble(num, NO_FLAGS));
CHECK_EQ(1.59999999999999997765e+308,
StringToDouble(num, NO_CONVERSION_FLAGS));
}
TEST(ExponentNumberStr) {
CHECK_EQ(1e1, StringToDouble("1e1", NO_FLAGS));
CHECK_EQ(1e1, StringToDouble("1e+1", NO_FLAGS));
CHECK_EQ(1e-1, StringToDouble("1e-1", NO_FLAGS));
CHECK_EQ(1e100, StringToDouble("1e+100", NO_FLAGS));
CHECK_EQ(1e-100, StringToDouble("1e-100", NO_FLAGS));
CHECK_EQ(1e-106, StringToDouble(".000001e-100", NO_FLAGS));
CHECK_EQ(1e1, StringToDouble("1e1", NO_CONVERSION_FLAGS));
CHECK_EQ(1e1, StringToDouble("1e+1", NO_CONVERSION_FLAGS));
CHECK_EQ(1e-1, StringToDouble("1e-1", NO_CONVERSION_FLAGS));
CHECK_EQ(1e100, StringToDouble("1e+100", NO_CONVERSION_FLAGS));
CHECK_EQ(1e-100, StringToDouble("1e-100", NO_CONVERSION_FLAGS));
CHECK_EQ(1e-106, StringToDouble(".000001e-100", NO_CONVERSION_FLAGS));
}
using OneBit1 = base::BitField<uint32_t, 0, 1>;

View File

@ -16,7 +16,8 @@ namespace platform {
// Parses |str| into |result|. Returns false iff there are
// leftover characters or parsing errors.
bool StrToD(const char* str, double* result) {
*result = v8::internal::StringToDouble(str, v8::internal::NO_FLAGS);
*result =
v8::internal::StringToDouble(str, v8::internal::NO_CONVERSION_FLAGS);
return std::isfinite(*result);
}