Index: src/objects.h |
diff --git a/src/objects.h b/src/objects.h |
index 74ed139080df8238601f931fc5b38910635d868c..e28081c33f4cd8bb48dfee82dbfb9aa9e86dfbd4 100644 |
--- a/src/objects.h |
+++ b/src/objects.h |
@@ -800,6 +800,7 @@ enum FixedArraySubInstanceType { |
}; |
+// TODO(bmeurer): Remove this in favor of the ComparisonResult below. |
enum CompareResult { |
LESS = -1, |
EQUAL = 0, |
@@ -809,6 +810,16 @@ enum CompareResult { |
}; |
+// 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 > x |
+ kUndefined // at least one of x or y was undefined or NaN |
+}; |
+ |
+ |
#define DECL_BOOLEAN_ACCESSORS(name) \ |
inline bool name() const; \ |
inline void set_##name(bool value); \ |
@@ -1083,6 +1094,10 @@ class Object { |
bool BooleanValue(); // ECMA-262 9.2. |
+ // ES6 section 7.2.11 Abstract Relational Comparison |
+ MUST_USE_RESULT static Maybe<ComparisonResult> Compare( |
+ Handle<Object> x, Handle<Object> y, Strength strength = Strength::WEAK); |
+ |
// ES6 section 7.2.12 Abstract Equality Comparison |
MUST_USE_RESULT static Maybe<bool> Equals(Handle<Object> x, Handle<Object> y); |
@@ -1148,6 +1163,16 @@ class Object { |
Isolate* isolate, Handle<Object> lhs, Handle<Object> rhs, |
Strength strength = Strength::WEAK); |
+ // ES6 section 12.9 Relational Operators |
+ MUST_USE_RESULT static inline Maybe<bool> GreaterThan( |
+ Handle<Object> x, Handle<Object> y, Strength strength = Strength::WEAK); |
+ MUST_USE_RESULT static inline Maybe<bool> GreaterThanOrEqual( |
+ Handle<Object> x, Handle<Object> y, Strength strength = Strength::WEAK); |
+ MUST_USE_RESULT static inline Maybe<bool> LessThan( |
+ Handle<Object> x, Handle<Object> y, Strength strength = Strength::WEAK); |
+ MUST_USE_RESULT static inline Maybe<bool> LessThanOrEqual( |
+ Handle<Object> x, Handle<Object> y, Strength strength = Strength::WEAK); |
+ |
// ES6 section 12.11 Binary Bitwise Operators |
MUST_USE_RESULT static MaybeHandle<Object> BitwiseAnd( |
Isolate* isolate, Handle<Object> lhs, Handle<Object> rhs, |
@@ -8489,6 +8514,20 @@ class String: public Name { |
// Requires: StringShape(this).IsIndirect() && this->IsFlat() |
inline String* GetUnderlying(); |
+ // String relational comparison, implemented according to ES6 section 7.2.11 |
+ // Abstract Relational Comparison (step 5): The comparison of Strings uses a |
+ // simple lexicographic ordering on sequences of code unit values. There is no |
+ // attempt to use the more complex, semantically oriented definitions of |
+ // character or string equality and collating order defined in the Unicode |
+ // specification. Therefore String values that are canonically equal according |
+ // to the Unicode standard could test as unequal. In effect this algorithm |
+ // assumes that both Strings are already in normalized form. Also, note that |
+ // for strings containing supplementary characters, lexicographic ordering on |
+ // sequences of UTF-16 code unit values differs from that on sequences of code |
+ // point values. |
+ MUST_USE_RESULT static ComparisonResult Compare(Handle<String> x, |
+ Handle<String> y); |
+ |
// String equality operations. |
inline bool Equals(String* other); |
inline static bool Equals(Handle<String> one, Handle<String> two); |