• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brs / #294

24 Apr 2023 07:40PM UTC coverage: 91.705% (+5.4%) from 86.275%
#294

push

web-flow
Merge pull request #1 from rokucommunity/adoption

refactor in preparation for adoption the project

1736 of 2013 branches covered (86.24%)

Branch coverage included in aggregate %.

5152 of 5498 relevant lines covered (93.71%)

8882.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/src/extensions/GetStackTrace.ts
1
import {
130✔
2
    BrsString,
3
    RoArray,
4
    Callable,
5
    ValueKind,
6
    StdlibArgument,
7
    Int32,
8
    BrsInvalid,
9
    BrsType,
10
    isBrsString,
11
} from "../brsTypes";
12
import { Location } from "../lexer";
130✔
13
import { Interpreter } from "../interpreter";
14

15
const INTERNAL_REGEX_FILTER = /\(internal\)/;
130✔
16

17
/**
18
 * Returns a stack trace in the format:
19
 * [
20
 *   filename:line:column,
21
 *   ...
22
 * ]
23
 */
24
export const GetStackTrace = new Callable("GetStackTrace", {
130✔
25
    signature: {
26
        args: [
27
            new StdlibArgument("numEntries", ValueKind.Int32, new Int32(10)),
28
            new StdlibArgument("excludePatterns", ValueKind.Dynamic, BrsInvalid.Instance),
29
        ],
30
        returns: ValueKind.Object,
31
    },
32
    impl: (interpreter: Interpreter, numEntries: Int32, excludePatterns: BrsType) => {
33
        let stack = interpreter.stack;
8✔
34

35
        // Filter out any files that the consumer doesn't want to include
36
        if (excludePatterns instanceof RoArray) {
8✔
37
            excludePatterns.getValue().forEach((pattern) => {
4✔
38
                if (isBrsString(pattern)) {
5✔
39
                    let regexFilter = new RegExp(pattern.value);
5✔
40
                    stack = stack.filter((location) => !regexFilter.test(location.file));
31✔
41
                }
42
            });
43
        } else if (!(excludePatterns instanceof BrsInvalid)) {
4!
44
            interpreter.stderr.write("Patterns to exclude argument must be an roArray");
×
45
        }
46

47
        return new RoArray(
8✔
48
            stack
49
                // Filter out any internal stack traces.
50
                .filter((location) => !INTERNAL_REGEX_FILTER.test(location.file))
40✔
51
                // Remove any duplicate entries that appear next to each other in the stack.
52
                .filter((location, index, locations) => {
53
                    if (index === 0) return true;
36✔
54
                    let prevLocation = locations[index - 1];
28✔
55
                    return !Location.equalTo(location, prevLocation);
28✔
56
                })
57
                .map(
58
                    (location) =>
59
                        new BrsString(
26✔
60
                            `${location.file}:${location.start.line}:${location.start.column}`
61
                        )
62
                )
63
                // Get the last item on the stack
64
                .slice(-1 * numEntries.getValue())
65
                .reverse()
66
        );
67
    },
68
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc