Commit a210f368 authored by Michael Starzinger's avatar Michael Starzinger

Extend typed lowering to cover JSStrictEqual on differing types.

R=rossberg@chromium.org, titzer@chromium.org
TEST=unittests/JSTypedLoweringTest.JSStrictEqualWithTheHole

Review URL: https://codereview.chromium.org/722223003

Cr-Commit-Position: refs/heads/master@{#25359}
parent 7e69b2f9
......@@ -459,8 +459,15 @@ Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) {
if (r.left() == r.right()) {
// x === x is always true if x != NaN
if (!r.left_type()->Maybe(Type::NaN())) {
return ReplaceEagerly(node, invert ? jsgraph()->FalseConstant()
: jsgraph()->TrueConstant());
return ReplaceEagerly(node, jsgraph()->BooleanConstant(!invert));
}
}
Type* string_or_number = Type::Union(Type::String(), Type::Number(), zone());
if (r.OneInputCannotBe(string_or_number)) {
// For values with canonical representation (i.e. not string nor number) an
// empty type intersection means the values cannot be strictly equal.
if (!r.left_type()->Maybe(r.right_type())) {
return ReplaceEagerly(node, jsgraph()->BooleanConstant(invert));
}
}
if (r.OneInputIs(Type::Undefined())) {
......
......@@ -26,6 +26,10 @@ const ExternalArrayType kExternalArrayTypes[] = {
};
Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(),
Type::Number(), Type::String(), Type::Object()};
const StrictMode kStrictModes[] = {SLOPPY, STRICT};
} // namespace
......@@ -108,6 +112,25 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumberAndBoolean) {
}
// -----------------------------------------------------------------------------
// JSStrictEqual
TEST_F(JSTypedLoweringTest, JSStrictEqualWithTheHole) {
Node* const the_hole = HeapConstant(factory()->the_hole_value());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FOREACH(Type*, type, kJSTypes) {
Node* const lhs = Parameter(type);
Reduction r = Reduce(graph()->NewNode(javascript()->StrictEqual(), lhs,
the_hole, context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsFalseConstant());
}
}
// -----------------------------------------------------------------------------
// JSShiftLeft
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment