boundBug3837520.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. function correctProtoBound(proto, functionType) {
  7. Object.setPrototypeOf(functionType, proto);
  8. var boundF = Function.prototype.bind.call(functionType, null);
  9. return Object.getPrototypeOf(boundF) === proto;
  10. }
  11. var tests = [
  12. {
  13. name: "Basic Function",
  14. body: function ()
  15. {
  16. var f = function(){};
  17. var a = correctProtoBound(Function.prototype, f) && correctProtoBound({}, f)
  18. && correctProtoBound(null, f);
  19. assert.isTrue(a, "confirm Let proto be targetFunction.[[GetPrototypeOf]](). is performed on basic functions");
  20. }
  21. },
  22. {
  23. name: "Generator Functions",
  24. body: function ()
  25. {
  26. var gf = function*(){};
  27. var a = correctProtoBound(Function.prototype, gf) && correctProtoBound({}, gf)
  28. && correctProtoBound(null, gf);
  29. assert.isTrue(a, "confirm Let proto be targetFunction.[[GetPrototypeOf]](). is performed on generator functions");
  30. }
  31. },
  32. {
  33. name: "Arrow Functions",
  34. body: function ()
  35. {
  36. var arrowfunction = ()=>5;
  37. var a = correctProtoBound(Function.prototype, arrowfunction) && correctProtoBound({}, arrowfunction)
  38. && correctProtoBound(null, arrowfunction);
  39. assert.isTrue(a, "confirm Let proto be targetFunction.[[GetPrototypeOf]](). is performed on arrow functions");
  40. }
  41. },
  42. {
  43. name: "Classes",
  44. body: function ()
  45. {
  46. class C {}
  47. var a = correctProtoBound(Function.prototype, C) && correctProtoBound({}, C)
  48. && correctProtoBound(null, C);
  49. assert.isTrue(a, "confirm Let proto be targetFunction.[[GetPrototypeOf]](). is performed on classes");
  50. }
  51. },
  52. {
  53. name: "subClasses",
  54. body: function ()
  55. {
  56. function correctProtoBound(superclass) {
  57. class C extends superclass {
  58. constructor() {
  59. return Object.create(null);
  60. }
  61. }
  62. var boundF = Function.prototype.bind.call(C, null);
  63. return Object.getPrototypeOf(boundF) === Object.getPrototypeOf(C);
  64. }
  65. var a = correctProtoBound(Array) && correctProtoBound(null) &&
  66. correctProtoBound(function() {});
  67. assert.isTrue(a, "confirm Let proto be targetFunction.[[GetPrototypeOf]](). is performed on subclasses");
  68. }
  69. },
  70. {
  71. name: "Proxy Function",
  72. body: function ()
  73. {
  74. function correctProtoBound(proto) {
  75. var p = new Proxy(function(){}, {});
  76. Object.setPrototypeOf(p, proto);
  77. var boundF = Function.prototype.bind.call(p, null);
  78. return Object.getPrototypeOf(boundF) === proto;
  79. }
  80. var a = correctProtoBound(Function.prototype) && correctProtoBound({});
  81. //&& correctProtoBound(null); proxy bug on setPrototypeOf for this case OS bug# 3842393
  82. assert.isTrue(a, "confirm Let proto be targetFunction.[[GetPrototypeOf]](). is performed on proxy functions");
  83. }
  84. }
  85. ];
  86. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });