Reviewers: arv,

Message:
PTAL

It's crrev.com/1072573002 without the flag flip, so that it's easier to revert
the flag flip if needed

Description:
[es6] don't "replace" Object.prototype.toString for --harmony-tostring

BUG=v8:3502
LOG=N
[email protected]

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

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

Affected files (+29, -21 lines):
  M src/harmony-tostring.js
  M src/runtime/runtime.h
  M src/runtime/runtime-internal.cc
  M src/v8natives.js
  M test/mjsunit/es6/prototype-ordinary-objects.js
  M test/mjsunit/function-arguments-null.js


Index: src/harmony-tostring.js
diff --git a/src/harmony-tostring.js b/src/harmony-tostring.js
index 4f4f986fd26bc904f45c92c2b202732d0a4cf709..cd2e7fb718366cf3f38b150e93b120d4becb0e17 100644
--- a/src/harmony-tostring.js
+++ b/src/harmony-tostring.js
@@ -36,19 +36,9 @@ HarmonyToStringExtendSymbolPrototype();
 function HarmonyToStringExtendObjectPrototype() {
   %CheckIsBootstrapping();

-  // Can't use InstallFunctions() because will fail in Debug mode.
-  // Emulate InstallFunctions() here.
-  %FunctionSetName(ObjectToStringHarmony, "toString");
-  %FunctionRemovePrototype(ObjectToStringHarmony);
-  %SetNativeFlag(ObjectToStringHarmony);
-
-  // Set up the non-enumerable functions on the Array prototype object.
-  var desc = ToPropertyDescriptor({
-    value: ObjectToStringHarmony
-  });
-  DefineOwnProperty($Object.prototype, "toString", desc, false);
-
-  %ToFastProperties($Object.prototype);
+  InstallFunctions($Object.prototype, DONT_ENUM, $Array(
+    "toString", ObjectToStringHarmony
+  ));
 }

 HarmonyToStringExtendObjectPrototype();
Index: src/runtime/runtime-internal.cc
diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index acaaeff3f820c74b60f1e207ee74497e17a25c2c..b6176974909d5937e9da0d030a6f74177e395167 100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -342,5 +342,11 @@ RUNTIME_FUNCTION(Runtime_Unlikely) {
   DCHECK(args.length() == 1);
   return args[0];
 }
+
+
+RUNTIME_FUNCTION(Runtime_HarmonyToString) {
+ // TODO(caitp): Delete this runtime method when removing --harmony-tostring
+  return isolate->heap()->ToBoolean(FLAG_harmony_tostring);
+}
 }
 }  // namespace v8::internal
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index a051fd0276e7c7b6fb91db539266dc8ea654d9c4..8560bcbb9ae66e6368c179db64cb2624cc2c3edc 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -290,7 +290,8 @@ namespace internal {
   F(GetFromCache, 2, 1)                   \
   F(IncrementStatsCounter, 1, 1)          \
   F(Likely, 1, 1)                         \
-  F(Unlikely, 1, 1)
+  F(Unlikely, 1, 1)                       \
+  F(HarmonyToString, 0, 1)


 #define FOR_EACH_INTRINSIC_JSON(F) \
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 56e8c2d69d035f49da62b2b2b7d25e7355a60979..4615c63620eb01ab3ccea1e849c5f912631097c8 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1408,9 +1408,7 @@ function SetUpObject() {

   %AddNamedProperty($Object.prototype, "constructor", $Object, DONT_ENUM);

-  // Set up non-enumerable functions on the Object.prototype object.
-  InstallFunctions($Object.prototype, DONT_ENUM, $Array(
-    "toString", NoSideEffectsObjectToString,
+  var kObjectProtoMethods = $Array(
     "toLocaleString", ObjectToLocaleString,
     "valueOf", ObjectValueOf,
     "hasOwnProperty", ObjectHasOwnProperty,
@@ -1420,7 +1418,14 @@ function SetUpObject() {
     "__lookupGetter__", ObjectLookupGetter,
     "__defineSetter__", ObjectDefineSetter,
     "__lookupSetter__", ObjectLookupSetter
-  ));
+  );
+
+  if (!%HarmonyToString()) {
+    kObjectProtoMethods.unshift("toString", NoSideEffectsObjectToString);
+  }
+
+  // Set up non-enumerable functions on the Object.prototype object.
+  InstallFunctions($Object.prototype, DONT_ENUM, kObjectProtoMethods);
   InstallGetterSetter($Object.prototype, "__proto__",
                       ObjectGetProto, ObjectSetProto);

Index: test/mjsunit/es6/prototype-ordinary-objects.js
diff --git a/test/mjsunit/es6/prototype-ordinary-objects.js b/test/mjsunit/es6/prototype-ordinary-objects.js index 6704288089a50dd355a09e16d96de47925d83e85..517ee068c3cf88e4d18b3c79fd743e286aaafb27 100644
--- a/test/mjsunit/es6/prototype-ordinary-objects.js
+++ b/test/mjsunit/es6/prototype-ordinary-objects.js
@@ -48,6 +48,9 @@ var funcs = [

 for (var fun of funcs) {
   var p = fun.prototype;
+
+  // @@toStringTag is tested separately, and interferes with this test.
+  delete p[Symbol.toStringTag];
   assertEquals('[object Object]', Object.prototype.toString.call(p));
 }

@@ -60,5 +63,5 @@ var funcs = [

 for (var fun of funcs) {
   var p = fun.prototype;
- assertEquals('[object ' + fun.name + ']', Object.prototype.toString.call(p));
+  assertEquals(`[object ${fun.name}]`, Object.prototype.toString.call(p));
 }
Index: test/mjsunit/function-arguments-null.js
diff --git a/test/mjsunit/function-arguments-null.js b/test/mjsunit/function-arguments-null.js index 21e542fc81e7a93362a886810ad7076443efecc5..6b47a10188b8ab2a97bca2d1731dec4241523eaa 100644
--- a/test/mjsunit/function-arguments-null.js
+++ b/test/mjsunit/function-arguments-null.js
@@ -25,6 +25,9 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-// The arguments property of functions should be null when not
+// The arguments property of sloppy functions should be null when not
 // executing inside the function.
-assertTrue(toString.arguments === null);
+
+function sloppy() {}
+
+assertTrue(sloppy.arguments === null);


--
--
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