for-of.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. var ArrayIterator = require("../array")
  3. , slice = Array.prototype.slice;
  4. module.exports = function (t, a) {
  5. var i = 0, x = ["raz", "dwa", "trzy"], y = {}, called = 0;
  6. t(x, function () {
  7. a.deep(slice.call(arguments, 0, 1), [x[i]], "Array " + i + "#");
  8. a(this, y, "Array: context: " + i++ + "#");
  9. }, y);
  10. i = 0;
  11. t((function () {
  12. return arguments;
  13. }("raz", "dwa", "trzy")), function () {
  14. a.deep(slice.call(arguments, 0, 1), [x[i]], "Arguments" + i + "#");
  15. a(this, y, "Arguments: context: " + i++ + "#");
  16. }, y);
  17. i = 0;
  18. t(x = "foo", function () {
  19. a.deep(slice.call(arguments, 0, 1), [x[i]], "String " + i + "#");
  20. a(this, y, "Regular String: context: " + i++ + "#");
  21. }, y);
  22. i = 0;
  23. x = ["r", "💩", "z"];
  24. t("r💩z", function () {
  25. a.deep(slice.call(arguments, 0, 1), [x[i]], "String " + i + "#");
  26. a(this, y, "Unicode String: context: " + i++ + "#");
  27. }, y);
  28. i = 0;
  29. t(new ArrayIterator(x), function () {
  30. a.deep(slice.call(arguments, 0, 1), [x[i]], "Iterator " + i + "#");
  31. a(this, y, "Iterator: context: " + i++ + "#");
  32. }, y);
  33. t(x = ["raz", "dwa", "trzy"], function (value, doBreak) {
  34. ++called;
  35. return doBreak();
  36. });
  37. a(called, 1, "Break");
  38. };