CheckThis.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // Flavors of inlined LdThis, some of which will bail out if we force the optimization.
  6. (function () {
  7. function f() {
  8. return this.foo();
  9. }
  10. var t = this;
  11. var x = { foo: function () { WScript.Echo(this); } };
  12. x.f = f;
  13. x.f();
  14. try {
  15. f();
  16. }
  17. catch (e) {
  18. WScript.Echo(e.message);
  19. }
  20. WScript.Echo(t === this);
  21. })();
  22. (function () {
  23. function f(o) {
  24. return o.foo();
  25. }
  26. var x = { foo: function () { WScript.Echo(this); } };
  27. f(x);
  28. })();
  29. function test() {
  30. Object.prototype['foo'] = function () {return this};
  31. var c = {}
  32. var x;
  33. x + c.foo("a");
  34. ((function(){
  35. return 1;
  36. })()).foo()
  37. };
  38. WScript.Echo(test());
  39. WScript.Echo(test());