Skip to content

Make Rtrace ESM by default, with UMD fallback #1515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rtrace/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RTrace
# AssemblyScript Rtrace

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.

Expand Down
2 changes: 1 addition & 1 deletion lib/rtrace/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export declare interface RtraceOptions {
export declare class Rtrace {
[key: string]: unknown; // can be used as a Wasm import

/** Creates a new `RTrace` instance. */
/** Creates a new `Rtrace` instance. */
constructor(options: RtraceOptions);

/** Checks if rtrace is active, i.e. at least one event has occurred. */
Expand Down
18 changes: 11 additions & 7 deletions lib/rtrace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const PTR_VIEW = Uint32Array;

const BLOCK_OVERHEAD = PTR_SIZE;

const RT_TLSF = "~lib/rt/tlsf/";

function assert(x) {
if (!x) throw Error("assertion failed");
return x;
Expand All @@ -23,10 +25,10 @@ function trimStacktrace(stack, levels) {
}

function isTLSF(stack) {
return stack[0].startsWith(" at ~lib/rt/tlsf/");
return stack[0].startsWith(` at ${RT_TLSF}`);
}

class Rtrace {
export class Rtrace {

constructor(options) {
this.options = options || {};
Expand Down Expand Up @@ -146,12 +148,12 @@ class Rtrace {
var mmInfo = header[0];
var gcInfo = header[1];
var gcInfo2 = header[2];
const mmTags = [ // 0│L│F
const mmTags = [
[],
["FREE"],
["LEFTFREE"],
["FREE", "LEFTFREE"]
];
]; // 2=LEFTFREE, 1=FREE
const gcColor = [
"BLACK",
"GRAY",
Expand Down Expand Up @@ -208,7 +210,7 @@ class Rtrace {
this.markShadow(info);
this.refCounts.set(ptr, 0);
this.blocks.set(ptr, Object.assign(info, {
allocStack: trimStacktrace(new Error().stack, /* onalloc */ 1)
allocStack: trimStacktrace(new Error().stack, 1) // strip onalloc
}));
}
}
Expand Down Expand Up @@ -264,7 +266,7 @@ class Rtrace {
this.refCounts.delete(ptr);
this.unmarkShadow(info);
let block = this.blocks.get(ptr);
block.freeStack = trimStacktrace(new Error().stack, /* onfree */ 1);
block.freeStack = trimStacktrace(new Error().stack, 1); // strip onfree
}
}

Expand Down Expand Up @@ -343,4 +345,6 @@ class Rtrace {
}
}

exports.Rtrace = Rtrace;
export default {
Rtrace
};
21 changes: 19 additions & 2 deletions lib/rtrace/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
{
"name": "@assemblyscript/rtrace",
"types": "index.d.ts",
"version": "0.2.0",
"license": "Apache-2.0",
"main": "index.js"
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": {
"import": "./index.js",
"require": "./umd/index.js"
},
"scripts": {
"build": "npx esm2umd rtrace index.js > umd/index.js"
},
"files": [
"index.d.ts",
"index.js",
"package.json",
"umd/index.d.ts",
"umd/index.js",
"umd/package.json",
"README.md"
]
}
1 change: 1 addition & 0 deletions lib/rtrace/umd/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "..";
Loading