Skip to content

Commit

Permalink
Merge pull request #176 from canjs/swallow
Browse files Browse the repository at this point in the history
Prevents errors thrown outside of the run promise from being swallowed
  • Loading branch information
matthewp authored Jun 21, 2018
2 parents 6fbb8cf + 06f267e commit 3eb882e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ Task.prototype.run = function(ctx, args){
zone.execHookR("afterTask", this);
} catch(err) {
Zone.current = previousZone;
if(!this.nestedTask)
if(!this.nestedTask) {
zone.execHookR("afterTask", this);
if(this.catchErrors !== false) {
}

if(this.catchErrors !== false && !this.zone.isResolved) {
zone.errors.push(err);
} else {
throw err;
Expand Down
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,27 @@ if(isBrowser && !isWorker) {
})
.then(done, done);
});

it("Event handlers ran after the Zone completes throw their error", function(done){
var el = document.createElement("div");

new Zone().run(function(){
el.addEventListener("some-event", function(){
throw new Error("Hello world!");
});
})
.then(function(){
var errorNotSwallowed = false;
window.onerror = function(){
window.onerror = null;
errorNotSwallowed = true;
return true;
};
el.dispatchEvent(new Event("some-event"));
assert.ok(errorNotSwallowed, "Threw an error, not swallowed");
})
.then(done, done);
});
});

describe("when third-party library (i.e. affirm) also wraps events (i.e. addEventListener) in strict-mode", function(){
Expand Down

0 comments on commit 3eb882e

Please sign in to comment.