Skip to content

Commit

Permalink
Add Assert Shortcodes (#5619)
Browse files Browse the repository at this point in the history
Now that the automation is coming together this change will apply the first set of shortcodes

related to #5409 #5529 #5552
  • Loading branch information
anthony-murphy authored Mar 25, 2021
1 parent 4006ac8 commit 0b4889b
Show file tree
Hide file tree
Showing 96 changed files with 937 additions and 521 deletions.
4 changes: 2 additions & 2 deletions common/lib/common-utils/src/bufferBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class IsoBuffer extends Uint8Array {
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)
} else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) {
// Support currently for full array, no view ports! (though it can be added in future)
assert(value.byteOffset === 0, "nonzero isobuffer byte offset");
assert(value.byteLength === value.buffer.byteLength, "unexpected isobuffer byte length");
assert(value.byteOffset === 0, 0x000 /* "nonzero isobuffer byte offset" */);
assert(value.byteLength === value.buffer.byteLength, 0x001 /* "unexpected isobuffer byte length" */);
return IsoBuffer.fromArrayBuffer(value.buffer, encodingOrOffset as number | undefined, length);
} else if (isArrayBuffer(value)) {
return IsoBuffer.fromArrayBuffer(value, encodingOrOffset as number | undefined, length);
Expand Down
2 changes: 1 addition & 1 deletion common/lib/common-utils/src/hashFileBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function setInsecureContextHashFn(hashFn: (f: IsoBuffer) => Promise<strin
export async function hashFile(file: IsoBuffer): Promise<string> {
// Use the function override if provided
if (insecureContextHashFn !== undefined) {
assert(crypto.subtle === undefined, "Both crypto.subtle and insecureContextHashFn are defined!");
assert(crypto.subtle === undefined, 0x002 /* "Both crypto.subtle and insecureContextHashFn are defined!" */);
return insecureContextHashFn(file);
}

Expand Down
17 changes: 10 additions & 7 deletions common/lib/common-utils/src/rangeTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export class RangeTracker {
public add(primary: number, secondary: number) {
// Both values must continuously be increasing - we won't always track the last value we saw so we do so
// below to check invariants
assert(primary >= this.lastPrimary, "Primary to add to range < last primary!");
assert(primary >= this.lastPrimary, 0x003 /* "Primary to add to range < last primary!" */);
if (this.lastSecondary !== undefined) {
assert(secondary >= this.lastSecondary, "Secondary to add to range < last secondary!");
assert(secondary >= this.lastSecondary, 0x004 /* "Secondary to add to range < last secondary!" */);
}
this.lastPrimary = primary;
this.lastSecondary = secondary;
Expand Down Expand Up @@ -140,7 +140,7 @@ export class RangeTracker {
* @returns the closest range to the primary
*/
public get(primary: number): number {
assert(primary >= this.ranges[0].primary, "Target primary to retrieve < first range's primary!");
assert(primary >= this.ranges[0].primary, 0x005 /* "Target primary to retrieve < first range's primary!" */);

// Find the first range where the starting position is greater than the primary. Our target range is
// the one before it.
Expand All @@ -150,7 +150,8 @@ export class RangeTracker {
break;
}
}
assert(primary >= this.ranges[index - 1].primary, "Target primary to retrieve < last range's primary!");
assert(primary >= this.ranges[index - 1].primary,
0x006 /* "Target primary to retrieve < last range's primary!" */);

// If the difference is within the stored range use it - otherwise add in the length - 1 as the highest
// stored secondary value to use.
Expand All @@ -164,7 +165,7 @@ export class RangeTracker {
* @param primary - the primary value to update
*/
public updateBase(primary: number) {
assert(primary >= this.ranges[0].primary, "Target primary to update < first range's primary!");
assert(primary >= this.ranges[0].primary, 0x007 /* "Target primary to update < first range's primary!" */);

// Walk the ranges looking for the first one that is greater than the primary. Primary is then within the
// previous index by definition (since it's less than the current index's primary but greather than the
Expand All @@ -175,7 +176,8 @@ export class RangeTracker {
break;
}
}
assert(primary >= this.ranges[index - 1].primary, "Target primary to update < last range's primary!");
assert(primary >= this.ranges[index - 1].primary,
0x008 /* "Target primary to update < last range's primary!" */);

// Update the last range values
const range = this.ranges[index - 1];
Expand All @@ -188,6 +190,7 @@ export class RangeTracker {
this.ranges = index - 1 > 0 ? this.ranges.slice(index - 1) : this.ranges;

// Assert that the lowest value is now the input to this method
assert(primary === this.ranges[0].primary, "After update, target primary is not first range's primary!");
assert(primary === this.ranges[0].primary,
0x009 /* "After update, target primary is not first range's primary!" */);
}
}
4 changes: 2 additions & 2 deletions common/lib/common-utils/src/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class Timer implements ITimer {
}

private handler() {
assert(!!this.runningState, "Running timer missing handler");
assert(!!this.runningState, 0x00a /* "Running timer missing handler" */);
const restart = this.runningState.restart;
if (restart !== undefined) {
// Restart with remaining time
Expand Down Expand Up @@ -222,7 +222,7 @@ export class PromiseTimer implements IPromiseTimer {

protected wrapHandler(handler: () => void) {
handler();
assert(!!this.deferred, "Handler executed without deferred");
assert(!!this.deferred, 0x00b /* "Handler executed without deferred" */);
this.deferred.resolve({ timerResult: "timeout" });
this.deferred = undefined;
}
Expand Down
170 changes: 160 additions & 10 deletions lerna-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b4889b

Please sign in to comment.