From 49c3cb3767214e4fbb7a558e4aa750610b7b10cd Mon Sep 17 00:00:00 2001 From: Ben McCurdy Date: Mon, 17 Oct 2016 20:10:34 -0700 Subject: [PATCH] Fix toString shim --- source-map-support.js | 4 ++++ test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/source-map-support.js b/source-map-support.js index fe21a9a..13cdf0c 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -270,6 +270,10 @@ function CallSiteToString() { var isMethodCall = !(this.isToplevel() || isConstructor); if (isMethodCall) { var typeName = this.getTypeName(); + // Fixes shim to be backward compatable with Node v0 to v4 + if (typeName === "[object Object]") { + typeName = "null"; + } var methodName = this.getMethodName(); if (functionName) { if (typeName && functionName.indexOf(typeName) != 0) { diff --git a/test.js b/test.js index 1179f5e..583dedd 100644 --- a/test.js +++ b/test.js @@ -259,6 +259,21 @@ it('throw with empty source map', function() { ]); }); +it('throw in Timeout with empty source map', function(done) { + compareStdout(done, createEmptySourceMap(), [ + 'require("./source-map-support").install();', + 'setTimeout(function () {', + ' throw new Error("this is the error")', + '})' + ], [ + /\/.generated.js:3$/, + ' throw new Error("this is the error")', + /^ \^$/, + 'Error: this is the error', + /^ at ((null)|(Timeout))\._onTimeout \((?:.*\/)?.generated.js:3:11\)$/ + ]); +}); + it('throw with source map with gap', function() { compareStackTrace(createSourceMapWithGap(), [ 'throw new Error("test");'