bug14323330.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. var r = typeof this;
  6. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. var tests = [
  8. {
  9. name: "typeof global this is 'object'",
  10. body: function () {
  11. assert.areEqual('object', r, "'typeof this' is 'object' for the global this");
  12. }
  13. },
  14. {
  15. name: "typeof nested function this",
  16. body: function () {
  17. function foo() {
  18. return typeof this;
  19. }
  20. assert.areEqual('object', foo(), "'typeof this' is 'object' for nested function this called with default 'this' binding");
  21. assert.areEqual('function', foo.call(foo), "'typeof this' should be 'function' when 'this' binding is overriden");
  22. function bar() {
  23. "use strict";
  24. return typeof this;
  25. }
  26. assert.areEqual('undefined', bar(), "'typeof this' is 'undefined' for nested strict function this called with default 'this' binding");
  27. assert.areEqual('function', bar.call(bar), "'typeof this' should be 'function' when 'this' binding is overriden");
  28. }
  29. },
  30. {
  31. name: "typeof nested function new.target",
  32. body: function () {
  33. var out = 'wrong';
  34. function foo() {
  35. out = typeof new.target;
  36. }
  37. foo();
  38. assert.areEqual('undefined', out, "'typeof new.target' is 'undefined' for normal function call");
  39. new foo();
  40. assert.areEqual('function', out, "'typeof new.target' is 'function' for function called as constructor");
  41. }
  42. },
  43. ];
  44. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });