Reviewers: yurys,

Message:
Yury, please take a look!

Description:
[V8] Use function.displayName in Error.stack

If function contains displayName and its type is string then use it instead
function.name in stack trace string.

BUG=17356
[email protected]

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

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

Affected files (+21, -1 lines):
  M src/messages.js
  M test/mjsunit/stack-traces.js


Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index b4da5326d661379e389b12f13abc3b4337196642..7a067c07bb4512e69b6e3a4a6e8669ae48f92373 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -823,8 +823,13 @@ function CallSiteGetFunction() {
 }

 function CallSiteGetFunctionName() {
+  // See if the function has displayName
+  var name = GET_PRIVATE(this, CallSiteFunctionKey).displayName;
+  if (name && IS_STRING(name)) {
+    return name;
+  }
   // See if the function knows its own name
-  var name = GET_PRIVATE(this, CallSiteFunctionKey).name;
+  name = GET_PRIVATE(this, CallSiteFunctionKey).name;
   if (name) {
     return name;
   }
Index: test/mjsunit/stack-traces.js
diff --git a/test/mjsunit/stack-traces.js b/test/mjsunit/stack-traces.js
index f80a627b24a87eae9fe00e5bd0a24c5b7f5af903..ac4f2f127d574d6e678c0e839ac11b8baf824326 100644
--- a/test/mjsunit/stack-traces.js
+++ b/test/mjsunit/stack-traces.js
@@ -94,6 +94,19 @@ function testAnonymousMethod() {
   (function () { FAIL }).call([1, 2, 3]);
 }

+function testMethodDisplayName() {
+  function gen(name, counter) {
+    var f = function() {
+      if (counter === 0)
+        FAIL;
+      gen(name, counter - 1)();
+    };
+    f.displayName = name + '_' + counter;
+    return f;
+  };
+  gen('foo', 2)();
+}
+
 function CustomError(message, stripPoint) {
   this.message = message;
   Error.captureStackTrace(this, stripPoint);
@@ -261,6 +274,8 @@ testTrace("testValue", testValue, ["at Number.causeError"]);
 testTrace("testConstructor", testConstructor, ["new Plonk"]);
testTrace("testRenamedMethod", testRenamedMethod, ["Wookie.a$b$c$d [as d]"]); testTrace("testAnonymousMethod", testAnonymousMethod, ["Array.<anonymous>"]);
+testTrace("testMethodDisplayName", testMethodDisplayName,
+    [" at foo_0", " at foo_1", " at foo_2 "]);
 testTrace("testDefaultCustomError", testDefaultCustomError,
     ["hep-hey", "new CustomError"],
     ["collectStackTrace"]);


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