test_on_promise_settled_duplicates.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <!--
  6. Bug 1084065 - Test that Debugger.prototype.onPromiseResolved doesn't get dupes.
  7. -->
  8. <html>
  9. <head>
  10. <title>Test for interaction with SpiderMonkey's Debugger.prototype.onNewPromise</title>
  11. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  12. <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  13. </head>
  14. <body>
  15. <p id="display"></p>
  16. <div id="content" style="display: none">
  17. </div>
  18. <pre id="test">
  19. <script type="application/javascript">
  20. SimpleTest.waitForExplicitFinish();
  21. is(Object.prototype.toString.call(new Promise(function () {})),
  22. "[object Promise]",
  23. "We should have the native DOM promise implementation.");
  24. var Cu = Components.utils;
  25. Cu.import("resource://gre/modules/jsdebugger.jsm");
  26. var dbgGlobal = new Cu.Sandbox(document.nodePrincipal);
  27. addDebuggerToGlobal(dbgGlobal);
  28. var dbg = new dbgGlobal.Debugger(this);
  29. var seen = new Set();
  30. dbg.onPromiseSettled = function (wp) {
  31. is(seen.has(wp), false);
  32. seen.add(wp);
  33. };
  34. var promise = new Promise(function (fulfill, reject) {
  35. fulfill(1);
  36. fulfill(2);
  37. fulfill(3);
  38. });
  39. promise
  40. .then(function () {
  41. dbg.onPromiseSettled = undefined;
  42. })
  43. .then(null, function (e) {
  44. ok(false, "Got an unexpected error: " + e);
  45. })
  46. .then(SimpleTest.finish);
  47. </script>
  48. </pre>
  49. </body>
  50. </html>