ES6Function_bugs.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // ES6 Function unit tests from bugfixes
  6. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. var tests = [
  8. {
  9. name: "OS1558391: assignment to 'length' after defineProperty with getter function should not trigger assertion",
  10. body: function() {
  11. function f() { }
  12. Object.defineProperty(f, 'length', {
  13. get: function () { }
  14. });
  15. assert.doesNotThrow(function () { f.length = 1; }, "assertion failure on assignment to 'length' after defineProperty with getter");
  16. }
  17. },
  18. {
  19. name: "OS1616633: defineProperty with getter function after sealing a function object should not trigger assertion",
  20. body: function() {
  21. function g(name) {
  22. var f=function () { }
  23. Object.seal(f);
  24. Object.defineProperty(f, name, {
  25. get: function () { }
  26. });
  27. }
  28. assert.doesNotThrow(function () { g('length') }, "assertion failure on defineProperty 'length' with getter after sealing a function object");
  29. assert.throws(function () { g('arguments') }, TypeError, "Cannot redefine non-configurable property 'arguments'");
  30. assert.throws(function () { g('caller') }, TypeError, "Cannot redefine non-configurable property 'caller'");
  31. }
  32. },
  33. {
  34. name: "OS1658052: defineProperty with value after sealing a function object should not trigger assertion",
  35. body: function() {
  36. function g(name) {
  37. var f=function () { }
  38. Object.seal(f);
  39. Object.defineProperty(f, name, {
  40. value: 0
  41. });
  42. }
  43. assert.doesNotThrow(function () { g('length') }, "assertion failure on defineProperty 'length' with value after sealing a function object");
  44. assert.throws(function () { g('arguments') }, TypeError, "Cannot redefine non-configurable property 'arguments'");
  45. assert.throws(function () { g('caller') }, TypeError, "Cannot redefine non-configurable property 'caller'");
  46. }
  47. },
  48. {
  49. name: "OS1893544: defineProperty with {writable: false, configurable:true} after defineProperty with getter on a function object should not trigger assertion",
  50. body: function() {
  51. function g(name) {
  52. var f=function () { }
  53. Object.defineProperty(f, name, {
  54. get: function () { },
  55. });
  56. Object.defineProperty(f, name, {
  57. writable: false,
  58. configurable: true
  59. });
  60. }
  61. assert.doesNotThrow(function () { g('length') }, "assertion failure on defineProperty 'length' with {writable: false, configurable:true} after defineProperty with getter on a function object");
  62. assert.throws(function () { g('arguments') }, TypeError, "Cannot redefine non-configurable property 'arguments'");
  63. assert.throws(function () { g('caller') }, TypeError, "Cannot redefine non-configurable property 'caller'");
  64. }
  65. },
  66. ];
  67. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });