Exemplo n.º 1
0
        public void ApplyMap_PartialMatchingSources_ReturnsCorrectMap()
        {
            // Expect mappings with same source filename as the applied source-map to be replaced
            // mappings with a different source filename should stay the same

            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 10);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 5);
            MappingEntry   childMapping = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 2);
            SourcePosition original2  = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 10);
            MappingEntry   mapping    = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourcePosition generated3 = UnitTestUtils.generateSourcePosition(lineNumber: 4, colNumber: 3);
            SourcePosition original3  = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 2);
            MappingEntry   mapping2   = UnitTestUtils.getSimpleEntry(generated3, original3, "noMapForThis.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js", "noMapForThis.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapping, mapping2
                }
            };

            // Act
            SourceMap combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            Assert.AreEqual(2, combinedMap.ParsedMappings.Count);
            Assert.AreEqual(2, combinedMap.Sources.Count);
            MappingEntry firstCombinedMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated3);

            Assert.IsTrue(firstCombinedMapping.IsValueEqual(mapping2));
            MappingEntry secondCombinedMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated2);

            Assert.AreEqual(0, secondCombinedMapping.OriginalSourcePosition.CompareTo(childMapping.OriginalSourcePosition));
        }
        /// <summary>
        /// Gets the original name corresponding to a function based on the information provided in the source map.
        /// </summary>
        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)
            {
                MappingEntry objectProtoypeMappingEntry = null;
                if (wrappingFunction.Bindings.Count == 2)
                {
                    objectProtoypeMappingEntry =
                        sourceMap.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings[0].SourcePosition);
                }

                MappingEntry mappingEntry =
                    sourceMap.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings.Last().SourcePosition);

                if (mappingEntry?.OriginalName != null)
                {
                    if (objectProtoypeMappingEntry?.OriginalName != null)
                    {
                        string objectName = objectProtoypeMappingEntry.OriginalName;
                        if (objectProtoypeMappingEntry.OriginalSourcePosition?.ZeroBasedColumnNumber == mappingEntry.OriginalSourcePosition?.ZeroBasedColumnNumber &&
                            objectProtoypeMappingEntry.OriginalSourcePosition?.ZeroBasedLineNumber == mappingEntry.OriginalSourcePosition?.ZeroBasedLineNumber &&
                            objectName.EndsWith($".{mappingEntry.OriginalName}"))
                        {
                            // The object name already contains the method name, so do not append it
                            methodName = objectName;
                        }
                        else
                        {
                            methodName = $"{objectName}.{mappingEntry.OriginalName}";
                        }
                    }
                    else
                    {
                        methodName = mappingEntry.OriginalName;
                    }
                }
            }
            return(methodName);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the original name corresponding to a function based on the information provided in the source map.
        /// </summary>
        internal static string GetDeminifiedMethodName(this SourceMap sourceMap, IReadOnlyList <BindingInformation> bindings)
        {
            if (sourceMap == null)
            {
                throw new ArgumentNullException(nameof(sourceMap));
            }

            string methodName = null;

            if (bindings != null && bindings.Count > 0)
            {
                MappingEntry?objectProtoypeMappingEntry = null;
                if (bindings.Count == 2)
                {
                    objectProtoypeMappingEntry =
                        sourceMap.GetMappingEntryForGeneratedSourcePosition(bindings[0].SourcePosition);
                }

                MappingEntry?mappingEntry =
                    sourceMap.GetMappingEntryForGeneratedSourcePosition(bindings.Last().SourcePosition);

                if (mappingEntry?.OriginalName != null)
                {
                    if (objectProtoypeMappingEntry?.OriginalName != null)
                    {
                        string objectName = objectProtoypeMappingEntry.Value.OriginalName;
                        if (objectProtoypeMappingEntry.Value.OriginalSourcePosition.ZeroBasedColumnNumber == mappingEntry.Value.OriginalSourcePosition.ZeroBasedColumnNumber &&
                            objectProtoypeMappingEntry.Value.OriginalSourcePosition.ZeroBasedLineNumber == mappingEntry.Value.OriginalSourcePosition.ZeroBasedLineNumber &&
                            objectName.Length > mappingEntry.Value.OriginalName.Length &&
                            objectName.EndsWith(mappingEntry.Value.OriginalName) &&
                            (objectName[objectName.Length - 1 - mappingEntry.Value.OriginalName.Length] == '.'))
                        {
                            // The object name already contains the method name, so do not append it
                            methodName = objectName;
                        }
                        else
                        {
                            methodName = $"{objectName}.{mappingEntry.Value.OriginalName}";
                        }
                    }
                    else
                    {
                        methodName = mappingEntry.Value.OriginalName;
                    }
                }
            }
            return(methodName);
        }
