util: drop all homemade polyfills.
This commit is contained in:
parent
d9342cd81c
commit
8358fa59c6
@ -1943,7 +1943,7 @@ Chain.prototype.getProofTime = function getProofTime(to, from) {
|
||||
work = work.div(this.tip.getProof());
|
||||
|
||||
if (work.bitLength() > 53)
|
||||
return sign * util.MAX_SAFE_INTEGER;
|
||||
return sign * Number.MAX_SAFE_INTEGER;
|
||||
|
||||
return sign * work.toNumber();
|
||||
};
|
||||
|
||||
@ -646,7 +646,7 @@ HTTPClient.prototype.getWalletCoin = function getWalletCoin(id, account, hash, i
|
||||
*/
|
||||
|
||||
HTTPClient.prototype.send = function send(id, options) {
|
||||
options = util.merge({}, options);
|
||||
options = Object.assign({}, options);
|
||||
options.outputs = options.outputs || [];
|
||||
|
||||
if (options.rate)
|
||||
@ -695,7 +695,7 @@ HTTPClient.prototype.setPassphrase = function setPassphrase(id, old, new_) {
|
||||
*/
|
||||
|
||||
HTTPClient.prototype.createTX = function createTX(id, options) {
|
||||
options = util.merge({}, options);
|
||||
options = Object.assign({}, options);
|
||||
|
||||
if (options.rate)
|
||||
options.rate = Amount.btc(options.rate);
|
||||
@ -725,7 +725,7 @@ HTTPClient.prototype.sign = function sign(id, tx, options) {
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
body = util.merge({}, options);
|
||||
body = Object.assign({}, options);
|
||||
body.tx = toHex(tx);
|
||||
|
||||
return this._post('/wallet/' + id + '/sign', body);
|
||||
|
||||
@ -99,7 +99,7 @@ CPUMiner.prototype._close = async function close() {
|
||||
|
||||
CPUMiner.prototype.start = function start() {
|
||||
assert(!this.running, 'Miner is already running.');
|
||||
this._start().catch(util.nop);
|
||||
this._start().catch(nop);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -571,6 +571,12 @@ CPUJob.prototype.pushTX = function pushTX(tx, view) {
|
||||
return this.attempt.pushTX(tx, view);
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function nop() {}
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
@ -1186,7 +1186,7 @@ Pool.prototype.createInbound = function createInbound(socket) {
|
||||
*/
|
||||
|
||||
Pool.prototype.uid = function uid() {
|
||||
var MAX = util.MAX_SAFE_INTEGER;
|
||||
var MAX = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
if (this.id >= MAX - this.peers.size() - 1)
|
||||
this.id = 0;
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
var assert = require('assert');
|
||||
var fs = require('../utils/fs');
|
||||
var util = require('../utils/util');
|
||||
var os = require('os');
|
||||
var HOME = os.homedir();
|
||||
|
||||
/**
|
||||
* Config Parser
|
||||
@ -25,7 +27,7 @@ function Config(module) {
|
||||
|
||||
this.module = module;
|
||||
this.network = 'main';
|
||||
this.prefix = util.HOME + '/.' + module;
|
||||
this.prefix = HOME + '/.' + module;
|
||||
|
||||
this.options = Object.create(null);
|
||||
this.data = Object.create(null);
|
||||
@ -531,7 +533,7 @@ Config.prototype.path = function path(key, fallback) {
|
||||
|
||||
switch (value[0]) {
|
||||
case '~': // home dir
|
||||
value = util.HOME + value.substring(1);
|
||||
value = HOME + value.substring(1);
|
||||
break;
|
||||
case '@': // prefix
|
||||
value = this.prefix + value.substring(1);
|
||||
@ -591,11 +593,11 @@ Config.prototype.getPrefix = function getPrefix() {
|
||||
|
||||
if (prefix) {
|
||||
if (prefix[0] === '~')
|
||||
prefix = util.HOME + prefix.substring(1);
|
||||
prefix = HOME + prefix.substring(1);
|
||||
return prefix;
|
||||
}
|
||||
|
||||
prefix = util.HOME + '/.' + this.module;
|
||||
prefix = HOME + '/.' + this.module;
|
||||
network = this.str('network');
|
||||
|
||||
if (network) {
|
||||
|
||||
@ -14,14 +14,6 @@
|
||||
var BN = require('bn.js');
|
||||
var encoding = exports;
|
||||
|
||||
/**
|
||||
* Max safe integer (53 bits).
|
||||
* @const {Number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
||||
|
||||
/**
|
||||
* An empty buffer.
|
||||
* @const {Buffer}
|
||||
@ -360,7 +352,7 @@ encoding._write64 = function _write64(dst, num, off, be) {
|
||||
num -= 1;
|
||||
}
|
||||
|
||||
enforce(num <= encoding.MAX_SAFE_INTEGER, off, 'Number exceeds 2^53-1');
|
||||
enforce(num <= Number.MAX_SAFE_INTEGER, off, 'Number exceeds 2^53-1');
|
||||
|
||||
lo = num % 0x100000000;
|
||||
hi = (num - lo) / 0x100000000;
|
||||
|
||||
@ -990,7 +990,7 @@ IP.isEqual = function isEqual(a, b) {
|
||||
*/
|
||||
|
||||
IP.getInterfaces = function _getInterfaces(name, family) {
|
||||
var interfaces = getInterfaces();
|
||||
var interfaces = os.networkInterfaces();
|
||||
var keys = Object.keys(interfaces);
|
||||
var result = [];
|
||||
var i, j, key, items, details, type, raw;
|
||||
@ -1081,16 +1081,6 @@ function Address(host, port, type, hostname, raw) {
|
||||
this.raw = raw || ZERO_IP;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function getInterfaces() {
|
||||
if (os.unsupported)
|
||||
return {};
|
||||
return os.networkInterfaces();
|
||||
}
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var nodeUtil = require('util');
|
||||
var os = require('os');
|
||||
|
||||
/**
|
||||
* @exports utils/util
|
||||
@ -17,25 +16,6 @@ var os = require('os');
|
||||
|
||||
var util = exports;
|
||||
|
||||
/**
|
||||
* The home directory.
|
||||
* @const {String}
|
||||
*/
|
||||
|
||||
util.HOME = '/';
|
||||
|
||||
if (os.homedir)
|
||||
util.HOME = os.homedir();
|
||||
|
||||
/**
|
||||
* Global NOP function.
|
||||
* @type function
|
||||
* @static
|
||||
* @method
|
||||
*/
|
||||
|
||||
util.nop = function() {};
|
||||
|
||||
/**
|
||||
* Clone a buffer.
|
||||
* @param {Buffer} data
|
||||
@ -135,39 +115,6 @@ util.revHex = function revHex(data) {
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shallow merge between multiple objects.
|
||||
* @param {Object} target
|
||||
* @param {...Object} args
|
||||
* @returns {Object} target
|
||||
*/
|
||||
|
||||
util.merge = function merge(target) {
|
||||
var i, j, obj, keys, key;
|
||||
|
||||
for (i = 1; i < arguments.length; i++) {
|
||||
obj = arguments[i];
|
||||
keys = Object.keys(obj);
|
||||
for (j = 0; j < keys.length; j++) {
|
||||
key = keys[j];
|
||||
target[key] = obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
if (Object.assign)
|
||||
util.merge = Object.assign;
|
||||
|
||||
/**
|
||||
* Max safe integer (53 bits).
|
||||
* @const {Number}
|
||||
* @default
|
||||
*/
|
||||
|
||||
util.MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
||||
|
||||
/**
|
||||
* Test whether a number is below MAX_SAFE_INTEGER.
|
||||
* @param {Number} value
|
||||
@ -175,7 +122,7 @@ util.MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
||||
*/
|
||||
|
||||
util.isSafeInteger = function isSafeInteger(value) {
|
||||
return value >= -0x1fffffffffffff && value <= 0x1fffffffffffff;
|
||||
return Number.isSafeInteger(value);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -363,6 +310,8 @@ util.inspectify = function inspectify(obj, color) {
|
||||
/**
|
||||
* Format a string.
|
||||
* @function
|
||||
* @param {...String} args
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
util.fmt = nodeUtil.format;
|
||||
@ -380,7 +329,7 @@ util.format = function format(args, color) {
|
||||
|
||||
return typeof args[0] === 'object'
|
||||
? util.inspectify(args[0], color)
|
||||
: nodeUtil.format.apply(nodeUtil, args);
|
||||
: util.fmt.apply(util, args);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -567,33 +516,12 @@ util.mb = function mb(size) {
|
||||
*/
|
||||
|
||||
util.inherits = function inherits(child, parent) {
|
||||
var f;
|
||||
|
||||
child.super_ = parent;
|
||||
|
||||
if (Object.setPrototypeOf) {
|
||||
Object.setPrototypeOf(child.prototype, parent.prototype);
|
||||
Object.defineProperty(child.prototype, 'constructor', {
|
||||
value: child,
|
||||
enumerable: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (Object.create) {
|
||||
child.prototype = Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
f = function() {};
|
||||
f.prototype = parent.prototype;
|
||||
child.prototype = new f();
|
||||
child.prototype.constructor = child;
|
||||
Object.setPrototypeOf(child.prototype, parent.prototype);
|
||||
Object.defineProperty(child.prototype, 'constructor', {
|
||||
value: child,
|
||||
enumerable: false
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -110,9 +110,9 @@ Master.prototype._initChildProcess = function _initChildProcess() {
|
||||
});
|
||||
|
||||
// Nowhere to send these errors:
|
||||
process.stdin.on('error', util.nop);
|
||||
process.stdout.on('error', util.nop);
|
||||
process.stderr.on('error', util.nop);
|
||||
process.stdin.on('error', nop);
|
||||
process.stdout.on('error', nop);
|
||||
process.stderr.on('error', nop);
|
||||
|
||||
process.on('uncaughtException', function(err) {
|
||||
self.send(new packets.ErrorPacket(err));
|
||||
@ -265,6 +265,12 @@ Master.prototype.handlePacket = function handlePacket(packet) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function nop() {}
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
@ -48,7 +48,7 @@ function WorkerPool(options) {
|
||||
|
||||
this.set(options);
|
||||
|
||||
this.on('error', util.nop);
|
||||
this.on('error', nop);
|
||||
}
|
||||
|
||||
util.inherits(WorkerPool, EventEmitter);
|
||||
@ -547,7 +547,7 @@ Worker.prototype._initChildProcess = function _initChildProcess() {
|
||||
var self = this;
|
||||
var file = process.argv[0];
|
||||
var argv = [__dirname + '/worker.js'];
|
||||
var env = util.merge({}, process.env, this.env);
|
||||
var env = Object.assign({}, process.env, this.env);
|
||||
var options = { stdio: 'pipe', env: env };
|
||||
|
||||
this.child = cp.spawn(file, argv, options);
|
||||
@ -887,12 +887,11 @@ PendingJob.prototype.reject = function reject(err) {
|
||||
*/
|
||||
|
||||
function getCores() {
|
||||
if (os.unsupported)
|
||||
return 2;
|
||||
|
||||
return Math.max(1, os.cpus().length);
|
||||
return Math.max(2, os.cpus().length);
|
||||
}
|
||||
|
||||
function nop() {}
|
||||
|
||||
/*
|
||||
* Default Pool
|
||||
*/
|
||||
|
||||
@ -67,14 +67,13 @@
|
||||
"webpack": "webpack"
|
||||
},
|
||||
"browser": {
|
||||
"bcoin-native": "./browser/empty.js",
|
||||
"child_process": "./browser/empty.js",
|
||||
"crypto": "./browser/empty.js",
|
||||
"dgram": "./browser/empty.js",
|
||||
"dns": "./browser/empty.js",
|
||||
"fs": "./browser/empty.js",
|
||||
"net": "./browser/empty.js",
|
||||
"os": "./browser/empty.js",
|
||||
"bcoin-native": "./browser/empty.js",
|
||||
"secp256k1": "./browser/empty.js",
|
||||
"socket.io": "./browser/empty.js",
|
||||
"./lib/bcoin": "./lib/bcoin-browser.js",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user