Merge branch 'handle-rejection' of https://github.com/johnjbarton/jasmine
- Merges #1521 from @johnjbarton
This commit is contained in:
@@ -13,18 +13,29 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
this.originalHandlers = {};
|
||||
this.installOne_ = function installOne_(errorType) {
|
||||
this.originalHandlers[errorType] = global.process.listeners(errorType);
|
||||
global.process.removeAllListeners(errorType);
|
||||
global.process.on(errorType, onerror);
|
||||
|
||||
this.uninstall = function uninstall() {
|
||||
var errorTypes = Object.keys(this.originalHandlers);
|
||||
for (var iType = 0; iType < errorTypes.length; iType++) {
|
||||
var errorType = errorTypes[iType];
|
||||
global.process.removeListener(errorType, onerror);
|
||||
for (var i = 0; i < this.originalHandlers[errorType].length; i++) {
|
||||
global.process.on(errorType, this.originalHandlers[errorType][i]);
|
||||
}
|
||||
delete this.originalHandlers[errorType];
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
this.install = function install() {
|
||||
if (global.process && global.process.listeners && j$.isFunction_(global.process.on)) {
|
||||
var originalHandlers = global.process.listeners('uncaughtException');
|
||||
global.process.removeAllListeners('uncaughtException');
|
||||
global.process.on('uncaughtException', onerror);
|
||||
|
||||
this.uninstall = function uninstall() {
|
||||
global.process.removeListener('uncaughtException', onerror);
|
||||
for (var i = 0; i < originalHandlers.length; i++) {
|
||||
global.process.on('uncaughtException', originalHandlers[i]);
|
||||
}
|
||||
};
|
||||
this.installOne_('uncaughtException');
|
||||
this.installOne_('unhandledRejection');
|
||||
} else {
|
||||
var originalHandler = global.onerror;
|
||||
global.onerror = onerror;
|
||||
|
||||
Reference in New Issue
Block a user