misc_bugs.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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: "calling Symbol.toPrimitive on Date prototype should not AV",
  9. body: function () {
  10. Date.prototype[Symbol.toPrimitive].call({},'strin' + 'g');
  11. }
  12. },
  13. {
  14. name: "updated stackTraceLimit should not fire re-entrancy assert",
  15. body: function () {
  16. Error.__defineGetter__('stackTraceLimit', function () { return 1;});
  17. assert.throws(()=> Array.prototype.map.call([]));
  18. }
  19. },
  20. {
  21. name: "Array.prototype.slice should not fire re-entrancy error when the species returns proxy",
  22. body: function () {
  23. let arr = [1, 2];
  24. arr.__proto__ = {
  25. constructor: {
  26. [Symbol.species]: function () {
  27. return new Proxy({}, {
  28. defineProperty(...args) {
  29. return Reflect.defineProperty(...args);
  30. }
  31. });
  32. }
  33. }
  34. }
  35. Array.prototype.slice.call(arr);
  36. }
  37. },
  38. {
  39. name: "rest param under eval with arguments usage in the body should not fail assert",
  40. body: function () {
  41. f();
  42. function f() {
  43.     eval("function bar(...x){arguments;}")
  44. }
  45. }
  46. },
  47. {
  48. name: "Token left after parsing lambda result to the syntax error",
  49. body: function () {
  50. assert.throws(()=> { eval('function foo ([ [] = () => { } = {a2:z2}]) { };'); });
  51. }
  52. },
  53. {
  54. name: "Token left after parsing lambda in ternary operator should not throw",
  55. body: function () {
  56. assert.doesNotThrow(()=> { eval('function foo () { true ? e => {} : 1};'); });
  57. }
  58. },
  59. {
  60. name: "ArrayBuffer.slice with proxy constructor should not fail fast",
  61. body: function () {
  62. let arr = new ArrayBuffer(10);
  63. arr.constructor = new Proxy(ArrayBuffer, {});
  64. arr.slice(1,2);
  65. }
  66. },
  67. {
  68. name: "Large proxy chain should not cause IsConstructor to crash on stack overflow",
  69. body: function () {
  70. let p = new Proxy(Object, {});
  71. for (let i=0; i<20000; ++i)
  72. {
  73. p = new Proxy(p, {});
  74. }
  75. try
  76. {
  77. let a = new p();
  78. }
  79. catch(e)
  80. {
  81. }
  82. }
  83. },
  84. {
  85. name: "splice an array which has getter/setter at 4294967295 should not fail due to re-entrancy error",
  86. body: function () {
  87. var base = 4294967290;
  88. var arr = [];
  89. for (var i = 0; i < 10; i++) {
  90. arr[base + i] = 100 + i;
  91. }
  92. Object.defineProperty(arr, 4294967295, {
  93. get: function () { }, set : function(b) { }
  94. }
  95. );
  96. assert.throws(()=> {arr.splice(4294967290, 0, 200, 201, 202, 203, 204, 205, 206);});
  97. }
  98. },
  99. {
  100. name: "Passing args count near 2**16 should not fire assert (OS# 17406027)",
  101. body: function () {
  102. try {
  103. eval.call(...(new Array(2**16)));
  104. } catch (e) { }
  105. try {
  106. eval.call(...(new Array(2**16+1)));
  107. } catch (e) { }
  108. try {
  109. var sc1 = WScript.LoadScript(`function foo() {}`, "samethread");
  110. sc1.foo(...(new Array(2**16)));
  111. } catch(e) { }
  112. try {
  113. var sc2 = WScript.LoadScript(`function foo() {}`, "samethread");
  114. sc2.foo(...(new Array(2**16+1)));
  115. } catch(e) { }
  116. try {
  117. function foo() {}
  118. Reflect.construct(foo, new Array(2**16-3));
  119. } catch(e) { }
  120. try {
  121. function foo() {}
  122. Reflect.construct(foo, new Array(2**16-2));
  123. } catch(e) { }
  124. try {
  125. function foo() {}
  126. var bar = foo.bind({}, 1);
  127. new bar(...(new Array(2**16+1)))
  128. } catch(e) { }
  129. }
  130. },
  131. {
  132. name: "getPrototypeOf Should not be called when set as prototype",
  133. body: function () {
  134. var p = new Proxy({}, { getPrototypeOf: function() {
  135. assert.fail("this should not be called")
  136. return {};
  137. }});
  138. var obj = {};
  139. obj.__proto__ = p; // This should not call the getPrototypeOf
  140. var obj1 = {};
  141. Object.setPrototypeOf(obj1, p); // This should not call the getPrototypeOf
  142. var obj2 = {__proto__ : p}; // This should not call the getPrototypeOf
  143. }
  144. },
  145. {
  146. name: "Destructuring declaration should return undefined",
  147. body: function () {
  148. assert.areEqual(undefined, eval("var {x} = {};"));
  149. assert.areEqual(undefined, eval("let {x,y} = {};"));
  150. assert.areEqual(undefined, eval("const [z] = [];"));
  151. assert.areEqual(undefined, eval("let {x} = {}, y = 1, {z} = {};"));
  152. assert.areEqual([1], eval("let {x} = {}; [x] = [1]"));
  153. }
  154. },
  155. {
  156. name: "Strict Mode : throw type error when the handler returns falsy value",
  157. body: function () {
  158. assert.throws(() => {"use strict"; let p1 = new Proxy({}, { set() {}}); p1.foo = 1;}, TypeError, "returning undefined on set handler is return false which will throw type error", "Proxy set handler returned false");
  159. assert.throws(() => {"use strict"; let p1 = new Proxy({}, { deleteProperty() {}}); delete p1.foo;}, TypeError, "returning undefined on deleteProperty handler is return false which will throw type error", "Proxy deleteProperty handler returned false");
  160. assert.throws(() => {"use strict"; let p1 = new Proxy({}, { set() {return false;}}); p1.foo = 1;}, TypeError, "set handler is returning false which will throw type error", "Proxy set handler returned false");
  161. assert.throws(() => {"use strict"; let p1 = new Proxy({}, { deleteProperty() {return false;}}); delete p1.foo;}, TypeError, "deleteProperty handler is returning false which will throw type error", "Proxy deleteProperty handler returned false");
  162. }
  163. },
  164. {
  165. name: "Generator : testing recursion",
  166. body: function () {
  167. // This will throw out of stack error
  168. assert.throws(() => {
  169. function foo() {
  170. function *f() {
  171. yield foo();
  172. }
  173. f().next();
  174. }
  175. foo();
  176. });
  177. }
  178. },
  179. {
  180. name: "destructuring : testing recursion",
  181. body: function () {
  182. try {
  183. eval(`
  184. var ${'['.repeat(6631)}
  185. `);
  186. assert.fail();
  187. }
  188. catch (e) {
  189. }
  190. try {
  191. eval(`
  192. var {${'a:{'.repeat(6631)}
  193. `);
  194. assert.fail();
  195. }
  196. catch (e) {
  197. }
  198. }
  199. }
  200. ];
  201. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });