[crankshaft] Add support for %_ToString.
authorbmeurer <bmeurer@chromium.org>
Mon, 28 Sep 2015 05:01:10 +0000 (22:01 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 28 Sep 2015 05:01:29 +0000 (05:01 +0000)
Also support %_ToString in Crankshaft utilizing the ToStringStub, which
is also used in TurboFan and fullcodegen. This is necessary to repair a
regression on Octane that was introduced when switching from the hand
crafted NonStringToString/ToString magic to %_ToString (which properly
supports @@toPrimitive).

BUG=chromium:535953,v8:4307
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#30955}

src/hydrogen.cc
src/hydrogen.h

index 87f8ce9..d2a617f 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "src/allocation-site-scopes.h"
 #include "src/ast-numbering.h"
+#include "src/code-factory.h"
 #include "src/full-codegen/full-codegen.h"
 #include "src/hydrogen-bce.h"
 #include "src/hydrogen-bch.h"
@@ -12224,6 +12225,24 @@ void HOptimizedGraphBuilder::GenerateToObject(CallRuntime* call) {
 }
 
 
+void HOptimizedGraphBuilder::GenerateToString(CallRuntime* call) {
+  DCHECK_EQ(1, call->arguments()->length());
+  CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
+  Callable callable = CodeFactory::ToString(isolate());
+  HValue* input = Pop();
+  if (input->type().IsString()) {
+    return ast_context()->ReturnValue(input);
+  } else {
+    HValue* stub = Add<HConstant>(callable.code());
+    HValue* values[] = {context(), input};
+    HInstruction* result =
+        New<HCallWithDescriptor>(stub, 0, callable.descriptor(),
+                                 Vector<HValue*>(values, arraysize(values)));
+    return ast_context()->ReturnInstruction(result, call->id());
+  }
+}
+
+
 void HOptimizedGraphBuilder::GenerateIsJSProxy(CallRuntime* call) {
   DCHECK(call->arguments()->length() == 1);
   CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
index 0b9ef42..f9589b2 100644 (file)
@@ -2224,6 +2224,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
   F(TwoByteSeqStringSetChar)           \
   F(ObjectEquals)                      \
   F(ToObject)                          \
+  F(ToString)                          \
   F(IsFunction)                        \
   F(IsSpecObject)                      \
   F(MathPow)                           \