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

rokucommunity / brs / #305

18 Jan 2024 09:05PM UTC coverage: 91.463% (+5.2%) from 86.214%
#305

push

TwitchBronBron
0.45.4

1796 of 2095 branches covered (85.73%)

Branch coverage included in aggregate %.

5275 of 5636 relevant lines covered (93.59%)

8947.19 hits per line

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

91.3
/src/extensions/GetStackTrace.ts
1
import {
131✔
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";
131✔
13
import { Interpreter } from "../interpreter";
14

15
const INTERNAL_REGEX_FILTER = /\(internal\)/;
131✔
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", {
131✔
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

© 2025 Coveralls, Inc