Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform to spec when generating PromiseRejectionEvent #1464

Merged
merged 3 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/debuggability.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ var fireDomEvent = (function() {
return function(name, event) {
var domEvent = new CustomEvent(name.toLowerCase(), {
detail: event,
cancelable: true
cancelable: true,
reason: event.reason,
promise: event.promise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to write this as get promise() { return event.promise; }? I'm unfamiliar with the compilation pipeline for bluebird, and whether that syntax is supported on all the browsers Bluebird targets.

If we wanted to be even more protective, we could do something like:

var reason = event.reason;
var promise = event.promise;
var domEvent = new CustomEvent(name.toLowerCase(), {
  detail: event,
  cancelable: true,
  get reason() { return reason; },
  get promise() { return promise; }
})

or the equivalent with Object.defineProperty

Let me know if that's a desirable change & I can update the PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bluebird actually targets ES3 browsers too (supports IE7 for example) - on the other hand this branch of code isn't reached on these browsers anyway.

});
return !util.global.dispatchEvent(domEvent);
};
Expand Down
8 changes: 8 additions & 0 deletions test/mocha/unhandled_rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,23 +644,31 @@ if (windowDomEventSupported) {
e.preventDefault();
assert.strictEqual(e.detail.promise, promise);
assert.strictEqual(e.detail.reason, err);
assert.strictEqual(e.promise, promise);
assert.strictEqual(e.reason, err);
order.push(1);
});
attachEvent("unhandledrejection", function(e) {
assert.strictEqual(e.detail.promise, promise);
assert.strictEqual(e.detail.reason, err);
assert.strictEqual(e.promise, promise);
assert.strictEqual(e.reason, err);
assert.strictEqual(e.defaultPrevented, true);
order.push(2);
});
attachEvent("rejectionhandled", function(e) {
e.preventDefault();
assert.strictEqual(e.detail.promise, promise);
assert.strictEqual(e.detail.reason, undefined);
assert.strictEqual(e.promise, promise);
assert.strictEqual(e.reason, err);
order.push(3);
});
attachEvent("rejectionhandled", function(e) {
assert.strictEqual(e.detail.promise, promise);
assert.strictEqual(e.detail.reason, undefined);
assert.strictEqual(e.promise, promise);
assert.strictEqual(e.reason, err);
assert.strictEqual(e.defaultPrevented, true);
order.push(4);
resolve();
Expand Down