MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / IndexReference

Class IndexReference

src/interpreter/reference.ts:53–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53class IndexReference implements Reference {
54 constructor(private target: Value[], private index: number) {
55 this.type = 'reference';
56 }
57
58 type: 'reference';
59
60 get(): Value {
61 this.assertIndexInRange();
62 return this.target[this.index]!;
63 }
64
65 set(value: Value): void {
66 this.assertIndexInRange();
67 this.target[this.index] = value;
68 }
69
70 private assertIndexInRange(): void {
71 const index = this.index;
72 if (index < 0 || this.target.length <= index) {
73 throw new AiScriptIndexOutOfRangeError(`Index out of range. index: ${this.index} max: ${this.target.length - 1}`);
74 }
75 }
76}
77
78class PropReference implements Reference {
79 constructor(private target: Map<string, Value>, private index: string) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected