aboutsummaryrefslogtreecommitdiff
path: root/node_modules/when/es6-shim/Promise.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/when/es6-shim/Promise.js')
-rw-r--r--node_modules/when/es6-shim/Promise.js52
1 files changed, 40 insertions, 12 deletions
diff --git a/node_modules/when/es6-shim/Promise.js b/node_modules/when/es6-shim/Promise.js
index 4441fde2b..655a3b447 100644
--- a/node_modules/when/es6-shim/Promise.js
+++ b/node_modules/when/es6-shim/Promise.js
@@ -252,8 +252,8 @@ define(function(require) {
}
function hasMutationObserver () {
- return (typeof MutationObserver === 'function' && MutationObserver) ||
- (typeof WebKitMutationObserver === 'function' && WebKitMutationObserver);
+ return (typeof MutationObserver !== 'undefined' && MutationObserver) ||
+ (typeof WebKitMutationObserver !== 'undefined' && WebKitMutationObserver);
}
function initMutationObserver(MutationObserver) {
@@ -1220,6 +1220,28 @@ define(function() {
function noop() {}
+ function hasCustomEvent() {
+ if(typeof CustomEvent === 'function') {
+ try {
+ var ev = new CustomEvent('unhandledRejection');
+ return ev instanceof CustomEvent;
+ } catch (ignoredException) {}
+ }
+ return false;
+ }
+
+ function hasInternetExplorerCustomEvent() {
+ if(typeof document !== 'undefined' && typeof document.createEvent === 'function') {
+ try {
+ // Try to create one event to make sure it's supported
+ var ev = document.createEvent('CustomEvent');
+ ev.initCustomEvent('eventType', false, true, {});
+ return true;
+ } catch (ignoredException) {}
+ }
+ return false;
+ }
+
function initEmitRejection() {
/*global process, self, CustomEvent*/
if(typeof process !== 'undefined' && process !== null
@@ -1233,15 +1255,9 @@ define(function() {
? process.emit(type, rejection.value, rejection)
: process.emit(type, rejection);
};
- } else if(typeof self !== 'undefined' && typeof CustomEvent === 'function') {
- return (function(noop, self, CustomEvent) {
- var hasCustomEvent = false;
- try {
- var ev = new CustomEvent('unhandledRejection');
- hasCustomEvent = ev instanceof CustomEvent;
- } catch (e) {}
-
- return !hasCustomEvent ? noop : function(type, rejection) {
+ } else if(typeof self !== 'undefined' && hasCustomEvent()) {
+ return (function (self, CustomEvent) {
+ return function (type, rejection) {
var ev = new CustomEvent(type, {
detail: {
reason: rejection.value,
@@ -1253,7 +1269,19 @@ define(function() {
return !self.dispatchEvent(ev);
};
- }(noop, self, CustomEvent));
+ }(self, CustomEvent));
+ } else if(typeof self !== 'undefined' && hasInternetExplorerCustomEvent()) {
+ return (function(self, document) {
+ return function(type, rejection) {
+ var ev = document.createEvent('CustomEvent');
+ ev.initCustomEvent(type, false, true, {
+ reason: rejection.value,
+ key: rejection
+ });
+
+ return !self.dispatchEvent(ev);
+ };
+ }(self, document));
}
return noop;