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

source-academy / js-slang / 23995741899

05 Apr 2026 06:14AM UTC coverage: 77.093% (+0.002%) from 77.091%
23995741899

push

github

web-flow
Upgrade to TypeScript 6 and Prettier improvements (#1936)

* Upgrade TypeScript to v6

* Fix import source

* Fix tsconfig

* Fix preexisting type errors

* Remove scm-slang

* Bump node types

* Fix tsconfig

* Fix node types specifier

* Enable trailing commas

* Enable semicolons

* Check and commit files with changed line numbers

* Update Yarn to 4.13.0

* Remove unneeded sicp package deps

3112 of 4282 branches covered (72.68%)

Branch coverage included in aggregate %.

3761 of 5218 new or added lines in 152 files covered. (72.08%)

26 existing lines in 9 files now uncovered.

7136 of 9011 relevant lines covered (79.19%)

175254.05 hits per line

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

93.65
/src/utils/buffer.ts
1
declare global {
2
  interface ArrayBufferConstructor {
3
    transfer(source: ArrayBuffer, length: number): ArrayBuffer;
4
  }
5
}
6

7
if (!ArrayBuffer.transfer) {
55!
8
  ArrayBuffer.transfer = (source, length) => {
55✔
9
    if (!(source instanceof ArrayBuffer))
11!
NEW
10
      throw new TypeError('Source must be an instance of ArrayBuffer');
×
11
    if (length <= source.byteLength) return source.slice(0, length);
11!
12
    const sourceView = new Uint8Array(source);
11✔
13
    const destView = new Uint8Array(new ArrayBuffer(length));
11✔
14
    destView.set(sourceView);
11✔
15
    return destView.buffer;
11✔
16
  };
17
}
18

19
/**
20
 * A little-endian byte buffer class.
21
 */
22
export default class Buffer {
23
  private _capacity: number;
24
  public cursor: number;
25
  private _written: number;
26
  private _buffer: ArrayBuffer;
27
  private _view: DataView;
28

29
  constructor() {
30
    this._capacity = 32;
29✔
31
    this.cursor = 0;
29✔
32
    this._written = 0;
29✔
33
    this._buffer = new ArrayBuffer(this._capacity);
29✔
34
    this._view = new DataView(this._buffer);
29✔
35
  }
36

37
  private maybeExpand(n: number) {
38
    if (this.cursor + n < this._capacity) {
351✔
39
      return;
340✔
40
    }
41

42
    while (this.cursor + n >= this._capacity) {
11✔
43
      this._capacity *= 2;
16✔
44
    }
45
    this._buffer = ArrayBuffer.transfer(this._buffer, this._capacity);
11✔
46
    this._view = new DataView(this._buffer);
11✔
47
  }
48

49
  private updateWritten() {
50
    this._written = Math.max(this._written, this.cursor);
351✔
51
  }
52

53
  get(signed: boolean, s: 8 | 16 | 32): number {
54
    const r = this._view[`get${signed ? 'I' : 'Ui'}nt${s}`](this.cursor, true);
6✔
55
    this.cursor += s / 8;
6✔
56
    return r;
6✔
57
  }
58

59
  getI(s: 8 | 16 | 32): number {
60
    return this.get(true, s);
3✔
61
  }
62

63
  getU(s: 8 | 16 | 32): number {
64
    return this.get(false, s);
3✔
65
  }
66

67
  getF(s: 32 | 64): number {
68
    const r = this._view[`getFloat${s}`](this.cursor, true);
2✔
69
    this.cursor += s / 8;
2✔
70
    return r;
2✔
71
  }
72

73
  put(n: number, signed: boolean, s: 8 | 16 | 32) {
74
    this.maybeExpand(s / 8);
328✔
75
    this._view[`set${signed ? 'I' : 'Ui'}nt${s}`](this.cursor, n, true);
328✔
76
    this.cursor += s / 8;
328✔
77
    this.updateWritten();
328✔
78
  }
79

80
  putI(s: 8 | 16 | 32, n: number) {
81
    this.put(n, true, s);
47✔
82
  }
83

84
  putU(s: 8 | 16 | 32, n: number) {
85
    this.put(n, false, s);
281✔
86
  }
87

88
  putF(s: 32 | 64, n: number) {
89
    this.maybeExpand(s / 8);
7✔
90
    this._view[`setFloat${s}`](this.cursor, n, true);
7✔
91
    this.cursor += s / 8;
7✔
92
    this.updateWritten();
7✔
93
  }
94

95
  putA(a: Uint8Array) {
96
    this.maybeExpand(a.byteLength);
16✔
97
    new Uint8Array(this._buffer, this.cursor, a.byteLength).set(a);
16✔
98
    this.cursor += a.byteLength;
16✔
99
    this.updateWritten();
16✔
100
  }
101

102
  align(n: number) {
103
    const rem = this.cursor % n;
12✔
104
    if (rem === 0) {
12✔
105
      return;
7✔
106
    }
107
    this.cursor += n - rem;
5✔
108
  }
109

110
  asArray(): Uint8Array {
111
    return new Uint8Array(this._buffer.slice(0, this._written));
24✔
112
  }
113

114
  get written(): number {
115
    return this._written;
1✔
116
  }
117
}
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