diff options
Diffstat (limited to 'devtools/client/debugger/src/utils/breakpoint/astBreakpointLocation.js')
-rw-r--r-- | devtools/client/debugger/src/utils/breakpoint/astBreakpointLocation.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/utils/breakpoint/astBreakpointLocation.js b/devtools/client/debugger/src/utils/breakpoint/astBreakpointLocation.js new file mode 100644 index 0000000000..6915ef74cc --- /dev/null +++ b/devtools/client/debugger/src/utils/breakpoint/astBreakpointLocation.js @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +// @flow + +import { findClosestFunction } from "../ast"; + +import type { SourceLocation, Source, ASTLocation } from "../../types"; +import type { Symbols } from "../../reducers/ast"; + +export function getASTLocation( + source: Source, + symbols: ?Symbols, + location: SourceLocation +): ASTLocation { + if (source.isWasm || !symbols || symbols.loading) { + return { name: undefined, offset: location, index: 0 }; + } + + const scope = findClosestFunction(symbols, location); + if (scope) { + // we only record the line, but at some point we may + // also do column offsets + const line = location.line - scope.location.start.line; + return { + name: scope.name, + offset: { line, column: undefined }, + index: scope.index, + }; + } + return { name: undefined, offset: location, index: 0 }; +} + +export function findFunctionByName( + symbols: Symbols, + name: ?string, + index: number +) { + if (symbols.loading) { + return null; + } + + return symbols.functions.find( + node => node.name === name && node.index === index + ); +} |