promises.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*!
  2. {
  3. "name": "ES6 Promises",
  4. "property": "promises",
  5. "caniuse": "promises",
  6. "polyfills": ["es6promises"],
  7. "authors": ["Krister Kari", "Jake Archibald"],
  8. "tags": ["es6"],
  9. "notes": [{
  10. "name": "The ES6 promises spec",
  11. "href": "https://github.com/domenic/promises-unwrapping"
  12. },{
  13. "name": "Chromium dashboard - ES6 Promises",
  14. "href": "https://www.chromestatus.com/features/5681726336532480"
  15. },{
  16. "name": "JavaScript Promises: an Introduction",
  17. "href": "https://developers.google.com/web/fundamentals/primers/promises/"
  18. }]
  19. }
  20. !*/
  21. /* DOC
  22. Check if browser implements ECMAScript 6 Promises per specification.
  23. */
  24. define(['Modernizr'], function(Modernizr) {
  25. Modernizr.addTest('promises', function() {
  26. return 'Promise' in window &&
  27. // Some of these methods are missing from
  28. // Firefox/Chrome experimental implementations
  29. 'resolve' in window.Promise &&
  30. 'reject' in window.Promise &&
  31. 'all' in window.Promise &&
  32. 'race' in window.Promise &&
  33. // Older version of the spec had a resolver object
  34. // as the arg rather than a function
  35. (function() {
  36. var resolve;
  37. new window.Promise(function(r) { resolve = r; });
  38. return typeof resolve === 'function';
  39. }());
  40. });
  41. });