Exemplo n.º 4
0
        public void ApplyMap_ExactMatchDeep_ReturnsCorrectMappingEntry()
        {
            // Arrange
            SourcePosition generated1 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            SourcePosition original1  = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 10);
            MappingEntry   mapLevel2  = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceThree.js");

            SourceMap grandChildMap = new SourceMap
            {
                File    = "sourceTwo.js",
                Sources = new List <string> {
                    "sourceThree.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel2
                }
            };

            SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 4, colNumber: 3);
            SourcePosition original2  = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            MappingEntry   mapLevel1  = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel1
                }
            };

            SourcePosition generated3 = UnitTestUtils.generateSourcePosition(lineNumber: 5, colNumber: 5);
            SourcePosition original3  = UnitTestUtils.generateSourcePosition(lineNumber: 4, colNumber: 3);
            MappingEntry   mapLevel0  = UnitTestUtils.getSimpleEntry(generated3, original3, "sourceOne.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel0
                }
            };

            // Act
            SourceMap firstCombinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(firstCombinedMap);
            SourceMap secondCombinedMap = firstCombinedMap.ApplySourceMap(grandChildMap);

            Assert.IsNotNull(secondCombinedMap);
            MappingEntry rootMapping = secondCombinedMap.GetMappingEntryForGeneratedSourcePosition(generated3);

            Assert.AreEqual(0, rootMapping.OriginalSourcePosition.CompareTo(mapLevel2.OriginalSourcePosition));
        }
Exemplo n.º 5
0
        public void GetMappingEntryForGeneratedSourcePosition_MatchingEntryInMappingList_ReturnMatchingEntry()
        {
            // Arrange
            SourceMap    sourceMap            = new SourceMap();
            MappingEntry matchingMappingEntry = new MappingEntry
            {
                GeneratedSourcePosition = new SourcePosition {
                    ZeroBasedLineNumber = 8, ZeroBasedColumnNumber = 13
                }
            };

            sourceMap.ParsedMappings = new List <MappingEntry>
            {
                new MappingEntry
                {
                    GeneratedSourcePosition = new SourcePosition {
                        ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0
                    }
                },
                matchingMappingEntry
            };
            SourcePosition sourcePosition = new SourcePosition {
                ZeroBasedLineNumber = 8, ZeroBasedColumnNumber = 13
            };

            // Act
            MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.Equal(matchingMappingEntry, result);
        }
Exemplo n.º 6
0
        public void GetMappingEntryForGeneratedSourcePosition_MatchingEntryInMappingList_ReturnMatchingEntry()
        {
            // Arrange
            var sourceMap            = new SourceMap();
            var matchingMappingEntry = new MappingEntry
            {
                GeneratedSourcePosition = new SourcePosition(8, 13)
            };

            sourceMap.ParsedMappings = new List <MappingEntry>
            {
                new MappingEntry
                {
                    GeneratedSourcePosition = new SourcePosition(0, 0)
                },
                matchingMappingEntry
            };
            var sourcePosition = new SourcePosition(8, 13);

            // Act
            var result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.AreEqual(matchingMappingEntry, result);
        }
Exemplo n.º 7
0
        public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnSameLine_ReturnSimilarEntry()
        {
            // Arrange
            SourceMap    sourceMap            = new SourceMap();
            MappingEntry matchingMappingEntry = new MappingEntry
            {
                GeneratedSourcePosition = new SourcePosition {
                    ZeroBasedLineNumber = 10, ZeroBasedColumnNumber = 13
                }
            };

            sourceMap.ParsedMappings = new List <MappingEntry>
            {
                new MappingEntry
                {
                    GeneratedSourcePosition = new SourcePosition {
                        ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0
                    }
                },
                matchingMappingEntry
            };
            SourcePosition sourcePosition = new SourcePosition {
                ZeroBasedLineNumber = 10, ZeroBasedColumnNumber = 14
            };

            // Act
            MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.AreEqual(matchingMappingEntry, result);
        }
