es5Array.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. var x = [];
  6. x[2] = 5;
  7. x.foo = 3;
  8. Object.defineProperty(x, '1', {
  9. get: function () { return this.foo + 1; },
  10. set: function (x) { this.foo = x / 2; }
  11. });
  12. Object.defineProperty(x, 11, {
  13. get: function () { return this.foo; }
  14. });
  15. var simpleArrayEmptyLength = [];
  16. Object.defineProperty(simpleArrayEmptyLength, "length", {});
  17. var aFixedInfo = [0, 1, 2, 3, 4, 5];
  18. Object.defineProperty(aFixedInfo, "length", { writable: false });
  19. Object.defineProperty(aFixedInfo, "2", { writable: false });
  20. var aFrozen = [0, 1, 2, 3, 4, 5];
  21. Object.freeze(aFrozen);
  22. var oIncFreeze = [0, 1, 2, 3, 4, 5];
  23. for (var i = 0; i < oIncFreeze.length; i++)
  24. {
  25. Object.defineProperty(oIncFreeze, i, { writable: false, configurable: false });
  26. }
  27. Object.preventExtensions(oIncFreeze);
  28. WScript.SetTimeout(testFunction, 50);
  29. /////////////////
  30. function testFunction()
  31. {
  32. telemetryLog(`Array.isArray(x): ${Array.isArray(x)}`, true); //true
  33. telemetryLog(`x.foo: ${x.foo}`, true); //3
  34. telemetryLog(`x[1]: ${x[1]}`, true); //4
  35. telemetryLog(`x[11]: ${x[11]}`, true); //3
  36. ////
  37. x[1] = 12;
  38. ////
  39. telemetryLog(`x[1]: ${x[1]}`, true); //7
  40. telemetryLog(`x[11]: ${x[11]}`, true); //6
  41. ////
  42. telemetryLog(`Object.getOwnPropertyDescriptor(simpleArrayEmptyLength.length): ${JSON.stringify(Object.getOwnPropertyDescriptor(simpleArrayEmptyLength, "length"))}`, true); //asdf
  43. aFixedInfo[9] = 9; // This would throw in strict mode
  44. telemetryLog(`aFixedInfo: ${JSON.stringify(aFixedInfo)}`, true); //0, 1, 2, 3, 4, 5
  45. aFixedInfo[1] = -1;
  46. aFixedInfo[2] = -2;
  47. telemetryLog(`aFixedInfo: ${JSON.stringify(aFixedInfo)}`, true); //0, 1, 2, 3, 4, 5
  48. telemetryLog(`Object.getOwnPropertyDescriptor(aFrozen.length): ${JSON.stringify(Object.getOwnPropertyDescriptor(aFrozen, "length"))}`, true); //asdf
  49. telemetryLog(`isFrozen: ${Object.isFrozen(oIncFreeze)}`, true); // false, because length writable
  50. Object.defineProperty(oIncFreeze, "length", { writable: false });
  51. telemetryLog(`isFrozen: ${Object.isFrozen(oIncFreeze)}`, true);
  52. emitTTDLog(ttdLogURI);
  53. }