[Pkg-javascript-commits] [node-stack-utils] 45/67: Correctly handle symbol functions

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:53:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stack-utils.

commit edc5acd5afa47ce37f22e5145835af7145aea267
Author: Mark Wubben <mark at novemberborn.net>
Date:   Thu Feb 16 14:57:22 2017 +0000

    Correctly handle symbol functions
---
 index.js     | 32 ++++++++++++++++++++------------
 test/test.js | 10 +++++++++-
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/index.js b/index.js
index 214e2e0..cc292d0 100644
--- a/index.js
+++ b/index.js
@@ -214,13 +214,16 @@ var re = new RegExp(
     // $2 = function name
     // $3 = method name
   '(?:([^\\(\\[]*)(?: \\[as ([^\\]]+)\\])? \\()?' +
+    // Object.[Symbol.…] (, maybe
+    // $4 = function name
+  '(?:([^\\(\\[]+\\[Symbol\\..+?\\]) \\()?' +
     // (eval at <anonymous> (file.js:1:1),
-    // $4 = eval origin
-    // $5:$6:$7 are eval file/line/col, but not normally reported
+    // $5 = eval origin
+    // $6:$7:$8 are eval file/line/col, but not normally reported
   '(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?' +
     // file:line:col
-    // $8:$9:$10
-    // $11 = 'native' if native
+    // $9:$10:$11
+    // $12 = 'native' if native
   '(?:(.+?):(\\d+):(\\d+)|(native))' +
     // maybe close the paren, then end
   '\\)?$'
@@ -235,14 +238,15 @@ StackUtils.prototype.parseLine = function parseLine(line) {
   var ctor = match[1] === 'new';
   var fname = match[2];
   var meth = match[3];
-  var evalOrigin = match[4];
-  var evalFile = match[5];
-  var evalLine = Number(match[6]);
-  var evalCol = Number(match[7]);
-  var file = match[8];
-  var lnum = match[9];
-  var col = match[10];
-  var native = match[11] === 'native';
+  var symbolFname = match[4];
+  var evalOrigin = match[5];
+  var evalFile = match[6];
+  var evalLine = Number(match[7]);
+  var evalCol = Number(match[8]);
+  var file = match[9];
+  var lnum = match[10];
+  var col = match[11];
+  var native = match[12] === 'native';
 
   var res = {};
 
@@ -279,6 +283,10 @@ StackUtils.prototype.parseLine = function parseLine(line) {
     res.method = meth;
   }
 
+  if (symbolFname) {
+    res.function = symbolFname;
+  }
+
   return res;
 };
 
diff --git a/test/test.js b/test/test.js
index a2e7698..58d29a5 100644
--- a/test/test.js
+++ b/test/test.js
@@ -392,7 +392,15 @@ t.test('parseLine', function (t) {
     line: 3,
     column: 8,
     function: 'Object.foo bar'
-  });
+  })
+
+  // Array.from({ *[Symbol.iterator] () { throw new Error() } })
+  t.same(stack.parseLine('    at Object.[Symbol.iterator] (/user/dev/project/foo.js:3:8)'), {
+    file: 'foo.js',
+    line: 3,
+    column: 8,
+    function: 'Object.[Symbol.iterator]'
+  })
 
   t.same(stack.parseLine('    at foo (/some/other/dir/file.js:3:8)'), {
     file: '/some/other/dir/file.js',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stack-utils.git



More information about the Pkg-javascript-commits mailing list