Exemplo n.º 8
0
        public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnSameLine_ReturnSimilarEntry()
        {
            // Arrange
            var sourceMap            = new SourceMap();
            var matchingMappingEntry = new MappingEntry
            {
                GeneratedSourcePosition = new SourcePosition(10, 13)
            };

            sourceMap.ParsedMappings = new List <MappingEntry>
            {
                new MappingEntry
                {
                    GeneratedSourcePosition = new SourcePosition(0, 0)
                },
                matchingMappingEntry
            };
            var sourcePosition = new SourcePosition(10, 14);

            // Act
            var result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.AreEqual(matchingMappingEntry, result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// This method will deminify a single stack from from a minified stack trace.
        /// </summary>
        /// <returns>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. </returns>
        public StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame, string callerSymbolName)
        {
            if (stackFrame == null)
            {
                throw new ArgumentNullException(nameof(stackFrame));
            }

            SourceMap      sourceMap = _sourceMapStore.GetSourceMapForUrl(stackFrame.FilePath);
            SourcePosition generatedSourcePosition = stackFrame.SourcePosition;

            StackFrameDeminificationResult result = null;

            if (_methodNameDeminifier != null)
            {
                result = _methodNameDeminifier.DeminifyStackFrame(stackFrame, callerSymbolName);
            }

            if (result == null || result.DeminificationError == DeminificationError.NoSourceCodeProvided)
            {
                result = new StackFrameDeminificationResult
                {
                    DeminificationError  = DeminificationError.None,
                    DeminifiedStackFrame = new StackFrame {
                        MethodName = callerSymbolName
                    }
                };
            }

            if (result.DeminificationError == DeminificationError.None)
            {
                MappingEntry?generatedSourcePositionMappingEntry =
                    sourceMap?.GetMappingEntryForGeneratedSourcePosition(generatedSourcePosition);

                if (generatedSourcePositionMappingEntry == null)
                {
                    if (sourceMap == null)
                    {
                        result.DeminificationError = DeminificationError.NoSourceMap;
                    }
                    else if (sourceMap.ParsedMappings == null)
                    {
                        result.DeminificationError = DeminificationError.SourceMapFailedToParse;
                    }
                    else
                    {
                        result.DeminificationError = DeminificationError.NoMatchingMapingInSourceMap;
                    }
                }
                else
                {
                    result.DeminifiedStackFrame.FilePath       = generatedSourcePositionMappingEntry.Value.OriginalFileName;
                    result.DeminifiedStackFrame.SourcePosition = generatedSourcePositionMappingEntry.Value.OriginalSourcePosition;
                    result.DeminifiedSymbolName = generatedSourcePositionMappingEntry.Value.OriginalName;
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the original name corresponding to a function based on the information provided in the source map.
        /// </summary>
        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.Count == 2)
                {
                    MappingEntry objectProtoypeMappingEntry =
                        sourceMap.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings[0].SourcePosition);

                    methodName = objectProtoypeMappingEntry?.OriginalName;
                }

                MappingEntry mappingEntry =
                    sourceMap.GetMappingEntryForGeneratedSourcePosition(wrappingFunction.Bindings.Last().SourcePosition);

                if (mappingEntry?.OriginalName != null)
                {
                    if (methodName != null)
                    {
                        methodName = methodName + "." + mappingEntry.OriginalName;
                    }
                    else
                    {
                        methodName = mappingEntry.OriginalName;
                    }
                }
            }
            return(methodName);
        }
Exemplo n.º 11
0
        public void GetMappingEntryForGeneratedSourcePosition_NullMappingList_ReturnNull()
        {
            // Arrange
            SourceMap      sourceMap      = CreateSourceMap();
            SourcePosition sourcePosition = new SourcePosition(zeroBasedLineNumber: 4, zeroBasedColumnNumber: 3);

            // Act
            MappingEntry?result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.Null(result);
        }
Exemplo n.º 12
0
        public void GetMappingEntryForGeneratedSourcePosition_NullMappingList_ReturnNull()
        {
            // Arrange
            var sourceMap      = new SourceMap();
            var sourcePosition = new SourcePosition(4, 3);

            // Act
            var result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.IsNull(result);
        }
Exemplo n.º 13
0
        public void GetMappingEntryForGeneratedSourcePosition_NullMappingList_ReturnNull()
        {
            // Arrange
            SourceMap      sourceMap      = new SourceMap();
            SourcePosition sourcePosition = new SourcePosition {
                ZeroBasedColumnNumber = 3, ZeroBasedLineNumber = 4
            };

            // Act
            MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.IsNull(result);
        }
