join2.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v); }
  6. Object.prototype.join = Array.prototype.join;
  7. var n = 10;
  8. var a = new Array();
  9. var o = new Object();
  10. for (var i=0; i<10; i++) {
  11. o[i] = a[i] = i * i + 1;
  12. }
  13. write(o.join());
  14. write(o.join(undefined));
  15. write(o.join("hello"));
  16. write(a.join(a));
  17. write(o.join(a));
  18. write(a.join(o));
  19. write(o.join(o));
  20. write(Array.prototype.join.call(a, a));
  21. write(Array.prototype.join.call(o, a));
  22. write(Array.prototype.join.call(a, o));
  23. write(Array.prototype.join.call(o, o));
  24. //implicit calls
  25. var a ;
  26. var arr = [10];
  27. Object.defineProperty(Array.prototype, "4", {configurable : true, get: function(){a = true; return 30;}});
  28. a = false;
  29. arr.length = 6;
  30. var f = arr.join();
  31. WScript.Echo(a);
  32. Object.prototype['length'] = 2;
  33. WScript.Echo(([""].join).call(5));
  34. Object.prototype['0'] = "test";
  35. WScript.Echo(([""].join).call(5.5));