From 7bda03745e4f48865e1b825586c24a9793c55fff Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Mon, 3 Dec 2012 19:45:31 -0800 Subject: [PATCH] Use custom assert in JS library. The assert was previously provided by Buster.JS which is not available outside of the test suite. --- src/js/remote.js | 14 +++++++------- src/js/utils.js | 8 +++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/js/remote.js b/src/js/remote.js index 0de15e54ca..2d8ac6f767 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -551,7 +551,7 @@ Remote.prototype.request_server_info = function () { // XXX This is a bad command. Some varients don't scale. // XXX Require the server to be trusted. Remote.prototype.request_ledger = function (ledger, full) { - //assert(this.trusted); + //utils.assert(this.trusted); var request = new Request(this, 'ledger'); @@ -566,7 +566,7 @@ Remote.prototype.request_ledger = function (ledger, full) { // Only for unit testing. Remote.prototype.request_ledger_hash = function () { - //assert(this.trusted); // If not trusted, need to check proof. + //utils.assert(this.trusted); // If not trusted, need to check proof. return new Request(this, 'ledger_closed'); }; @@ -588,7 +588,7 @@ Remote.prototype.request_ledger_current = function () { // .ledger_index() // .offer_id() Remote.prototype.request_ledger_entry = function (type) { - //assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol. + //utils.assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol. var self = this; var request = new Request(this, 'ledger_entry'); @@ -692,7 +692,7 @@ Remote.prototype.request_unsubscribe = function (streams) { }; Remote.prototype.request_transaction_entry = function (hash) { - //assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol. + //utils.assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol. return (new Request(this, 'transaction_entry')) .tx_hash(hash); @@ -700,7 +700,7 @@ Remote.prototype.request_transaction_entry = function (hash) { Remote.prototype.request_ripple_lines_get = function (accountID, index) { // XXX Does this require the server to be trusted? - //assert(this.trusted); + //utils.assert(this.trusted); var request = new Request(this, 'ripple_lines_get'); @@ -713,7 +713,7 @@ Remote.prototype.request_ripple_lines_get = function (accountID, index) { }; Remote.prototype.request_wallet_accounts = function (seed) { - assert(this.trusted); // Don't send secrets. + utils.assert(this.trusted); // Don't send secrets. var request = new Request(this, 'wallet_accounts'); @@ -724,7 +724,7 @@ Remote.prototype.request_wallet_accounts = function (seed) { Remote.prototype.request_account_tx = function (accountID, ledger_min, ledger_max) { // XXX Does this require the server to be trusted? - //assert(this.trusted); + //utils.assert(this.trusted); var request = new Request(this, 'account_tx'); diff --git a/src/js/utils.js b/src/js/utils.js index 31d2a72d63..0128711f2c 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -87,13 +87,19 @@ var logObject = function (msg, obj) { console.log(msg, JSON.stringify(obj, undefined, 2)); }; +var assert = function (assertion, msg) { + if (!assertion) { + throw new Error("Assertion failed" + (msg ? ": "+msg : ".")); + } +}; exports.trace = trace; exports.arraySet = arraySet; exports.hexToString = hexToString; exports.stringToArray = stringToArray; exports.stringToHex = stringToHex; -exports.logObject = logObject; exports.chunkString = chunkString; +exports.logObject = logObject; +exports.assert = assert; // vim:sw=2:sts=2:ts=8:et