bug_OS14880030.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. "use strict";
  6. var r = delete this;
  7. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  8. var tests = [
  9. {
  10. name: "Delete this in strict global code",
  11. body: function () {
  12. assert.isTrue(r, "We should have returned true from the global delete this above");
  13. }
  14. },
  15. {
  16. name: "Delete this in strict mode nested function",
  17. body: function () {
  18. function test() {
  19. "use strict";
  20. return delete this;
  21. }
  22. assert.isTrue(test(), "Delete this in strict nested function does nothing but returns true");
  23. }
  24. },
  25. {
  26. name: "Delete new.target in strict mode nested function",
  27. body: function () {
  28. function test() {
  29. "use strict";
  30. return delete new.target;
  31. }
  32. assert.isTrue(test(), "Delete new.target in strict nested function does nothing but returns true");
  33. }
  34. },
  35. {
  36. name: "Delete arguments in strict mode nested function",
  37. body: function () {
  38. function test() {
  39. "use strict";
  40. try {
  41. eval('delete arguments;');
  42. } catch(e) {
  43. return true;
  44. }
  45. return false;
  46. }
  47. assert.isTrue(test(), "Delete arguments in strict nested function should throw early SyntaxError");
  48. }
  49. },
  50. {
  51. name: "Delete user identifier in strict mode nested function",
  52. body: function () {
  53. function test() {
  54. "use strict";
  55. let a = 'a';
  56. try {
  57. eval('delete a;');
  58. } catch(e) {
  59. return true;
  60. }
  61. return false;
  62. }
  63. assert.isTrue(test(), "Delete user identifier in strict nested function should throw early SyntaxError");
  64. }
  65. },
  66. {
  67. name: "Delete user identifier in strict eval in strict mode nested function",
  68. body: function () {
  69. function test() {
  70. "use strict";
  71. try {
  72. eval(`
  73. function test5_eval() {
  74. "use strict";
  75. let a = 'a';
  76. delete a;
  77. }
  78. test5_eval();
  79. `);
  80. } catch(e) {
  81. return true;
  82. }
  83. return false;
  84. }
  85. assert.isTrue(test(), "Delete user identifier in strict nested function should throw early SyntaxError");
  86. }
  87. },
  88. ];
  89. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });