Reviewers: Yang,

Message:
Hey Yang,

Here's another easy... ripping out builtins one-by-one.
Please take a look.

Thanks,
Benedikt

Description:
[runtime] Replace %to_string_fun with %_ToString.

Introduce a new macro TO_STRING that maps to %_ToString and use that
instead of calling into the %to_string_fun JS builtin.  Long-term plan
is to use TO_STRING also in places where we now use TO_STRING_INLINE.

BUG=v8:4307
LOG=n

Please review this at https://codereview.chromium.org/1323543002/

Base URL: https://chromium.googlesource.com/v8/v8.git@ToStringStub

Affected files (+15, -54 lines):
  M src/contexts.h
  M src/macros.py
  M src/parser.cc
  M src/runtime.js
  M test/cctest/compiler/test-run-jscalls.cc
  D test/mjsunit/compiler/jsnatives.js
  M test/webkit/webkit.status


Index: test/mjsunit/compiler/jsnatives.js
diff --git a/test/mjsunit/compiler/jsnatives.js b/test/mjsunit/compiler/jsnatives.js
deleted file mode 100644
index 2369763db77d32c5a08ada78557f26375a233508..0000000000000000000000000000000000000000
--- a/test/mjsunit/compiler/jsnatives.js
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2009 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-//       notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-//       copyright notice, this list of conditions and the following
-//       disclaimer in the documentation and/or other materials provided
-//       with the distribution.
-//     * Neither the name of Google Inc. nor the names of its
-//       contributors may be used to endorse or promote products derived
-//       from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// Flags: --allow-natives-syntax
-
-// Test call of JS runtime functions.
-
-assertEquals("1", %to_string_fun(1));
Index: src/contexts.h
diff --git a/src/contexts.h b/src/contexts.h
index 05bc3b55ec872f65ce3b934b0639fcb98beb0e2b..4659750b94dd6d738ea3ba7d63b198403fe9a2c9 100644
--- a/src/contexts.h
+++ b/src/contexts.h
@@ -86,8 +86,7 @@ enum BindingFlags {
   V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable)                   \
   V(TO_LENGTH_FUN_INDEX, JSFunction, to_length_fun)                       \
   V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun)                       \
-  V(TO_PRIMITIVE_INDEX, JSFunction, to_primitive)                         \
-  V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun)
+  V(TO_PRIMITIVE_INDEX, JSFunction, to_primitive)


#define NATIVE_CONTEXT_JS_BUILTINS(V) \
Index: src/macros.py
diff --git a/src/macros.py b/src/macros.py
index 63b0b29489c28bb1df526154814120a01eb6a36c..278450ecc45d37ff478510fb250633111fbf09d3 100644
--- a/src/macros.py
+++ b/src/macros.py
@@ -150,6 +150,7 @@ macro TO_INTEGER_FOR_SIDE_EFFECT(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToNumber( macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
 macro TO_INT32(arg) = (arg | 0);
 macro TO_UINT32(arg) = (arg >>> 0);
+macro TO_STRING(arg) = (%_ToString(arg));
macro TO_STRING_INLINE(arg) = (IS_STRING(%IS_VAR(arg)) ? arg : $nonStringToString(arg)); macro TO_NUMBER_INLINE(arg) = (IS_NUMBER(%IS_VAR(arg)) ? arg : $nonNumberToNumber(arg));
 macro TO_OBJECT(arg) = (%_ToObject(arg));
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 3f635c70df275ea837606aa81354f6daea36a882..2d53a7f338ff8d195bbb7993be9226855e575618 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -5918,8 +5918,8 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
       ZoneList<Expression*>* args =
           new (zone()) ZoneList<Expression*>(1, zone());
       args->Add(sub, zone());
-      Expression* middle = factory()->NewCallRuntime(
-          Context::TO_STRING_FUN_INDEX, args, sub->position());
+ Expression* middle = factory()->NewCallRuntime(Runtime::kInlineToString, + args, sub->position());

       expr = factory()->NewBinaryOperation(
           Token::ADD, factory()->NewBinaryOperation(
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index 89a3f2241dd9e95beefe7733fc282b42a1b5fd83..18efec36f5ee4703d03555d94d92ac1442539446 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -165,7 +165,7 @@ function ADD(x) {
   var b = %to_primitive(x, NO_HINT);

   if (IS_STRING(a)) {
-    return %_StringAdd(a, %to_string_fun(b));
+    return %_StringAdd(a, TO_STRING(b));
   } else if (IS_STRING(b)) {
     return %_StringAdd(%non_string_to_string(a), b);
   } else {
@@ -191,7 +191,7 @@ function STRING_ADD_LEFT(y) {
     } else {
       y = IS_NUMBER(y)
           ? %_NumberToString(y)
-          : %to_string_fun(%to_primitive(y, NO_HINT));
+          : TO_STRING(%to_primitive(y, NO_HINT));
     }
   }
   return %_StringAdd(this, y);
@@ -207,7 +207,7 @@ function STRING_ADD_RIGHT(y) {
     } else {
       x = IS_NUMBER(x)
           ? %_NumberToString(x)
-          : %to_string_fun(%to_primitive(x, NO_HINT));
+          : TO_STRING(%to_primitive(x, NO_HINT));
     }
   }
   return %_StringAdd(x, y);
@@ -495,7 +495,7 @@ function APPLY_PREPARE(args) {
if (length > kSafeArgumentsLength) throw %make_range_error(kStackOverflow);

   if (!IS_SPEC_FUNCTION(this)) {
- throw %make_type_error(kApplyNonFunction, %to_string_fun(this), typeof this); + throw %make_type_error(kApplyNonFunction, TO_STRING(this), typeof this);
   }

   // Make sure the arguments list has the right type.
@@ -523,7 +523,7 @@ function REFLECT_APPLY_PREPARE(args) {
   }

   if (!IS_SPEC_FUNCTION(this)) {
-    throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
+    throw %make_type_error(kCalledNonCallable, TO_STRING(this));
   }

   if (!IS_SPEC_OBJECT(args)) {
@@ -562,17 +562,17 @@ function REFLECT_CONSTRUCT_PREPARE(

   if (!ctorOk) {
     if (!IS_SPEC_FUNCTION(this)) {
-      throw %make_type_error(kCalledNonCallable, %to_string_fun(this));
+      throw %make_type_error(kCalledNonCallable, TO_STRING(this));
     } else {
-      throw %make_type_error(kNotConstructor, %to_string_fun(this));
+      throw %make_type_error(kNotConstructor, TO_STRING(this));
     }
   }

   if (!newTargetOk) {
     if (!IS_SPEC_FUNCTION(newTarget)) {
- throw %make_type_error(kCalledNonCallable, %to_string_fun(newTarget));
+      throw %make_type_error(kCalledNonCallable, TO_STRING(newTarget));
     } else {
-      throw %make_type_error(kNotConstructor, %to_string_fun(newTarget));
+      throw %make_type_error(kNotConstructor, TO_STRING(newTarget));
     }
   }

@@ -609,12 +609,6 @@ function TO_NUMBER() {
 }


-// Convert the receiver to a string - forward to ToString.
-function TO_STRING() {
-  return %to_string_fun(this);
-}
-
-
 /* -------------------------------------
    - - -   C o n v e r s i o n s   - - -
    -------------------------------------
@@ -873,7 +867,6 @@ $toString = ToString;
   "to_length_fun", ToLength,
   "to_number_fun", ToNumber,
   "to_primitive", ToPrimitive,
-  "to_string_fun", ToString,
 ]);

 utils.Export(function(to) {
Index: test/cctest/compiler/test-run-jscalls.cc
diff --git a/test/cctest/compiler/test-run-jscalls.cc b/test/cctest/compiler/test-run-jscalls.cc index ed3a0b412a1112e964764bfbd71bfc72a55e44ea..1166cf0b816470ab214f1d739748e0e25d1451a9 100644
--- a/test/cctest/compiler/test-run-jscalls.cc
+++ b/test/cctest/compiler/test-run-jscalls.cc
@@ -144,11 +144,10 @@ TEST(RuntimeCallCPP2) {

 TEST(RuntimeCallJS) {
   FLAG_allow_natives_syntax = true;
-  FunctionTester T("(function(a) { return %to_string_fun(a); })");
+  FunctionTester T("(function(a) { return %non_string_to_string(a); })");

   T.CheckCall(T.Val("23"), T.Val(23), T.undefined());
   T.CheckCall(T.Val("4.2"), T.Val(4.2), T.undefined());
-  T.CheckCall(T.Val("str"), T.Val("str"), T.undefined());
   T.CheckCall(T.Val("true"), T.true_value(), T.undefined());
   T.CheckCall(T.Val("false"), T.false_value(), T.undefined());
   T.CheckCall(T.Val("undefined"), T.undefined(), T.undefined());
Index: test/webkit/webkit.status
diff --git a/test/webkit/webkit.status b/test/webkit/webkit.status
index 57d86cb92138dfbeab39edb1e1abf2449710cd76..578d1141125ac590e4be22a7fd4398aa7b944688 100644
--- a/test/webkit/webkit.status
+++ b/test/webkit/webkit.status
@@ -35,6 +35,7 @@
   'dfg-inline-arguments-reset-changetype': [PASS, FAIL],
   # TODO(turbofan): We run out of stack earlier on 64-bit for now.
   'fast/js/deep-recursion-test': [PASS, NO_VARIANTS],
+  'function-apply-aliased': [PASS, NO_VARIANTS],
   # TODO(bmeurer,svenpanne): Investigate test failure.
   'fast/js/toString-number': [SKIP],
 }],  # ALWAYS


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to