public override void Visit(FunctionObject node)
        {
            base.Visit(node);
            List <BindingInformation> bindings = GetBindings(node);

            if (bindings != null)
            {
                FunctionMapEntry functionMapEntry = new FunctionMapEntry
                {
                    Bindings            = bindings,
                    StartSourcePosition = new SourcePosition
                    {
                        ZeroBasedLineNumber   = node.Body.Context.StartLineNumber - 1,                       // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere.
                        ZeroBasedColumnNumber = node.Body.Context.StartColumn
                    },
                    EndSourcePosition = new SourcePosition
                    {
                        ZeroBasedLineNumber   = node.Body.Context.EndLineNumber - 1,                       // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere.
                        ZeroBasedColumnNumber = node.Body.Context.EndColumn
                    }
                };

                FunctionMap.Add(functionMapEntry);
            }
        }
        /// <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);
        }
Пример #3
0
        public override void Visit(FunctionObject node)
        {
            base.Visit(node);
            var bindings = GetBindings(node);

            if (bindings != null)
            {
                FunctionMapEntry functionMapEntry = new FunctionMapEntry(
                    bindings: bindings,
                    deminifiedMethodName: SourceMap.GetDeminifiedMethodName(bindings),
                    startSourcePosition: new SourcePosition(
                        zeroBasedLineNumber: node.Body.Context.StartLineNumber - 1,                         // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere.
                        zeroBasedColumnNumber: node.Body.Context.StartColumn),
                    endSourcePosition: new SourcePosition(
                        zeroBasedLineNumber: node.Body.Context.EndLineNumber - 1,                         // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere.
                        zeroBasedColumnNumber: node.Body.Context.EndColumn));

                FunctionMap.Add(functionMapEntry);
            }
        }
Пример #4
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);
        }
        /// <summary>
        /// This method will deminify the method name of a single stack from from a minified stack trace.
        /// </summary>
        public virtual StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame, string callerSymbolName)
        {
            StackFrameDeminificationResult result = new StackFrameDeminificationResult
            {
                DeminificationError = DeminificationError.None
            };

            if (stackFrame == null)
            {
                throw new ArgumentNullException(nameof(stackFrame));
            }

            FunctionMapEntry wrappingFunction = null;

            // This code deminifies the stack frame by finding the wrapping function in
            // the generated code and then using the source map to find the name and
            // and original source location.
            List <FunctionMapEntry> functionMap = _functionMapStore.GetFunctionMapForSourceCode(stackFrame.FilePath);

            if (functionMap != null)
            {
                wrappingFunction =
                    _functionMapConsumer.GetWrappingFunctionForSourceLocation(stackFrame.SourcePosition, functionMap);

                if (wrappingFunction == null)
                {
                    result.DeminificationError = DeminificationError.NoWrapingFunctionFound;
                }
            }
            else
            {
                result.DeminificationError = DeminificationError.NoSourceCodeProvided;
            }

            result.DeminifiedStackFrame = new StackFrame {
                MethodName = wrappingFunction?.DeminfifiedMethodName
            };
            return(result);
        }