This commit is contained in:
Christopher Jeffrey 2016-06-05 17:25:05 -07:00
parent f71aa44acc
commit d1695bf014
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -6,6 +6,7 @@
*/ */
var utils = require('./utils'); var utils = require('./utils');
var global = utils.global;
var fs; var fs;
if (!utils.isBrowser) if (!utils.isBrowser)
@ -26,16 +27,20 @@ if (!utils.isBrowser)
* *
* @param {(Object|NetworkType)?} options - Options object or network type. * @param {(Object|NetworkType)?} options - Options object or network type.
* @param {(Network|NetworkType)?} options.network * @param {(Network|NetworkType)?} options.network
* @param {String?} options.prefix - Prefix for filesystem (default=~/.bcoin). * @param {String} [options.prefix=~/.bcoin] - Prefix for filesystem.
* @param {String?} options.db - Database backend (default=leveldb). * @param {String} [options.db=leveldb] - Database backend.
* @param {Boolean?} options.debug - Whether to display debug output. * @param {Boolean} [options.debug=false] - Whether to display debug output.
* @param {(String|Boolean)?} options.debugFile - A file to * @param {String|Boolean} [options.debugFile=~/.bcoin/debug.log] - A file to
* pipe debug output to. * pipe debug output to.
* @param {Boolean?} options.profile - Enable profiler. * @param {Boolean} [options.profile=false] - Enable profiler.
* @param {Boolean?} options.useWorkers - Enable workers. * @param {Boolean} [options.useWorkers=false] - Enable workers.
* @param {Number?} options.maxWorkers - Max size of * @param {Number} [options.maxWorkers=6] - Max size of
* the worker pool (default=6). * the worker pool.
* * @param {String} [options.workerUri=/bcoin-worker.js] Location of the bcoin
* worker.js file for web workers.
* @param {String} [options.proxyServer=localhost:8080] -
* Websocket->tcp proxy server for browser.
* @param {Object?} options.logger - Custom logger.
* @property {Boolean} isBrowser * @property {Boolean} isBrowser
* @property {NetworkType} networkType * @property {NetworkType} networkType
* *
@ -189,8 +194,8 @@ function Environment(options) {
this.useWorkers = null; this.useWorkers = null;
this.maxWorkers = null; this.maxWorkers = null;
this.workerTimeout = null; this.workerTimeout = null;
this.proxyServer = null;
this.workerUri = null; this.workerUri = null;
this.proxyServer = null;
this.logger = null; this.logger = null;
this.time = new this.timedata(); this.time = new this.timedata();
@ -267,8 +272,8 @@ Environment.prototype.set = function set(options) {
this.network.set(this.networkType); this.network.set(this.networkType);
if (this.isBrowser && this.useWorkers) { if (this.isBrowser && this.useWorkers) {
this.useWorkers = typeof utils.global.Worker === 'function' this.useWorkers = typeof global.Worker === 'function'
|| typeof utils.global.postMessage === 'function'; || typeof global.postMessage === 'function';
} }
if (this.useWorkers) { if (this.useWorkers) {
@ -318,8 +323,11 @@ Environment.prototype.debug = function debug() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
var msg; var msg;
if (this.logger) if (this.logger) {
this.logger.debug(args); if (this.debugLogs)
this.logger.debug(args);
return;
}
if (this.isBrowser) { if (this.isBrowser) {
if (this.debugLogs) { if (this.debugLogs) {
@ -356,8 +364,11 @@ Environment.prototype.error = function error(err) {
if (typeof err === 'string') if (typeof err === 'string')
err = new Error(err); err = new Error(err);
if (this.logger) if (this.logger) {
this.logger.error(err); if (this.debugLogs)
this.logger.error(err);
return;
}
if (this.isBrowser) { if (this.isBrowser) {
if (this.debugLogs) if (this.debugLogs)