callerOrArgsNoAccess.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 test1() {
  6. function foo () {
  7. "use strict";
  8. }
  9. function bar () {
  10. function baz () {
  11. "use strict";
  12. }
  13. }
  14. try {
  15. foo.caller; // should throw TypeError
  16. return false;
  17. }
  18. catch (e) {
  19. bar.caller; // should pass
  20. return e instanceof TypeError;
  21. }
  22. }
  23. function test2() {
  24. function foo () {
  25. "use strict";
  26. }
  27. function bar () {
  28. function baz () {
  29. "use strict";
  30. }
  31. }
  32. try {
  33. foo.caller = 42; // should throw TypeError
  34. return false;
  35. }
  36. catch (e) {
  37. bar.caller = 42; // should pass
  38. return e instanceof TypeError;
  39. }
  40. }
  41. function test3() {
  42. function foo () {
  43. "use strict";
  44. }
  45. function bar () {
  46. function baz () {
  47. "use strict";
  48. }
  49. }
  50. try {
  51. foo.arguments; // should throw TypeError
  52. return false;
  53. }
  54. catch (e) {
  55. bar.arguments; // should pass
  56. return e instanceof TypeError;
  57. }
  58. }
  59. function test4() {
  60. function foo () {
  61. "use strict";
  62. }
  63. function bar () {
  64. function baz () {
  65. "use strict";
  66. }
  67. }
  68. try {
  69. foo.arguments = 42; // should throw TypeError
  70. return false;
  71. }
  72. catch (e) {
  73. bar.arguments = 42; // should pass
  74. return e instanceof TypeError;
  75. }
  76. }
  77. // The following statements should pass.
  78. test1.caller;
  79. test2.caller = 42;
  80. test3.arguments;
  81. test4.arguments = 42;
  82. // The following statements should print "true".
  83. var echo = WScript.Echo;
  84. echo(test1());
  85. echo(test2());
  86. echo(test3());
  87. echo(test4());