Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: src/hydrogen.cc

Issue 27011002: Handle string + number in hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 45fbbc09821824998595b84291389a3bf214bfd0..4bfb91c1108245716adbbb6f19c1f32b49ead887 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -1283,8 +1283,7 @@ void HGraphBuilder::BuildTransitionElementsKind(HValue* object,
HValue* HGraphBuilder::BuildLookupNumberStringCache(
- HValue* object,
- HIfContinuation* continuation) {
+ HValue* object, ToStringMode mode, HIfContinuation* continuation) {
// Create a joinable continuation.
HIfContinuation found(graph()->CreateBasicBlock(),
graph()->CreateBasicBlock());
@@ -1366,6 +1365,10 @@ HValue* HGraphBuilder::BuildLookupNumberStringCache(
}
if_keyeqobject.JoinContinuation(&found);
}
+ if (mode == CHECK_NUMBER) {
+ if_objectisnumber.Else();
+ if_objectisnumber.Deopt("Expected Argument to be Numeric");
+ }
if_keyisnumber.JoinContinuation(&found);
}
if_objectisnumber.JoinContinuation(&found);
@@ -1391,12 +1394,12 @@ HValue* HGraphBuilder::BuildLookupNumberStringCache(
}
-HValue* HGraphBuilder::BuildNumberToString(HValue* number) {
+HValue* HGraphBuilder::BuildNumberToString(HValue* number, ToStringMode mode) {
NoObservableSideEffectsScope scope(this);
// Lookup the number in the number string cache.
HIfContinuation continuation;
- HValue* value = BuildLookupNumberStringCache(number, &continuation);
+ HValue* value = BuildLookupNumberStringCache(number, mode, &continuation);
IfBuilder if_found(this, &continuation);
if_found.Then();
@@ -7909,17 +7912,25 @@ HInstruction* HGraphBuilder::BuildBinaryOperation(
switch (op) {
case Token::ADD:
if (is_string_add) {
- StringAddFlags flags = STRING_ADD_CHECK_BOTH;
+ StringAddFlags flags = STRING_ADD_CHECK_NONE;
if (left_type->Is(Type::String())) {
BuildCheckHeapObject(left);
AddInstruction(HCheckInstanceType::NewIsString(left, zone()));
- flags = STRING_ADD_CHECK_RIGHT;
+ if (right_type->Is(Type::Number())) {
+ right = BuildNumberToString(right, CHECK_NUMBER);
+ } else {
+ flags = STRING_ADD_CHECK_RIGHT;
+ }
}
if (right_type->Is(Type::String())) {
+ if (left_type->Is(Type::Number())) {
+ left = BuildNumberToString(left, CHECK_NUMBER);
+ } else {
+ flags = (flags == STRING_ADD_CHECK_RIGHT)
+ ? STRING_ADD_CHECK_NONE : STRING_ADD_CHECK_LEFT;
+ }
BuildCheckHeapObject(right);
AddInstruction(HCheckInstanceType::NewIsString(right, zone()));
- flags = (flags == STRING_ADD_CHECK_BOTH)
- ? STRING_ADD_CHECK_LEFT : STRING_ADD_CHECK_NONE;
}
instr = NewUncasted<HStringAdd>(left, right, flags);
} else {
@@ -9124,7 +9135,7 @@ void HOptimizedGraphBuilder::GenerateNumberToString(CallRuntime* call) {
ASSERT_EQ(1, call->arguments()->length());
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
HValue* number = Pop();
- HValue* result = BuildNumberToString(number);
+ HValue* result = BuildNumberToString(number, ALLOW_SIDE_EFFECTS);
return ast_context()->ReturnValue(result);
}
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698