Skip to content

Commit 2e249e4

Browse files
authored
feat: Make Rtrace ESM by default, with UMD fallback (#1515)
BREAKING CHANGE: Rtrace is now an ES module by default as well.
1 parent 8c97612 commit 2e249e4

File tree

10 files changed

+437
-19
lines changed

10 files changed

+437
-19
lines changed

lib/rtrace/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RTrace
1+
# AssemblyScript Rtrace
22

33
A tiny utility that records allocations, retains, releases and frees performed by the runtime and emits an error if something is off. Also checks for leaks.
44

lib/rtrace/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export declare interface RtraceOptions {
3030
export declare class Rtrace {
3131
[key: string]: unknown; // can be used as a Wasm import
3232

33-
/** Creates a new `RTrace` instance. */
33+
/** Creates a new `Rtrace` instance. */
3434
constructor(options: RtraceOptions);
3535

3636
/** Checks if rtrace is active, i.e. at least one event has occurred. */

lib/rtrace/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const PTR_VIEW = Uint32Array;
1111

1212
const BLOCK_OVERHEAD = PTR_SIZE;
1313

14+
const RT_TLSF = "~lib/rt/tlsf/";
15+
1416
function assert(x) {
1517
if (!x) throw Error("assertion failed");
1618
return x;
@@ -23,10 +25,10 @@ function trimStacktrace(stack, levels) {
2325
}
2426

2527
function isTLSF(stack) {
26-
return stack[0].startsWith(" at ~lib/rt/tlsf/");
28+
return stack[0].startsWith(` at ${RT_TLSF}`);
2729
}
2830

29-
class Rtrace {
31+
export class Rtrace {
3032

3133
constructor(options) {
3234
this.options = options || {};
@@ -146,12 +148,12 @@ class Rtrace {
146148
var mmInfo = header[0];
147149
var gcInfo = header[1];
148150
var gcInfo2 = header[2];
149-
const mmTags = [ // 0│L│F
151+
const mmTags = [
150152
[],
151153
["FREE"],
152154
["LEFTFREE"],
153155
["FREE", "LEFTFREE"]
154-
];
156+
]; // 2=LEFTFREE, 1=FREE
155157
const gcColor = [
156158
"BLACK",
157159
"GRAY",
@@ -208,7 +210,7 @@ class Rtrace {
208210
this.markShadow(info);
209211
this.refCounts.set(ptr, 0);
210212
this.blocks.set(ptr, Object.assign(info, {
211-
allocStack: trimStacktrace(new Error().stack, /* onalloc */ 1)
213+
allocStack: trimStacktrace(new Error().stack, 1) // strip onalloc
212214
}));
213215
}
214216
}
@@ -264,7 +266,7 @@ class Rtrace {
264266
this.refCounts.delete(ptr);
265267
this.unmarkShadow(info);
266268
let block = this.blocks.get(ptr);
267-
block.freeStack = trimStacktrace(new Error().stack, /* onfree */ 1);
269+
block.freeStack = trimStacktrace(new Error().stack, 1); // strip onfree
268270
}
269271
}
270272

@@ -343,4 +345,6 @@ class Rtrace {
343345
}
344346
}
345347

346-
exports.Rtrace = Rtrace;
348+
export default {
349+
Rtrace
350+
};

lib/rtrace/package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
{
22
"name": "@assemblyscript/rtrace",
3-
"types": "index.d.ts",
43
"version": "0.2.0",
54
"license": "Apache-2.0",
6-
"main": "index.js"
5+
"type": "module",
6+
"main": "index.js",
7+
"types": "index.d.ts",
8+
"exports": {
9+
"import": "./index.js",
10+
"require": "./umd/index.js"
11+
},
12+
"scripts": {
13+
"build": "npx esm2umd rtrace index.js > umd/index.js"
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"index.js",
18+
"package.json",
19+
"umd/index.d.ts",
20+
"umd/index.js",
21+
"umd/package.json",
22+
"README.md"
23+
]
724
}

lib/rtrace/umd/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "..";

0 commit comments

Comments
 (0)