undefThis.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Tests to verify that "undefined" is passed as "this" to non-property-reference callees
  6. function echo(x) { WScript.Echo(x + ''); }
  7. try {
  8. echo((1, Object.prototype.valueOf)());
  9. }
  10. catch (e) {
  11. echo(e);
  12. }
  13. try {
  14. var foo = Object.prototype.valueOf;
  15. echo(foo());
  16. }
  17. catch (e) {
  18. echo(e);
  19. }
  20. (function () {
  21. try {
  22. echo((1, Object.prototype.valueOf)());
  23. }
  24. catch (e) {
  25. echo(e);
  26. }
  27. try {
  28. var foo = Object.prototype.valueOf;
  29. echo(foo());
  30. }
  31. catch (e) {
  32. echo(e);
  33. }
  34. })();
  35. function f1() {
  36. "use strict";
  37. var f1a = function () {
  38. echo(this === undefined);
  39. }
  40. f1a();
  41. }
  42. f1();
  43. function f2() {
  44. function f2a() {
  45. "use strict";
  46. echo(this === undefined);
  47. }
  48. f2a();
  49. }
  50. f2();
  51. function x() {
  52. "use strict";
  53. echo(this);
  54. }
  55. x.bind()();