diff --git a/README.md b/README.md index 1580a85..98ada51 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ StackTraceDeminifier sourceMapCallstackDeminifier = StackTraceDeminfierFactory.G DeminifyStackTraceResult deminifyStackTraceResult = sourceMapCallstackDeminifier.DeminifyStackTrace(callstack) ``` -The result of `DeminifyStackTrace` is a `DeminifyStackTraceResult`, which is an object that contains a list of the parsed minified `StackFrame` objects in the `MinifiedStackFrame` property. The `DeminifiedStackFrame` property contains the best guess `StackFrame` object that maps to the `MinifiedStackFrame` element with the same index. Note that any of the properties on a `StackTrace` object may be null if no value could be extracted from the input callstack string or source map. +The result of `DeminifyStackTrace` is a `DeminifyStackTraceResult`, which is an object that contains a list of `StackFrameDeminificationResults` which contains the parsed minified `StackFrame` objects in the `MinifiedStackFrame` property and an enum indicating if any errors occured when attempting to deminify the `StackFrame`. The `DeminifiedStackFrame` property contains the best guess `StackFrame` object that maps to the `MinifiedStackFrame` element with the same index. Note that any of the properties on a `StackTrace` object may be null if no value could be extracted from the input callstack string or source map. #### Memory Consumption Parsed soure maps can take up a lot of memory for large JavaScript files. In order to allow for the `StackTraceDeminifier` to be used on servers with limited memory resources, the `StackTraceDeminfierFactory` exposes a `GetMethodNameOnlyStackTraceDeminfier` method that returns a `StackTraceDeminifier` that does not keep source maps in memory. Since the `StackTraceDeminifier` returned from this method only reads the source map once, the deminified stack frames will only contain the deminified method name and will not contain the original source location. diff --git a/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs b/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs index b294035..70ef4d7 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs @@ -6,6 +6,6 @@ namespace SourcemapToolkit.CallstackDeminifier { public List MinifiedStackFrames; - public List DeminifiedStackFrames; + public List DeminifiedStackFrameResults; } } diff --git a/src/SourceMapToolkit.CallstackDeminifier/FunctionMapGenerator.cs b/src/SourceMapToolkit.CallstackDeminifier/FunctionMapGenerator.cs index a1a2bbf..7a3d243 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/FunctionMapGenerator.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/FunctionMapGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Ajax.Utilities; @@ -61,36 +62,42 @@ namespace SourcemapToolkit.CallstackDeminifier /// /// Gets the original name corresponding to a function based on the information provided in the source map. /// - /// internal static string GetDeminifiedMethodNameFromSourceMap(FunctionMapEntry wrappingFunction, SourceMap sourceMap) { + if (wrappingFunction == null) + { + throw new ArgumentNullException(nameof(wrappingFunction)); + } + + if (sourceMap == null) + { + throw new ArgumentNullException(nameof(sourceMap)); + } + string methodName = null; - if (wrappingFunction?.Bindings != null && wrappingFunction.Bindings.Count > 0) + if (wrappingFunction.Bindings != null && wrappingFunction.Bindings.Count > 0) { if (wrappingFunction.Bindings.Count == 2) { MappingEntry objectProtoypeMappingEntry = - sourceMap?.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings[0].SourcePosition); + sourceMap.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings[0].SourcePosition); methodName = objectProtoypeMappingEntry?.OriginalName; } MappingEntry mappingEntry = - sourceMap?.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings.Last().SourcePosition); + sourceMap.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings.Last().SourcePosition); - if (mappingEntry != null) + if (mappingEntry?.OriginalName != null) { - if (mappingEntry.OriginalName != null) + if (methodName != null) { - if (methodName != null) - { - methodName = methodName + "." + mappingEntry.OriginalName; - } - else - { - methodName = mappingEntry.OriginalName; - } + methodName = methodName + "." + mappingEntry.OriginalName; + } + else + { + methodName = mappingEntry.OriginalName; } } } diff --git a/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs b/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs index 9cf3b6f..97a48eb 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs @@ -5,7 +5,7 @@ /// /// This method will deminify a single stack from from a minified stack trace. /// - /// Returns a stack trace that has been translated to the original source code. Returns null if it could not be deminified. - StackFrame DeminifyStackFrame(StackFrame stackFrame); + /// Returns a StackFrameDeminificationResult that contains a stack trace that has been translated to the original source code. The DeminificationError Property indicates if the StackFrame could not be deminified. DeminifiedStackFrame will not be null, but any properties of DeminifiedStackFrame could be null if the value could not be extracted. + StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame); } } \ No newline at end of file diff --git a/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs b/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs index 0f2ffc0..79a5b27 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs @@ -19,8 +19,12 @@ namespace SourcemapToolkit.CallstackDeminifier /// /// This method will deminify the method name of a single stack from from a minified stack trace. /// - public virtual StackFrame DeminifyStackFrame(StackFrame stackFrame) + public virtual StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame) { + StackFrameDeminificationResult result = new StackFrameDeminificationResult + { + DeminificationError = DeminificationError.None + }; if (stackFrame == null) { throw new ArgumentNullException(nameof(stackFrame)); @@ -36,9 +40,19 @@ namespace SourcemapToolkit.CallstackDeminifier { wrappingFunction = _functionMapConsumer.GetWrappingFunctionForSourceLocation(stackFrame.SourcePosition, functionMap); + + if (wrappingFunction == null) + { + result.DeminificationError = DeminificationError.NoWrapingFunctionFound; + } + } + else + { + result.DeminificationError = DeminificationError.NoSourceCodeProvided; } - return new StackFrame {MethodName = wrappingFunction?.DeminfifiedMethodName}; + result.DeminifiedStackFrame = new StackFrame {MethodName = wrappingFunction?.DeminfifiedMethodName}; + return result; } } } \ No newline at end of file diff --git a/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj b/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj index d6cbb69..1ae1ab8 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj +++ b/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj @@ -51,6 +51,7 @@ + @@ -74,15 +75,15 @@ - - - {69FD1EB5-32F2-4759-9187-9A8E25927BCA} SourcemapToolkit.SourcemapParser + + +