From f512b0606d1e1e93899752693e35f90e69b024ee Mon Sep 17 00:00:00 2001 From: Halstatt Lake Date: Mon, 12 Jun 2017 22:13:40 +0400 Subject: [PATCH 1/2] Expose MaxUsagesPerEngine as an configuration option in React.NET --- src/React.Core/IReactSiteConfiguration.cs | 11 +++++++++++ src/React.Core/JavaScriptEngineFactory.cs | 4 ++++ src/React.Core/ReactSiteConfiguration.cs | 15 +++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/React.Core/IReactSiteConfiguration.cs b/src/React.Core/IReactSiteConfiguration.cs index 9337db3c0..bd10fee0f 100644 --- a/src/React.Core/IReactSiteConfiguration.cs +++ b/src/React.Core/IReactSiteConfiguration.cs @@ -102,6 +102,17 @@ public interface IReactSiteConfiguration /// IReactSiteConfiguration SetMaxEngines(int? maxEngines); + /// + /// Gets or sets the maximum number of times an engine can be reused before it is disposed. + /// 0 is unlimited. Defaults to 100. + /// + int? MaxUsagesPerEngine { get; set; } + /// + /// Sets the maximum number of times an engine can be reused before it is disposed. + /// 0 is unlimited. Defaults to 100. + /// + IReactSiteConfiguration SetMaxUsagesPerEngine(int? maxUsagesPerEngine); + /// /// Gets or sets whether the MSIE engine should be used if V8 is unavailable. /// diff --git a/src/React.Core/JavaScriptEngineFactory.cs b/src/React.Core/JavaScriptEngineFactory.cs index 073f7b791..45315204a 100644 --- a/src/React.Core/JavaScriptEngineFactory.cs +++ b/src/React.Core/JavaScriptEngineFactory.cs @@ -100,6 +100,10 @@ protected virtual IJsPool CreatePool() { poolConfig.StartEngines = _config.StartEngines.Value; } + if (_config.MaxUsagesPerEngine != null) + { + poolConfig.MaxUsagesPerEngine = _config.MaxUsagesPerEngine.Value; + } var pool = new JsPool(poolConfig); // Reset the recycle exception on recycle. If there *are* errors loading the scripts diff --git a/src/React.Core/ReactSiteConfiguration.cs b/src/React.Core/ReactSiteConfiguration.cs index 5fc057eec..bab2e5e23 100644 --- a/src/React.Core/ReactSiteConfiguration.cs +++ b/src/React.Core/ReactSiteConfiguration.cs @@ -191,6 +191,21 @@ public IReactSiteConfiguration SetMaxEngines(int? maxEngines) return this; } + /// + /// Gets or sets the maximum number of times an engine can be reused before it is disposed. + /// 0 is unlimited. Defaults to 100. + /// + public int? MaxUsagesPerEngine { get; set; } + /// + /// Sets the maximum number of times an engine can be reused before it is disposed. + /// 0 is unlimited. Defaults to 100. + /// + public IReactSiteConfiguration SetMaxUsagesPerEngine(int? maxUsagesPerEngine) + { + MaxUsagesPerEngine = maxUsagesPerEngine; + return this; + } + /// /// Gets or sets whether the MSIE engine should be used if V8 is unavailable. /// From a54470a8393c7edbfc4ad3b9a23413c578e898c9 Mon Sep 17 00:00:00 2001 From: Halstatt Lake Date: Mon, 26 Jun 2017 14:08:18 +0400 Subject: [PATCH 2/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..e4b70d292 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: callstack ? '"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');