Skip to content

Commit

Permalink
Cleanup bigint literals (Agoric#2302)
Browse files Browse the repository at this point in the history
* fix: cleanup bigint literals
  • Loading branch information
erights authored Feb 1, 2021
1 parent f41efb7 commit eb84a03
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 75 deletions.
14 changes: 7 additions & 7 deletions packages/dapp-svelte-wallet/ui/src/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const CONVENTIONAL_DECIMAL_PLACES = 2;
*/

/**
*
* @param {string} str
* @param {AmountDisplayInfo} displayInfo
*
* @param {string} str
* @param {AmountDisplayInfo} displayInfo
*/
export function parseValue(str, displayInfo) {
const { amountMathKind = MathKind.NAT, decimalPlaces = 0 } = displayInfo || {};
Expand Down Expand Up @@ -47,14 +47,14 @@ export function parseValue(str, displayInfo) {
}

/**
*
* @param {any} value
*
* @param {any} value
* @param {AmountDisplayInfo} [displayInfo]
* @returns {string}
*/
export function stringifyValue(value, displayInfo = undefined) {
const { amountMathKind = MathKind.NAT, decimalPlaces = 0 } = displayInfo || {};

if (amountMathKind !== MathKind.NAT) {
// Just return the size of the set.
return `${value.length}`;
Expand All @@ -66,7 +66,7 @@ export function stringifyValue(value, displayInfo = undefined) {
return `${bValue}`;
}

const bScale = BigInt(10) ** BigInt(decimalPlaces);
const bScale = 10n ** BigInt(decimalPlaces);

// Take integer division of the value by the scale.
const unitstr = `${bValue / bScale}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/marshal/test/test-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('serialize static data', t => {
});
let bn;
try {
bn = BigInt(4);
bn = 4n;
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
Expand Down Expand Up @@ -112,14 +112,14 @@ test('unserialize static data', t => {
t.deepEqual(uns('{"foo": {"@qclass":"undefined"}}'), { foo: undefined });
let bn;
try {
bn = BigInt(4);
bn = 4n;
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
if (bn) {
t.deepEqual(uns('{"@qclass":"bigint","digits":"1234"}'), BigInt(1234));
t.deepEqual(uns('{"@qclass":"bigint","digits":"1234"}'), 1234n);
}

const em1 = uns(
Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-runner/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export async function main() {
const statsPre = controller.getStats();
const args = { body: '[]', slots: [] };
let totalSteps = 0;
let totalDeltaT = BigInt(0);
let totalDeltaT = 0n;
for (let i = 0; i < rounds; i += 1) {
const roundResult = controller.queueToVatExport(
launchIndirectly ? 'launcher' : 'bootstrap',
Expand Down
27 changes: 0 additions & 27 deletions packages/tame-metering/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/tame-metering/src/tame.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global globalThis */
import * as c from './constants';

let replaceGlobalMeter;
Expand Down
27 changes: 0 additions & 27 deletions packages/transform-metering/.eslintrc.js

This file was deleted.

5 changes: 2 additions & 3 deletions packages/transform-metering/src/meter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global BigInt */
import * as c from './constants';

const { isArray } = Array;
Expand All @@ -7,8 +6,8 @@ const { ceil } = Math;
const ObjectConstructor = Object;

// eslint-disable-next-line no-bitwise
const bigIntWord = typeof BigInt !== 'undefined' && BigInt(2) ** BigInt(64);
const bigIntZero = bigIntWord && BigInt(0);
const bigIntWord = typeof BigInt !== 'undefined' && 2n ** 64n;
const bigIntZero = bigIntWord && 0n;

// Stop deducting when we reach a negative number.
const makeCounter = initBalance => {
Expand Down
1 change: 0 additions & 1 deletion packages/transform-metering/test/test-meter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* globals BigInt */
/* eslint-disable no-await-in-loop */
import test from 'ava';

Expand Down
1 change: 0 additions & 1 deletion packages/transform-metering/test/test-zzz-eval.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global Compartment */
// eslint-disable-next-line import/order
import { replaceGlobalMeter } from './install-metering';
import '@agoric/install-ses'; // calls lockdown()
Expand Down
3 changes: 0 additions & 3 deletions packages/zoe/src/contractSupport/bondingCurves.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { natSafeMath } from './safeMath';

const { multiply, floorDivide } = natSafeMath;

// TODO(2196): use 10000n instead of BigInt(10000)
// We use this workaround due to some parser in our toolchain that can't parse
// bigint literals.
const BIG_10000 = 10000n;
const BIG_ONE = 1n;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test('percentMath - Nats only', t => {
message: 'not a safe integer',
});

t.throws(() => makePercent(BigInt(47), amountMath), {
t.throws(() => makePercent(47n, amountMath), {
message: 'not a safe integer',
});
});

0 comments on commit eb84a03

Please sign in to comment.