diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index 62e19e1275..0e690cb3e9 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -992,16 +992,10 @@ HValue* CodeStubGraphBuilder::BuildCodeInitializedStub() { // Make sure that both arguments are strings if not known in advance. if ((flags & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { - IfBuilder if_leftnotstring(this); - if_leftnotstring.IfNot(left); - if_leftnotstring.Then(); - if_leftnotstring.Deopt("Expected string for LHS of string addition"); + left = BuildCheckString(left); } if ((flags & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { - IfBuilder if_rightnotstring(this); - if_rightnotstring.IfNot(right); - if_rightnotstring.Then(); - if_rightnotstring.Deopt("Expected string for RHS of string addition"); + right = BuildCheckString(right); } return BuildStringAdd(left, right, pretenure_flag); diff --git a/src/hydrogen.cc b/src/hydrogen.cc index f7b310003e..fd93ce3296 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -1273,17 +1273,14 @@ HValue* HGraphBuilder::BuildCheckMap(HValue* obj, Handle map) { } -HValue* HGraphBuilder::BuildCheckString( - HValue* object, const char* failure_reason) { - if (!object->type().IsString()) { - ASSERT(!object->IsConstant() || - !HConstant::cast(object)->HasStringValue()); - IfBuilder if_isstring(this); - if_isstring.If(object); - if_isstring.Then(); - if_isstring.ElseDeopt(failure_reason); +HValue* HGraphBuilder::BuildCheckString(HValue* string) { + if (!string->type().IsString()) { + ASSERT(!string->IsConstant() || + !HConstant::cast(string)->HasStringValue()); + BuildCheckHeapObject(string); + return Add(string, HCheckInstanceType::IS_STRING); } - return object; + return string; } @@ -8657,14 +8654,12 @@ HValue* HGraphBuilder::BuildBinaryOperation( (left_type->Is(Type::String()) || right_type->Is(Type::String()))) { // Validate type feedback for left argument. if (left_type->Is(Type::String())) { - left = BuildCheckString( - left, "Expected string for LHS of binary operation"); + left = BuildCheckString(left); } // Validate type feedback for right argument. if (right_type->Is(Type::String())) { - right = BuildCheckString( - right, "Expected string for RHS of binary operation"); + right = BuildCheckString(right); } // Convert left argument as necessary. diff --git a/src/hydrogen.h b/src/hydrogen.h index a117c551ad..d11fbc0a0d 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -1256,7 +1256,7 @@ class HGraphBuilder { HValue* BuildCheckHeapObject(HValue* object); HValue* BuildCheckMap(HValue* obj, Handle map); - HValue* BuildCheckString(HValue* object, const char* failure_reason); + HValue* BuildCheckString(HValue* string); HValue* BuildWrapReceiver(HValue* object, HValue* function); // Building common constructs