react / wstein / node_modules / browserify / node_modules / crypto-browserify / node_modules / public-encrypt / node_modules / parse-asn1 / node_modules / asn1.js / lib / asn1 / base / reporter.js
80647 viewsvar inherits = require('inherits');12function Reporter(options) {3this._reporterState = {4obj: null,5path: [],6options: options || {},7errors: []8};9}10exports.Reporter = Reporter;1112Reporter.prototype.isError = function isError(obj) {13return obj instanceof ReporterError;14};1516Reporter.prototype.save = function save() {17var state = this._reporterState;1819return { obj: state.obj, pathLen: state.path.length };20};2122Reporter.prototype.restore = function restore(data) {23var state = this._reporterState;2425state.obj = data.obj;26state.path = state.path.slice(0, data.pathLen);27};2829Reporter.prototype.enterKey = function enterKey(key) {30return this._reporterState.path.push(key);31};3233Reporter.prototype.leaveKey = function leaveKey(index, key, value) {34var state = this._reporterState;3536state.path = state.path.slice(0, index - 1);37if (state.obj !== null)38state.obj[key] = value;39};4041Reporter.prototype.enterObject = function enterObject() {42var state = this._reporterState;4344var prev = state.obj;45state.obj = {};46return prev;47};4849Reporter.prototype.leaveObject = function leaveObject(prev) {50var state = this._reporterState;5152var now = state.obj;53state.obj = prev;54return now;55};5657Reporter.prototype.error = function error(msg) {58var err;59var state = this._reporterState;6061var inherited = msg instanceof ReporterError;62if (inherited) {63err = msg;64} else {65err = new ReporterError(state.path.map(function(elem) {66return '[' + JSON.stringify(elem) + ']';67}).join(''), msg.message || msg, msg.stack);68}6970if (!state.options.partial)71throw err;7273if (!inherited)74state.errors.push(err);7576return err;77};7879Reporter.prototype.wrapResult = function wrapResult(result) {80var state = this._reporterState;81if (!state.options.partial)82return result;8384return {85result: this.isError(result) ? null : result,86errors: state.errors87};88};8990function ReporterError(path, msg) {91this.path = path;92this.rethrow(msg);93};94inherits(ReporterError, Error);9596ReporterError.prototype.rethrow = function rethrow(msg) {97this.message = msg + ' at: ' + (this.path || '(shallow)');98Error.captureStackTrace(this, ReporterError);99100return this;101};102103104