From abd94a7f5a50f43c797a11b53549ae48fff667c3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 10 Oct 2016 03:43:44 +0200 Subject: add node_modules to address #4364 --- node_modules/when/monitor/ConsoleReporter.js | 106 ++++++++++++++ node_modules/when/monitor/PromiseMonitor.js | 197 +++++++++++++++++++++++++++ node_modules/when/monitor/README.md | 3 + node_modules/when/monitor/console.js | 14 ++ node_modules/when/monitor/error.js | 86 ++++++++++++ 5 files changed, 406 insertions(+) create mode 100644 node_modules/when/monitor/ConsoleReporter.js create mode 100644 node_modules/when/monitor/PromiseMonitor.js create mode 100644 node_modules/when/monitor/README.md create mode 100644 node_modules/when/monitor/console.js create mode 100644 node_modules/when/monitor/error.js (limited to 'node_modules/when/monitor') diff --git a/node_modules/when/monitor/ConsoleReporter.js b/node_modules/when/monitor/ConsoleReporter.js new file mode 100644 index 000000000..2b0c97411 --- /dev/null +++ b/node_modules/when/monitor/ConsoleReporter.js @@ -0,0 +1,106 @@ +/** @license MIT License (c) copyright 2010-2014 original author or authors */ +/** @author Brian Cavalier */ +/** @author John Hann */ + +(function(define) { 'use strict'; +define(function(require) { + + var error = require('./error'); + var unhandledRejectionsMsg = '[promises] Unhandled rejections: '; + var allHandledMsg = '[promises] All previously unhandled rejections have now been handled'; + + function ConsoleReporter() { + this._previouslyReported = false; + } + + ConsoleReporter.prototype = initDefaultLogging(); + + ConsoleReporter.prototype.log = function(traces) { + if(traces.length === 0) { + if(this._previouslyReported) { + this._previouslyReported = false; + this.msg(allHandledMsg); + } + return; + } + + this._previouslyReported = true; + this.groupStart(unhandledRejectionsMsg + traces.length); + try { + this._log(traces); + } finally { + this.groupEnd(); + } + }; + + ConsoleReporter.prototype._log = function(traces) { + for(var i=0; i= 0; --i) { + t = this._traces[i]; + if(t.handler === handler) { + break; + } + } + + if(i >= 0) { + t.extraContext = extraContext; + } else { + this._traces.push({ + handler: handler, + extraContext: extraContext + }); + } + + this.logTraces(); + }; + + PromiseMonitor.prototype.removeTrace = function(/*handler*/) { + this.logTraces(); + }; + + PromiseMonitor.prototype.fatal = function(handler, extraContext) { + var err = new Error(); + err.stack = this._createLongTrace(handler.value, handler.context, extraContext).join('\n'); + setTimer(function() { + throw err; + }, 0); + }; + + PromiseMonitor.prototype.logTraces = function() { + if(!this._traceTask) { + this._traceTask = setTimer(this._doLogTraces, this.logDelay); + } + }; + + PromiseMonitor.prototype._logTraces = function() { + this._traceTask = void 0; + this._traces = this._traces.filter(filterHandled); + this._reporter.log(this.formatTraces(this._traces)); + }; + + + PromiseMonitor.prototype.formatTraces = function(traces) { + return traces.map(function(t) { + return this._createLongTrace(t.handler.value, t.handler.context, t.extraContext); + }, this); + }; + + PromiseMonitor.prototype._createLongTrace = function(e, context, extraContext) { + var trace = error.parse(e) || [String(e) + ' (WARNING: non-Error used)']; + trace = filterFrames(this.stackFilter, trace, 0); + this._appendContext(trace, context); + this._appendContext(trace, extraContext); + return this.filterDuplicateFrames ? this._removeDuplicates(trace) : trace; + }; + + PromiseMonitor.prototype._removeDuplicates = function(trace) { + var seen = {}; + var sep = this.stackJumpSeparator; + var count = 0; + return trace.reduceRight(function(deduped, line, i) { + if(i === 0) { + deduped.unshift(line); + } else if(line === sep) { + if(count > 0) { + deduped.unshift(line); + count = 0; + } + } else if(!seen[line]) { + seen[line] = true; + deduped.unshift(line); + ++count; + } + return deduped; + }, []); + }; + + PromiseMonitor.prototype._appendContext = function(trace, context) { + trace.push.apply(trace, this._createTrace(context)); + }; + + PromiseMonitor.prototype._createTrace = function(traceChain) { + var trace = []; + var stack; + + while(traceChain) { + stack = error.parse(traceChain); + + if (stack) { + stack = filterFrames(this.stackFilter, stack); + appendStack(trace, stack, this.stackJumpSeparator); + } + + traceChain = traceChain.parent; + } + + return trace; + }; + + function appendStack(trace, stack, separator) { + if (stack.length > 1) { + stack[0] = separator; + trace.push.apply(trace, stack); + } + } + + function filterFrames(stackFilter, stack) { + return stack.filter(function(frame) { + return !stackFilter.test(frame); + }); + } + + function filterHandled(t) { + return !t.handler.handled; + } + + return PromiseMonitor; +}); +}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); })); diff --git a/node_modules/when/monitor/README.md b/node_modules/when/monitor/README.md new file mode 100644 index 000000000..57acff9d8 --- /dev/null +++ b/node_modules/when/monitor/README.md @@ -0,0 +1,3 @@ +# Promise monitoring and debugging + +This dir contains experimental new promise monitoring and debugging utilities for when.js. See [the docs](../docs/api.md#debugging-promises). diff --git a/node_modules/when/monitor/console.js b/node_modules/when/monitor/console.js new file mode 100644 index 000000000..931caa641 --- /dev/null +++ b/node_modules/when/monitor/console.js @@ -0,0 +1,14 @@ +/** @license MIT License (c) copyright 2010-2014 original author or authors */ +/** @author Brian Cavalier */ +/** @author John Hann */ + +(function(define) { 'use strict'; +define(function(require) { + + var monitor = require('../monitor'); + var Promise = require('../when').Promise; + + return monitor(Promise); + +}); +}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); })); diff --git a/node_modules/when/monitor/error.js b/node_modules/when/monitor/error.js new file mode 100644 index 000000000..63825e2c4 --- /dev/null +++ b/node_modules/when/monitor/error.js @@ -0,0 +1,86 @@ +/** @license MIT License (c) copyright 2010-2014 original author or authors */ +/** @author Brian Cavalier */ +/** @author John Hann */ + +(function(define) { 'use strict'; +define(function() { + + var parse, captureStack, format; + + if(Error.captureStackTrace) { + // Use Error.captureStackTrace if available + parse = function(e) { + return e && e.stack && e.stack.split('\n'); + }; + + format = formatAsString; + captureStack = Error.captureStackTrace; + + } else { + // Otherwise, do minimal feature detection to determine + // how to capture and format reasonable stacks. + parse = function(e) { + var stack = e && e.stack && e.stack.split('\n'); + if(stack && e.message) { + stack.unshift(e.message); + } + return stack; + }; + + (function() { + var e = new Error(); + if(typeof e.stack !== 'string') { + format = formatAsString; + captureStack = captureSpiderMonkeyStack; + } else { + format = formatAsErrorWithStack; + captureStack = useStackDirectly; + } + }()); + } + + function captureSpiderMonkeyStack(host) { + try { + throw new Error(); + } catch(err) { + host.stack = err.stack; + } + } + + function useStackDirectly(host) { + host.stack = new Error().stack; + } + + function formatAsString(longTrace) { + return join(longTrace); + } + + function formatAsErrorWithStack(longTrace) { + var e = new Error(); + e.stack = formatAsString(longTrace); + return e; + } + + // About 5-10x faster than String.prototype.join o_O + function join(a) { + var sep = false; + var s = ''; + for(var i=0; i< a.length; ++i) { + if(sep) { + s += '\n' + a[i]; + } else { + s+= a[i]; + sep = true; + } + } + return s; + } + + return { + parse: parse, + format: format, + captureStack: captureStack + }; + +}); +}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); })); -- cgit v1.2.3