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

visgl / luma.gl / 23357510199

20 Mar 2026 06:40PM UTC coverage: 58.158% (+5.9%) from 52.213%
23357510199

push

github

web-flow
chore: Run tests on src instead of dist (#2555)

3021 of 6029 branches covered (50.11%)

Branch coverage included in aggregate %.

7102 of 11377 relevant lines covered (62.42%)

243.33 hits per line

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

90.0
/modules/test-utils/src/null-device/resources/null-buffer.ts
1
// luma.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import {Buffer, type BufferProps, type BufferMapCallback} from '@luma.gl/core';
6
import {type NullDevice} from '../null-device';
7

8
export class NullBuffer extends Buffer {
9
  device: NullDevice;
10
  readonly handle: 'null' | null = 'null';
13✔
11

12
  byteLength: number;
13
  private _storage: ArrayBuffer;
14

15
  constructor(device: NullDevice, props: BufferProps = {}) {
13✔
16
    super(device, props);
13✔
17
    this.device = device;
13✔
18

19
    const byteOffset = props.byteOffset || 0;
13✔
20
    const byteLength = props.byteLength ?? (props.data ? props.data.byteLength + byteOffset : 0);
13✔
21

22
    this.byteLength = byteLength;
13✔
23
    this._storage = new ArrayBuffer(byteLength);
13✔
24

25
    // If initial data is provided, copy it in
26
    if (props.data) {
13✔
27
      this.write(props.data, byteOffset);
7✔
28
    }
29

30
    this.trackAllocatedMemory(byteLength);
13✔
31
  }
32

33
  override destroy(): void {
34
    if (!this.destroyed) {
12✔
35
      super.destroy();
11✔
36
      this.trackDeallocatedMemory();
11✔
37
      // @ts-expect-error
38
      this.handle = null;
11✔
39
      // Clear internal storage
40
      this._storage = new ArrayBuffer(0);
11✔
41
    }
42
  }
43

44
  write(data: ArrayBufferLike | ArrayBufferView, byteOffset: number = 0): void {
8✔
45
    const source = ArrayBuffer.isView(data)
8!
46
      ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
47
      : new Uint8Array(data);
48
    const target = new Uint8Array(this._storage, byteOffset, source.byteLength);
8✔
49

50
    if (byteOffset + source.byteLength > this.byteLength) {
8!
51
      throw new RangeError(`NullBuffer.write(): write would overflow buffer`);
×
52
    }
53

54
    target.set(source);
8✔
55
    this._setDebugData(data, byteOffset, source.byteLength);
8✔
56
  }
57

58
  async mapAndWriteAsync(
59
    callback: BufferMapCallback<void>,
60
    byteOffset = 0,
2✔
61
    byteLength = this.byteLength - byteOffset
2✔
62
  ): Promise<void> {
63
    const view = new Uint8Array(this._storage, byteOffset, byteLength);
2✔
64
    const tempBuffer = new Uint8Array(view.length); // safe scratch copy
2✔
65
    callback(tempBuffer.buffer, 'copied');
2✔
66
    view.set(tempBuffer);
2✔
67
    this._setDebugData(view, byteOffset, byteLength);
2✔
68
  }
69

70
  async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {
12✔
71
    byteLength = byteLength ?? this.byteLength - byteOffset;
12✔
72

73
    if (byteOffset + byteLength > this.byteLength) {
12!
74
      throw new RangeError(`NullBuffer.readAsync(): read would overflow buffer`);
×
75
    }
76

77
    const view = new Uint8Array(this._storage, byteOffset, byteLength);
12✔
78
    return new Uint8Array(view); // return a copy
12✔
79
  }
80

81
  async mapAndReadAsync<T>(
82
    callback: BufferMapCallback<T>,
83
    byteOffset = 0,
2✔
84
    byteLength = this.byteLength - byteOffset
2✔
85
  ): Promise<T> {
86
    const view = new Uint8Array(this._storage, byteOffset, byteLength);
2✔
87
    const copy = new Uint8Array(view); // copy to protect memory
2✔
88
    return callback(copy.buffer, 'copied');
2✔
89
  }
90

91
  readSyncWebGL(): Uint8Array {
92
    throw new Error('NullBuffer.readSyncWebGL() not implemented');
×
93
  }
94
}
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