From a0417c29d8d1551d9b964c1baa909fc74c8bfaec Mon Sep 17 00:00:00 2001 From: Matthias Liedtke Date: Wed, 25 Jan 2023 17:03:45 +0100 Subject: [PATCH] Use explicit values for ComparisonResult Change-Id: I2e0d1896b5fae166bb8563d1fcb1cea620e20f0f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4194716 Commit-Queue: Jakob Kummerow Auto-Submit: Matthias Liedtke Reviewed-by: Jakob Kummerow Cr-Commit-Position: refs/heads/main@{#85484} --- src/objects/js-temporal-objects.cc | 12 ++---------- src/objects/objects.h | 8 ++++---- src/runtime/runtime-wasm.cc | 12 ++---------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/objects/js-temporal-objects.cc b/src/objects/js-temporal-objects.cc index c08d78e783..36afb3a0dd 100644 --- a/src/objects/js-temporal-objects.cc +++ b/src/objects/js-temporal-objects.cc @@ -3106,16 +3106,8 @@ MaybeHandle SystemZonedDateTime( } int CompareResultToSign(ComparisonResult r) { - switch (r) { - case ComparisonResult::kEqual: - return 0; - case ComparisonResult::kLessThan: - return -1; - case ComparisonResult::kGreaterThan: - return 1; - case ComparisonResult::kUndefined: - UNREACHABLE(); - } + DCHECK_NE(r, ComparisonResult::kUndefined); + return static_cast(r); } // #sec-temporal-formattimezoneoffsetstring diff --git a/src/objects/objects.h b/src/objects/objects.h index 85e1c6012a..88dc5731a8 100644 --- a/src/objects/objects.h +++ b/src/objects/objects.h @@ -262,10 +262,10 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; // Result of an abstract relational comparison of x and y, implemented according // to ES6 section 7.2.11 Abstract Relational Comparison. enum class ComparisonResult { - kLessThan, // x < y - kEqual, // x = y - kGreaterThan, // x > y - kUndefined // at least one of x or y was undefined or NaN + kLessThan = -1, // x < y + kEqual = 0, // x = y + kGreaterThan = 1, // x > y + kUndefined = 2 // at least one of x or y was undefined or NaN }; // (Returns false whenever {result} is kUndefined.) diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc index 35e581e55d..a56b81b10e 100644 --- a/src/runtime/runtime-wasm.cc +++ b/src/runtime/runtime-wasm.cc @@ -1369,16 +1369,8 @@ RUNTIME_FUNCTION(Runtime_WasmStringCompare) { Handle lhs(String::cast(args[0]), isolate); Handle rhs(String::cast(args[1]), isolate); ComparisonResult result = String::Compare(isolate, lhs, rhs); - switch (result) { - case ComparisonResult::kEqual: - return Smi::FromInt(0); - case ComparisonResult::kGreaterThan: - return Smi::FromInt(1); - case ComparisonResult::kLessThan: - return Smi::FromInt(-1); - case ComparisonResult::kUndefined: - UNREACHABLE(); - } + DCHECK_NE(result, ComparisonResult::kUndefined); + return Smi::FromInt(static_cast(result)); } } // namespace internal