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

rokucommunity / brs / #213

27 Jan 2025 05:30PM UTC coverage: 86.996% (-2.2%) from 89.205%
#213

push

web-flow
Implemented several improvements to SceneGraph (#87)

* Implemented several improvements to SceneGraph

* Fixed most test cases

* Reduced unnecessary code

* Fixed typo

* Added Warning when trying to create a non-existent Node

* Fixed parser

* Fixed unit tests

* Implemented support for `infoFields`

* Prettier fix

* Simplified execute callback code and matched behavior with Roku

* Adding comment to clarify the exception

2240 of 2807 branches covered (79.8%)

Branch coverage included in aggregate %.

139 of 304 new or added lines in 18 files covered. (45.72%)

2 existing lines in 1 file now uncovered.

6129 of 6813 relevant lines covered (89.96%)

27562.41 hits per line

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

87.88
/src/brsTypes/components/BrsObjects.ts
1
import { RoAssociativeArray } from "./RoAssociativeArray";
143✔
2
import { RoDeviceInfo } from "./RoDeviceInfo";
143✔
3
import { RoArray } from "./RoArray";
143✔
4
import { RoList } from "./RoList";
143✔
5
import { RoByteArray } from "./RoByteArray";
143✔
6
import { RoDateTime } from "./RoDateTime";
143✔
7
import { RoTimespan } from "./RoTimespan";
143✔
8
import { createNodeByType } from "./RoSGNode";
143✔
9
import { roSGScreen } from "./RoSGScreen";
143✔
10
import { RoMessagePort } from "./RoMessagePort";
143✔
11
import { RoRegex } from "./RoRegex";
143✔
12
import { RoXMLElement } from "./RoXMLElement";
143✔
13
import { BrsString, BrsBoolean } from "../BrsType";
14
import { RoString } from "./RoString";
143✔
15
import { roBoolean } from "./RoBoolean";
143✔
16
import { roDouble } from "./RoDouble";
143✔
17
import { roFloat } from "./RoFloat";
143✔
18
import { roInt } from "./RoInt";
143✔
19
import { roLongInteger } from "./RoLongInteger";
143✔
20
import { Double } from "../Double";
21
import { Float } from "../Float";
22
import { Int32 } from "../Int32";
23
import { Int64 } from "../Int64";
24
import { Interpreter } from "../../interpreter";
25
import { RoInvalid } from "./RoInvalid";
143✔
26
import { BrsComponent } from "./BrsComponent";
27
import { RoAppInfo } from "./RoAppInfo";
143✔
28
import { RoPath } from "./RoPath";
143✔
29

30
// Class to define a case-insensitive map of BrightScript objects.
31
class BrsObjectsMap {
32
    private readonly map = new Map<
143✔
33
        string,
34
        { originalKey: string; value: Function; params: number }
35
    >();
36

37
    constructor(entries: [string, Function, number?][]) {
38
        entries.forEach(([key, value, params]) => this.set(key, value, params));
3,003✔
39
    }
40

41
    get(key: string) {
42
        const entry = this.map.get(key.toLowerCase());
149✔
43
        return entry ? entry.value : undefined;
149✔
44
    }
45

46
    set(key: string, value: Function, params?: number) {
47
        return this.map.set(key.toLowerCase(), {
3,005✔
48
            originalKey: key,
49
            value: value,
50
            params: params ?? 0,
9,015✔
51
        });
52
    }
53

54
    has(key: string) {
55
        return this.map.has(key.toLowerCase());
×
56
    }
57

58
    delete(key: string) {
59
        return this.map.delete(key.toLowerCase());
×
60
    }
61

62
    clear() {
63
        return this.map.clear();
×
64
    }
65

66
    values() {
67
        return Array.from(this.map.values()).map((entry) => entry.value);
×
68
    }
69

70
    keys() {
71
        return Array.from(this.map.values()).map((entry) => entry.originalKey);
×
72
    }
73

74
    // Returns the number of parameters required by the object constructor.
75
    // >=0 = exact number of parameters required
76
    // -1  = ignore parameters, create object with no parameters
77
    // -2  = do not check for minimum number of parameters
78
    params(key: string) {
79
        const entry = this.map.get(key.toLowerCase());
146✔
80
        return entry ? entry.params : -1;
146!
81
    }
82
}
83

84
/** Map containing a list of BrightScript components that can be created. */
85
export const BrsObjects = new BrsObjectsMap([
143✔
86
    ["roAssociativeArray", (_: Interpreter) => new RoAssociativeArray([])],
5✔
87
    [
88
        "roArray",
89
        (interpreter: Interpreter, capacity: Int32 | Float, resizable: BrsBoolean) =>
90
            new RoArray(capacity, resizable),
2✔
91
        2,
92
    ],
93
    ["roList", (_: Interpreter) => new RoList([])],
1✔
94
    ["roByteArray", (_: Interpreter) => new RoByteArray()],
9✔
95
    ["roDateTime", (_: Interpreter) => new RoDateTime()],
1✔
96
    ["roTimespan", (_: Interpreter) => new RoTimespan()],
1✔
97
    ["roDeviceInfo", (_: Interpreter) => new RoDeviceInfo()],
4✔
98
    [
99
        "roSGNode",
100
        (interpreter: Interpreter, nodeType: BrsString) => createNodeByType(interpreter, nodeType),
89✔
101
        1,
102
    ],
NEW
103
    ["roSGScreen", (interpreter: Interpreter) => new roSGScreen(interpreter)],
×
NEW
104
    ["roMessagePort", (_: Interpreter) => new RoMessagePort()],
×
105
    [
106
        "roRegex",
107
        (_: Interpreter, expression: BrsString, flags: BrsString) => new RoRegex(expression, flags),
5✔
108
        2,
109
    ],
110
    ["roXMLElement", (_: Interpreter) => new RoXMLElement()],
1✔
111
    ["roString", (_: Interpreter) => new RoString(), -1],
3✔
112
    ["roBoolean", (_: Interpreter, literal: BrsBoolean) => new roBoolean(literal), -1],
4✔
113
    ["roDouble", (_: Interpreter, literal: Double) => new roDouble(literal), -1],
3✔
114
    ["roFloat", (_: Interpreter, literal: Float) => new roFloat(literal), -1],
4✔
115
    ["roInt", (_: Interpreter, literal: Int32) => new roInt(literal), -1],
3✔
116
    ["roLongInteger", (_: Interpreter, literal: Int64) => new roLongInteger(literal), -1],
3✔
117
    ["roAppInfo", (_: Interpreter) => new RoAppInfo()],
1✔
118
    ["roPath", (_: Interpreter, path: BrsString) => new RoPath(path), 1],
1✔
119
    ["roInvalid", (_: Interpreter) => new RoInvalid(), -1],
3✔
120
]);
121

122
/**
123
 * Lets another software using BRS as a library to add/overwrite an implementation of a BrsObject.
124
 *
125
 * This is useful, for example, if another piece of software wanted to implement video playback or Draw2d functionality.
126
 *
127
 * In each element of the objectList param, it is pair:
128
 * [name of the BrsObject (e.g. "roScreen", etc.), function (interpreter, ...additionalArgs) that returns a new object]
129
 *
130
 * @example
131
 *
132
 * extendBrsObjects([
133
 *   ["roScreen", (_interpreter) => {return new roScreen();}]
134
 * ])
135
 *
136
 * @param objectList array of pairs: [name, constructor function]
137
 */
138
export function extendBrsObjects(objectList: [string, () => BrsComponent][]): void {
143✔
139
    objectList.forEach(([name, ctor]) => {
2✔
140
        BrsObjects.set(name.toLowerCase(), ctor);
2✔
141
    });
142
}
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