|
1 | | -/** |
2 | | - * This method returns an `RTrace` object used for reference count tracing. |
3 | | - * |
4 | | - * @param {TraceEventCallback?} onerror - A method that is called when a trace error event occurs. |
5 | | - * @param {TraceEventCallback?} oninfo - A method that is called when a trace info event occurs. |
6 | | - */ |
7 | | -declare function rtrace(onerror?: rtrace.TraceEventCallback, oninfo?: rtrace.TraceEventCallback): rtrace.RTrace; |
| 1 | +/** Creates a new `RTrace` instance, tracking allocations, frees and reference counts. */ |
| 2 | +declare function rtrace( |
| 3 | + /** Function being called when a problem is detected. */ |
| 4 | + onerror?: (error: Error) => void, |
| 5 | + /** Function being called with information messages. */ |
| 6 | + oninfo?: (info: string) => void |
| 7 | +): rtrace.RTrace; |
8 | 8 |
|
9 | 9 | declare namespace rtrace { |
10 | | - /** |
11 | | - * The RTrace interface represents a collection of properties that help develoeprs describe the |
12 | | - * reference counts and state of the Web Assembly module. |
13 | | - */ |
| 10 | + /** The rtrace instance used as the `rtrace` import to the Wasm module. */ |
14 | 11 | export interface RTrace { |
15 | | - |
16 | | - /** |
17 | | - * The current allocation count. |
18 | | - */ |
| 12 | + /** Number of allocations so far. */ |
19 | 13 | allocCount: number; |
20 | | - |
21 | | - /** |
22 | | - * The current free count. |
23 | | - */ |
| 14 | + /** Number of reallocations so far. */ |
| 15 | + reallocCount: number; |
| 16 | + /** Number of frees so far. */ |
24 | 17 | freeCount: number; |
25 | | - |
26 | | - /** |
27 | | - * The current increment count. |
28 | | - */ |
| 18 | + /** Number of RC increments (retains) so far. */ |
29 | 19 | incrementCount: number; |
30 | | - |
31 | | - /** |
32 | | - * The current decrement count. |
33 | | - */ |
| 20 | + /** Number of RC decrements (releases) so far. */ |
34 | 21 | decrementCount: number; |
35 | 22 |
|
36 | | - /** |
37 | | - * This method is called when an allocation occurs. |
38 | | - * |
39 | | - * @param {number} block - The `ptr - 16` value indicating the start of the block. |
40 | | - */ |
41 | | - onalloc(block: number): void; |
42 | | - |
43 | | - /** |
44 | | - * This method is called when a block is freed. |
45 | | - * |
46 | | - * @param {number} block - The `ptr - 16` value indicating the start of the block. |
47 | | - */ |
48 | | - onfree(block: number): void; |
49 | | - |
50 | | - /** |
51 | | - * This method is called when a reference count is incrememnted |
52 | | - * |
53 | | - * @param {number} block - The `ptr - 16` value indicating the start of the block. |
54 | | - */ |
55 | | - onincrement(block: number): void; |
56 | | - |
57 | | - /** |
58 | | - * This method is called when a reference count is decremented. |
59 | | - * |
60 | | - * @param {number} block - The `ptr - 16` value indicating the start of the block. |
61 | | - */ |
62 | | - ondecrement(block: number): void; |
63 | | - |
64 | | - /** |
65 | | - * This property indicates if rtrace is active. |
66 | | - */ |
| 23 | + /** Called when a new block is allocated. */ |
| 24 | + onalloc( |
| 25 | + /** New block being allocated. */ |
| 26 | + block: number |
| 27 | + ): void; |
| 28 | + |
| 29 | + /** Called when a block is reallocated and must be moved. */ |
| 30 | + onrealloc( |
| 31 | + /** Block being moved. */ |
| 32 | + oldBlock: number, |
| 33 | + /** New block used from now on. */ |
| 34 | + newBlock: number |
| 35 | + ): void; |
| 36 | + |
| 37 | + /** Called when a block is freed, implicitly or explicitly. */ |
| 38 | + onfree( |
| 39 | + /** Block being freed. */ |
| 40 | + block: number |
| 41 | + ): void; |
| 42 | + |
| 43 | + /** Called when a reference to a block is retained (RC incremented by one). */ |
| 44 | + onincrement( |
| 45 | + /** Block a reference to is being retained. */ |
| 46 | + block: number |
| 47 | + ): void; |
| 48 | + |
| 49 | + /** Called when a reference to a block is released (RC decremented by one). */ |
| 50 | + ondecrement( |
| 51 | + /** Block a reference to is being released. */ |
| 52 | + block: number |
| 53 | + ): void; |
| 54 | + |
| 55 | + /** Checks if rtrace is active, i.e. at least one event has occurred. */ |
67 | 56 | readonly active: boolean; |
68 | 57 |
|
69 | | - /** |
70 | | - * This method returns the current number of allocated blocks. |
71 | | - */ |
| 58 | + /** Checks if there are any leaks and emits them via `oninfo`. Returns the number of live blocks. */ |
72 | 59 | check(): number; |
73 | | - |
74 | 60 | } |
75 | | - |
76 | | - /** |
77 | | - * This is a trace event callback. It accepts a string containing a message about the event. |
78 | | - */ |
79 | | - export type TraceEventCallback = (info: string) => void; |
80 | 61 | } |
81 | 62 |
|
82 | 63 | export = rtrace; |
0 commit comments