es5_defineProperty_arrayLength.js 898 B

123456789101112131415161718192021222324252627282930
  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 check(val, equals, msg) {
  6. if(val !== equals) {
  7. throw new Error(msg);
  8. }
  9. }
  10. function test () {
  11. var arr = [1, 2, 3, 4];
  12. Object.defineProperty(arr, 1, {configurable: false});
  13. for(var i = 0; i < 80; i++) {
  14. if(!arr.length) {
  15. arr[0] = -1;
  16. }
  17. else {
  18. arr.length = 0;
  19. check(arr.length, 2, "cannot delete a non-configurable property");
  20. }
  21. }
  22. }
  23. for(var j = 0; j < 80; j++) {
  24. test();
  25. }
  26. print("PASS");