From 2952828f553980cd1099e8b2aa2e2b7e72015e47 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 5 Oct 2017 14:36:19 -0700 Subject: [PATCH 1/3] Conform to spec when generating PromiseRejectionEvent --- src/debuggability.js | 4 +++- test/mocha/unhandled_rejections.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/debuggability.js b/src/debuggability.js index 8a97eab68..d6b6ec9fd 100644 --- a/src/debuggability.js +++ b/src/debuggability.js @@ -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 }); return !util.global.dispatchEvent(domEvent); }; 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(); From 3accc32b35bea6833c07444ce792e7f43665ae85 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 5 Oct 2017 16:23:53 -0700 Subject: [PATCH 2/3] Use getters instead of plain properties --- src/debuggability.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/debuggability.js b/src/debuggability.js index d6b6ec9fd..cf5aafce2 100644 --- a/src/debuggability.js +++ b/src/debuggability.js @@ -154,12 +154,17 @@ var fireDomEvent = (function() { var event = new CustomEvent("CustomEvent"); util.global.dispatchEvent(event); return function(name, event) { - var domEvent = new CustomEvent(name.toLowerCase(), { + var promise = event.promise; + var reason = event.reason; + var eventData = { detail: event, - cancelable: true, - reason: event.reason, - promise: event.promise + cancelable: true + }; + Object.defineProperties(eventData, { + promise: { get: function() { return promise; } }, + reason: { get: function() { return reason; } } }); + var domEvent = new CustomEvent(name.toLowerCase(), eventData); return !util.global.dispatchEvent(domEvent); }; // In Firefox < 48 CustomEvent is not available in workers but @@ -172,6 +177,10 @@ var fireDomEvent = (function() { cancelable: true }); domEvent.detail = event; + Object.defineProperties(domEvent, { + promise: { get: function() { return event.promise; } }, + reason: { get: function() { return event.reason; } } + }); return !util.global.dispatchEvent(domEvent); }; } else { From 0da7d15c7241857fc2b853393fb8dd1ab3bbd5d7 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 5 Oct 2017 16:38:26 -0700 Subject: [PATCH 3/3] Use the es5.defineProperty shim --- src/debuggability.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/debuggability.js b/src/debuggability.js index cf5aafce2..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,16 +155,13 @@ var fireDomEvent = (function() { var event = new CustomEvent("CustomEvent"); util.global.dispatchEvent(event); return function(name, event) { - var promise = event.promise; - var reason = event.reason; var eventData = { detail: event, cancelable: true }; - Object.defineProperties(eventData, { - promise: { get: function() { return promise; } }, - reason: { get: function() { return reason; } } - }); + 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); }; @@ -177,10 +175,8 @@ var fireDomEvent = (function() { cancelable: true }); domEvent.detail = event; - Object.defineProperties(domEvent, { - promise: { get: function() { return event.promise; } }, - reason: { get: function() { return event.reason; } } - }); + es5.defineProperty(domEvent, "promise", {value: event.promise}); + es5.defineProperty(domEvent, "reason", {value: event.reason}); return !util.global.dispatchEvent(domEvent); }; } else {