3 var Promise = require('./core');
5 var DEFAULT_WHITELIST = [
12 exports.disable = disable;
19 exports.enable = enable;
20 function enable(options) {
21 options = options || {};
22 if (enabled) disable();
27 Promise._37 = function (promise) {
29 promise._65 === 2 && // IS REJECTED
30 rejections[promise._51]
32 if (rejections[promise._51].logged) {
33 onHandled(promise._51);
35 clearTimeout(rejections[promise._51].timeout);
37 delete rejections[promise._51];
40 Promise._87 = function (promise, err) {
41 if (promise._40 === 0) { // not yet handled
43 rejections[promise._51] = {
47 onUnhandled.bind(null, promise._51),
48 // For reference errors and type errors, this almost always
49 // means the programmer made a mistake, so log them after just
51 // otherwise, wait 2 seconds to see if they get handled
52 matchWhitelist(err, DEFAULT_WHITELIST)
60 function onUnhandled(id) {
62 options.allRejections ||
65 options.whitelist || DEFAULT_WHITELIST
68 rejections[id].displayId = displayId++;
69 if (options.onUnhandled) {
70 rejections[id].logged = true;
72 rejections[id].displayId,
76 rejections[id].logged = true;
78 rejections[id].displayId,
84 function onHandled(id) {
85 if (rejections[id].logged) {
86 if (options.onHandled) {
87 options.onHandled(rejections[id].displayId, rejections[id].error);
88 } else if (!rejections[id].onUnhandled) {
90 'Promise Rejection Handled (id: ' + rejections[id].displayId + '):'
93 ' This means you can ignore any previous messages of the form "Possible Unhandled Promise Rejection" with id ' +
94 rejections[id].displayId + '.'
101 function logError(id, error) {
102 console.warn('Possible Unhandled Promise Rejection (id: ' + id + '):');
103 var errStr = (error && (error.stack || error)) + '';
104 errStr.split('\n').forEach(function (line) {
105 console.warn(' ' + line);
109 function matchWhitelist(error, list) {
110 return list.some(function (cls) {
111 return error instanceof cls;