From db491c915f43318552f77902c4028eb6f5a8dae4 Mon Sep 17 00:00:00 2001 From: Halstatt Lake Date: Mon, 26 Jun 2017 14:20:49 +0400 Subject: [PATCH 1/2] Added forwarding of stack traces from React.NET console mock --- src/React.Core/Resources/shims.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/React.Core/Resources/shims.js b/src/React.Core/Resources/shims.js index d73353df3..ab7640834 100644 --- a/src/React.Core/Resources/shims.js +++ b/src/React.Core/Resources/shims.js @@ -23,13 +23,23 @@ MockConsole.prototype = { for (var i = 1; i < arguments.length; i++) { serializedArgs.push(JSON.stringify(arguments[i])); } + + var callstack = this._getCallStack(); + this._calls.push({ method: methodName, - args: serializedArgs + args: serializedArgs, + stack: '"Call stack: ' + (callstack || 'not available') + '"' }); }, _formatCall: function(call) { - return 'console.' + call.method + '("[.NET]", ' + call.args.join(', ') + ');'; + return 'console.' + call.method + '("[.NET]", ' + call.args.join(', ') + ',' + call.stack + ');'; + }, + _getCallStack: function() { + var stack = new Error().stack; + return stack + ? stack.replace(/[\n\r]/g, '\\n') + : ''; }, getCalls: function() { return this._calls.map(this._formatCall).join('\n'); From bc864a0dd56c48c5dfeec07065b1c8b1cf9573b7 Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Sun, 2 Jul 2017 15:48:52 -0700 Subject: [PATCH 2/2] Use JSON encoding to simplify stack trace handling --- src/React.Core/Resources/shims.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/React.Core/Resources/shims.js b/src/React.Core/Resources/shims.js index ab7640834..2ac285f21 100644 --- a/src/React.Core/Resources/shims.js +++ b/src/React.Core/Resources/shims.js @@ -24,22 +24,14 @@ MockConsole.prototype = { serializedArgs.push(JSON.stringify(arguments[i])); } - var callstack = this._getCallStack(); - this._calls.push({ method: methodName, args: serializedArgs, - stack: '"Call stack: ' + (callstack || 'not available') + '"' + stack: '\nCall stack: ' + (new Error().stack || 'not available') }); }, _formatCall: function(call) { - return 'console.' + call.method + '("[.NET]", ' + call.args.join(', ') + ',' + call.stack + ');'; - }, - _getCallStack: function() { - var stack = new Error().stack; - return stack - ? stack.replace(/[\n\r]/g, '\\n') - : ''; + return 'console.' + call.method + '("[.NET]", ' + call.args.join(', ') + ', ' + JSON.stringify(call.stack) + ');'; }, getCalls: function() { return this._calls.map(this._formatCall).join('\n');