Exemplo n.º 14
0
        protected override async Task HandleReport(StacktraceReport report)
        {
            foreach (var stackFrame in report.Stack.Where(x => !string.IsNullOrEmpty(x.FileName)))
            {
                SourceMap sourceMap = null;
                var       url       = stackFrame.FileName;
                try
                {
                    var uri = new Uri(url);
                    if (!uri.Scheme.Equals("http", StringComparison.InvariantCultureIgnoreCase) && !uri.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    if (!setings.IsAllowedDomain(uri.Host))
                    {
                        log.Error($"{url} doesn't contain allowed domain");
                        continue;
                    }
                    if (!setings.IsAllowedDomainForSourceMap(uri.Host))
                    {
                        log.Debug($"{url} domain doesn't support sourcemaps");
                        continue;
                    }

                    if (!cache.Get(url, out sourceMap))
                    {
                        sourceMap = await GetMapFromUrl(url);

                        cache.Set(url, sourceMap, expirationTimeSpan);
                    }
                }
                catch (Exception e)
                {
                    log.Error($"failed to get sourcemap from url: {url}", e);
                }
                var mappingEntry = sourceMap?.GetMappingEntryForGeneratedSourcePosition(
                    new SourcePosition {
                    ZeroBasedLineNumber = stackFrame.LineNumber - 1, ZeroBasedColumnNumber = stackFrame.ColumnNumber - 1
                });
                if (mappingEntry != null)
                {
                    stackFrame.LineNumber   = mappingEntry.OriginalSourcePosition.ZeroBasedLineNumber + 1;
                    stackFrame.ColumnNumber = mappingEntry.OriginalSourcePosition.ZeroBasedColumnNumber + 1;
                    stackFrame.FileName     = mappingEntry.OriginalFileName;
                    stackFrame.FunctionName = mappingEntry.OriginalName;
                    log.Debug("report before patching:\n" + report.ToPrettyJson());
                }
            }
        }
Exemplo n.º 15
0
        public void ApplyMap_MatchingSources_ReturnsCorrectMap()
        {
            // Expect mapping with same source filename as the applied source-map to be replaced

            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 4);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 3);
            MappingEntry   childMapping = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            SourcePosition generated2    = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            SourcePosition original2     = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 4);
            MappingEntry   parentMapping = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    parentMapping
                }
            };

            // Act
            SourceMap combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            Assert.AreEqual(1, combinedMap.ParsedMappings.Count);
            Assert.AreEqual(1, combinedMap.Sources.Count);
            MappingEntry rootMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated2);

            Assert.AreEqual(0, rootMapping.OriginalSourcePosition.CompareTo(childMapping.OriginalSourcePosition));
        }
Exemplo n.º 16
0
        public void GetMappingEntryForGeneratedSourcePosition_NoMatchingEntryInMappingList_ReturnNull()
        {
            // Arrange
            List <MappingEntry> parsedMappings = new List <MappingEntry>
            {
                new MappingEntry(
                    generatedSourcePosition: new SourcePosition(zeroBasedLineNumber: 0, zeroBasedColumnNumber: 0))
            };

            SourceMap      sourceMap      = CreateSourceMap(parsedMappings: parsedMappings);
            SourcePosition sourcePosition = new SourcePosition(zeroBasedLineNumber: 4, zeroBasedColumnNumber: 3);

            // Act
            MappingEntry?result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.Null(result);
        }
Exemplo n.º 17
0
        public void GetMappingEntryForGeneratedSourcePosition_NoMatchingEntryInMappingList_ReturnNull()
        {
            // Arrange
            var sourceMap = new SourceMap();

            sourceMap.ParsedMappings = new List <MappingEntry>
            {
                new MappingEntry
                {
                    GeneratedSourcePosition = new SourcePosition(0, 0),
                }
            };
            var sourcePosition = new SourcePosition(4, 3);

            // Act
            var result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.IsNull(result);
        }
Exemplo n.º 18
0
        public void GetMappingEntryForGeneratedSourcePosition_NoExactMatchHasSimilarOnDifferentLinesLine_ReturnSimilarEntry()
        {
            // Arrange
            MappingEntry matchingMappingEntry = new MappingEntry(
                generatedSourcePosition: new SourcePosition(zeroBasedLineNumber: 23, zeroBasedColumnNumber: 15));
            List <MappingEntry> parsedMappings = new List <MappingEntry>
            {
                new MappingEntry(
                    generatedSourcePosition: new SourcePosition(zeroBasedLineNumber: 0, zeroBasedColumnNumber: 0)),
                matchingMappingEntry
            };
            SourceMap      sourceMap      = CreateSourceMap(parsedMappings: parsedMappings);
            SourcePosition sourcePosition = new SourcePosition(zeroBasedLineNumber: 24, zeroBasedColumnNumber: 0);

            // Act
            MappingEntry?result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.Equal(matchingMappingEntry, result);
        }
