push3.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
  4. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. //-------------------------------------------------------------------------------------------------------
  6. function confirmThrows(call, errorType)
  7. {
  8. var success = false;
  9. try {
  10. call();
  11. } catch (e) {
  12. if (e instanceof errorType) {
  13. success = true;
  14. }
  15. }
  16. if (!success) {
  17. throw new Error ("Test was meant to throw " + errorType + "but it didn't")
  18. }
  19. }
  20. function test0() {
  21. var GiantPrintArray = [];
  22. var obj1 = {};
  23. function v9870() {
  24. var arr = [];
  25. var v9872 = [];
  26. Object.defineProperty(Array.prototype, "0", { configurable: true, get: function () { return 30; } });
  27. GiantPrintArray.push(v9872.indexOf(30));
  28. }
  29. confirmThrows(v9870, TypeError);
  30. if (GiantPrintArray[0] !== 30) {
  31. throw new Error('Wrong value set');
  32. }
  33. };
  34. test0();
  35. test0();
  36. function test1() {
  37. var arr = [];
  38. Object.preventExtensions(arr);
  39. arr.push(0);
  40. }
  41. confirmThrows(test1, TypeError);
  42. confirmThrows(test1, TypeError);
  43. Object.defineProperty(Object.prototype,"a",{get:function(){return 8 }});
  44. function test2() {
  45. var GiantPrintArray = [];
  46. var obj1 = {};
  47. var func1 = function(){
  48. GiantPrintArray.push(obj1.a);
  49. }
  50. confirmThrows(func1, TypeError);
  51. function v31079()
  52. {
  53. Object.defineProperty(Array.prototype, "4", {configurable : true, get: function(){return 15;}});
  54. GiantPrintArray.push(1);
  55. GiantPrintArray.push(1);
  56. }
  57. confirmThrows(v31079, TypeError);
  58. confirmThrows(v31079, TypeError);
  59. if (GiantPrintArray.length > 0) {
  60. throw new Error ("Length should be 0");
  61. }
  62. }
  63. test2();
  64. test2();
  65. print("pass");