reflectConstructConsumeNewTarget.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  6. var tests = [
  7. {
  8. name: "Reflect.construct consumes new.target",
  9. body: function () {
  10. class myBaseClass {
  11. construct() {
  12. assert.areEqual(myNewTarget, new.target, "the main point of the test is to make sure myNewTarget is passed into the constructor as new.target");
  13. }
  14. }
  15. class myDerivedClass extends myBaseClass {
  16. }
  17. function myNewTarget() {
  18. }
  19. Reflect.construct(myDerivedClass, [], myNewTarget);
  20. }
  21. },
  22. {
  23. name: "Reflect.construct should throw a type error if new.target is not a constructor",
  24. body: function () {
  25. class myBaseClass {
  26. construct() {
  27. }
  28. }
  29. class myDerivedClass extends myBaseClass {
  30. }
  31. function myNewTarget() {
  32. }
  33. assert.throws(function () { Reflect.construct(myDerivedClass, [], undefined ) }, TypeError, "undefined is not a constructor", "'newTarget' is not a constructor");
  34. }
  35. }
  36. ];
  37. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });