diff --git a/src/debuggability.js b/src/debuggability.js index 8a97eab68..024892f0a 100644 --- a/src/debuggability.js +++ b/src/debuggability.js @@ -4,6 +4,7 @@ var getDomain = Promise._getDomain; var async = Promise._async; var Warning = require("./errors").Warning; var util = require("./util"); +var es5 = require("./es5"); var ASSERT = require("./assert"); var canAttachTrace = util.canAttachTrace; var unhandledRejectionHandled; @@ -154,10 +155,14 @@ var fireDomEvent = (function() { var event = new CustomEvent("CustomEvent"); util.global.dispatchEvent(event); return function(name, event) { - var domEvent = new CustomEvent(name.toLowerCase(), { + var eventData = { detail: event, cancelable: true - }); + }; + es5.defineProperty( + eventData, "promise", {value: event.promise}); + es5.defineProperty(eventData, "reason", {value: event.reason}); + var domEvent = new CustomEvent(name.toLowerCase(), eventData); return !util.global.dispatchEvent(domEvent); }; // In Firefox < 48 CustomEvent is not available in workers but @@ -170,6 +175,8 @@ var fireDomEvent = (function() { cancelable: true }); domEvent.detail = event; + es5.defineProperty(domEvent, "promise", {value: event.promise}); + es5.defineProperty(domEvent, "reason", {value: event.reason}); return !util.global.dispatchEvent(domEvent); }; } else { diff --git a/test/mocha/unhandled_rejections.js b/test/mocha/unhandled_rejections.js index cf36add80..b4a43ece7 100644 --- a/test/mocha/unhandled_rejections.js +++ b/test/mocha/unhandled_rejections.js @@ -644,11 +644,15 @@ 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); }); @@ -656,11 +660,15 @@ if (windowDomEventSupported) { 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();