Exemplo n.º 19
0
        public void GetMappingEntryForGeneratedSourcePosition_MatchingEntryInMappingList_ReturnMatchingEntry()
        {
            // Arrange
            MappingEntry matchingMappingEntry = new MappingEntry(
                generatedSourcePosition: new SourcePosition(zeroBasedLineNumber: 8, zeroBasedColumnNumber: 13));
            List <MappingEntry> parsedMappings = new List <MappingEntry>
            {
                new MappingEntry(
                    generatedSourcePosition: new SourcePosition(zeroBasedLineNumber: 0, zeroBasedColumnNumber: 0)),
                matchingMappingEntry
            };

            SourceMap      sourceMap      = CreateSourceMap(parsedMappings: parsedMappings);
            SourcePosition sourcePosition = new SourcePosition(zeroBasedLineNumber: 8, zeroBasedColumnNumber: 13);

            // Act
            MappingEntry?result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.Equal(matchingMappingEntry, result);
        }
        /// <summary>
        /// This method will deminify a single stack from from a minified stack trace.
        /// </summary>
        /// <returns>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. </returns>
        public override StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame)
        {
            if (stackFrame == null)
            {
                throw new ArgumentNullException(nameof(stackFrame));
            }

            SourceMap      sourceMap = _sourceMapStore.GetSourceMapForUrl(stackFrame.FilePath);
            SourcePosition generatedSourcePosition = stackFrame.SourcePosition;

            StackFrameDeminificationResult result = base.DeminifyStackFrame(stackFrame);

            if (result.DeminificationError == DeminificationError.None)
            {
                MappingEntry generatedSourcePositionMappingEntry =
                    sourceMap?.GetMappingEntryForGeneratedSourcePosition(generatedSourcePosition);

                if (generatedSourcePositionMappingEntry == null)
                {
                    if (sourceMap == null)
                    {
                        result.DeminificationError = DeminificationError.NoSourceMap;
                    }
                    else if (sourceMap.ParsedMappings == null)
                    {
                        result.DeminificationError = DeminificationError.SourceMapFailedToParse;
                    }
                    else
                    {
                        result.DeminificationError = DeminificationError.NoMatchingMapingInSourceMap;
                    }
                }

                result.DeminifiedStackFrame.FilePath       = generatedSourcePositionMappingEntry?.OriginalFileName;
                result.DeminifiedStackFrame.SourcePosition = generatedSourcePositionMappingEntry?.OriginalSourcePosition;
            }

            return(result);
        }
Exemplo n.º 21
0
        public void GetRootMappingEntryForGeneratedSourcePosition_NoChildren_ReturnsSameEntry()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 5);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 5);
            MappingEntry   mappingEntry = UnitTestUtils.getSimpleEntry(generated1, original1, "generated.js");

            SourceMap sourceMap = CreateSourceMap(
                sources: new List <string>()
            {
                "generated.js"
            },
                parsedMappings: new List <MappingEntry> {
                mappingEntry
            });

            // Act
            MappingEntry?rootEntry = sourceMap.GetMappingEntryForGeneratedSourcePosition(generated1);

            // Assert
            Assert.Equal(rootEntry, mappingEntry);
        }
Exemplo n.º 22
0
        public void GetRootMappingEntryForGeneratedSourcePosition_NoChildren_ReturnsSameEntry()
        {
            // Arrange
            var generated1   = UnitTestUtils.GenerateSourcePosition(lineNumber: 2, colNumber: 5);
            var original1    = UnitTestUtils.GenerateSourcePosition(lineNumber: 1, colNumber: 5);
            var mappingEntry = UnitTestUtils.GetSimpleEntry(generated1, original1, "generated.js");

            var sourceMap = new SourceMap
            {
                Sources = new List <string> {
                    "generated.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mappingEntry
                }
            };

            // Act
            var rootEntry = sourceMap.GetMappingEntryForGeneratedSourcePosition(generated1);

            // Assert
            Assert.AreEqual(rootEntry, mappingEntry);
        }
Exemplo n.º 23
0
        public void GetMappingEntryForGeneratedSourcePosition_NoMatchingEntryInMappingList_ReturnNull()
        {
            // Arrange
            SourceMap sourceMap = new SourceMap();

            sourceMap.ParsedMappings = new List <MappingEntry>
            {
                new MappingEntry
                {
                    GeneratedSourcePosition = new SourcePosition {
                        ZeroBasedLineNumber = 0, ZeroBasedColumnNumber = 0
                    }
                }
            };
            SourcePosition sourcePosition = new SourcePosition {
                ZeroBasedColumnNumber = 3, ZeroBasedLineNumber = 4
            };

            // Act
            MappingEntry result = sourceMap.GetMappingEntryForGeneratedSourcePosition(sourcePosition);

            // Asset
            Assert.IsNull(result);
        }