superDotOSBug3930962.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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 sym1 = Symbol("bart");
  7. var count = 0;
  8. class A {
  9. constructor() {
  10. count++;
  11. }
  12. increment() {
  13. count++;
  14. }
  15. decrement() {
  16. count--;
  17. }
  18. getCount()
  19. {
  20. return count;
  21. }
  22. 1() { return 1; }
  23. 2() { return 2; }
  24. 1.1() { return 1.1; }
  25. 2.2() { return 2.2; }
  26. [1+3]() { return 4; }
  27. [1.1+1]() { return 2.1; }
  28. ["foo"+1]() { return "foo1"; }
  29. [sym1](){return "bart";}
  30. }
  31. A.prototype.x = 42;
  32. A.prototype["y"] = 30;
  33. A.prototype[10] = 10;
  34. A.prototype[10.1] = 10.1;
  35. Object.defineProperty(A.prototype, "length", {writable : true, value : 2 });
  36. Object.defineProperty(A, "length", {writable : true, value : -1 });
  37. var tests = [
  38. {
  39. name: "Access length",
  40. body: function ()
  41. {
  42. class B extends A {
  43. constructor() {
  44. super();
  45. assert.areEqual(2, super.length, "confirm we can make dot property call to access A.prototype.length");
  46. var super_arrow = () => {
  47. assert.areEqual(2, super.length, "confirm we can make dot property call to access A.prototype.length when it is in a lambda");
  48. }
  49. super_arrow();
  50. }
  51. }
  52. var bar = new B();
  53. }
  54. },
  55. {
  56. name: "Access of property fields on super",
  57. body: function ()
  58. {
  59. class B extends A {
  60. constructor() {
  61. super();
  62. assert.areEqual(42, super.x, "confirm we can make dot property calls on non function types");
  63. assert.areEqual(42, super["x"], "confirm we can make index property calls of properties defined as dot properties");
  64. assert.areEqual(30, super["y"], "confirm we can make index property calls on string properties promoted to dot properties");
  65. assert.areEqual(10, super[10], "confirm we can make index property calls on integer properties");
  66. assert.areEqual(10.1, super[10.1], "confirm we can make index property calls on float point properties");
  67. assert.areEqual(10, super["10"], "confirm we can make index property calls on integer properties accessed as strings");
  68. assert.areEqual(10.1, super["10.1"], "confirm we can make index property calls on float point properties accessed as strings");
  69. }
  70. }
  71. var bar = new B();
  72. }
  73. },
  74. {
  75. name: "Access of property fields on super in a lambda",
  76. body: function ()
  77. {
  78. class B extends A {
  79. constructor() {
  80. super();
  81. var super_arrow = () => {
  82. assert.areEqual(42, super.x, "confirm we can make dot property calls on non function types");
  83. assert.areEqual(42, super["x"], "confirm we can make index property calls of properties defined as dot properties");
  84. assert.areEqual(30, super["y"], "confirm we can make index property calls on string properties promoted to dot properties");
  85. assert.areEqual(10, super[10], "confirm we can make index property calls on integer properties");
  86. assert.areEqual(10.1, super[10.1], "confirm we can make index property calls on float point properties");
  87. assert.areEqual(10, super["10"], "confirm we can make index property calls on integer properties accessed as strings");
  88. assert.areEqual(10.1, super["10.1"], "confirm we can make index property calls on float point properties accessed as strings");
  89. }
  90. super_arrow();
  91. }
  92. }
  93. var bar = new B();
  94. }
  95. },
  96. {
  97. name: "Access of property fields on super in a lambda with super also inside the lambda",
  98. body: function ()
  99. {
  100. class B extends A {
  101. constructor() {
  102. var super_arrow = () => {
  103. super();
  104. assert.areEqual(42, super.x, "confirm we can make dot property calls on non function types");
  105. assert.areEqual(42, super["x"], "confirm we can make index property calls of properties defined as dot properties");
  106. assert.areEqual(30, super["y"], "confirm we can make index property calls on string properties promoted to dot properties");
  107. assert.areEqual(10, super[10], "confirm we can make index property calls on integer properties");
  108. assert.areEqual(10.1, super[10.1], "confirm we can make index property calls on float point properties");
  109. assert.areEqual(10, super["10"], "confirm we can make index property calls on integer properties accessed as strings");
  110. assert.areEqual(10.1, super["10.1"], "confirm we can make index property calls on float point properties accessed as strings");
  111. }
  112. super_arrow();
  113. }
  114. }
  115. var bar = new B();
  116. }
  117. },
  118. {
  119. name: "lamda call on super before making a super call",
  120. body: function ()
  121. {
  122. count = 0;
  123. class B extends A {
  124. constructor() {
  125. var super_arrow = () => {
  126. assert.throws(()=>{ super.increment(); }, ReferenceError, "Use before declaration");
  127. assert.areEqual(0,count,"We should not have incremented");
  128. assert.throws(()=>{ super.increment.call(5); }, ReferenceError, "Use before declaration");
  129. assert.throws(()=>{ super[1](); }, ReferenceError, "Use before declaration");
  130. assert.throws(()=>{ super[1].call(5); }, ReferenceError, "Use before declaration");
  131. super();
  132. }
  133. super_arrow();
  134. }
  135. }
  136. var bar = new B();
  137. }
  138. },
  139. {
  140. name: "super.<method>.call",
  141. body: function ()
  142. {
  143. count = 0;
  144. class B extends A {
  145. constructor() {
  146. super();
  147. var super_arrow = () => {
  148. super.increment.call(this);
  149. assert.areEqual(2,super.getCount.call(this), "confirm we can make the the method call on class A's method inside a lambda");
  150. assert.areEqual(1,super[1].call(this), "confirm we can make index method call on class A's method inside a lambda");
  151. }
  152. super_arrow();
  153. super.decrement.call(this);
  154. assert.areEqual(1,super.getCount.call(this),"confirm we can make the the method call on class A's method");
  155. assert.areEqual(2,super[2].call(this), "confirm we can make index method call on class A's method");
  156. }
  157. }
  158. var bar = new B();
  159. }
  160. },
  161. {
  162. name: "lamda super dot calls",
  163. body: function ()
  164. {
  165. count = 0;
  166. class B extends A {
  167. constructor() {
  168. var super_arrow = () => {
  169. super();
  170. assert.areEqual(1,super.getCount(),"confirm we can make the the method call on class A's method");
  171. super.increment();
  172. assert.areEqual(2, super.getCount(), "confirm we can make the the method call on class A's method");
  173. super.decrement();
  174. assert.areEqual(1, super.getCount(), "confirm we can make the the method call on class A's method");
  175. }
  176. super_arrow();
  177. }
  178. }
  179. var bar = new B();
  180. }
  181. },
  182. {
  183. name: "lamda super string index calls",
  184. body: function ()
  185. {
  186. count = 0;
  187. class B extends A {
  188. constructor() {
  189. var super_arrow = () => {
  190. super();
  191. assert.areEqual(1,super["getCount"](), "confirm we can make the the method call on class A's method");
  192. super["increment"]();
  193. assert.areEqual(2, super["getCount"](), "confirm we can make the the method call on class A's method");
  194. super["decrement"]();
  195. assert.areEqual(1, super["getCount"](), "confirm we can make the the method call on class A's method");
  196. }
  197. super_arrow();
  198. }
  199. }
  200. var bar = new B();
  201. }
  202. },
  203. {
  204. name: "lambda super double index calls",
  205. body: function ()
  206. {
  207. class B extends A {
  208. constructor() {
  209. var super_arrow = () => {
  210. super();
  211. assert.areEqual(1.1,super[1.1](), "confirm we can make the the method call on class A's method");
  212. assert.areEqual(2.2, super[2.2](), "confirm we can make the the method call on class A's method");
  213. }
  214. super_arrow();
  215. }
  216. }
  217. var bar = new B();
  218. }
  219. },
  220. {
  221. name: "lambda super int index calls",
  222. body: function ()
  223. {
  224. class B extends A {
  225. constructor() {
  226. var super_arrow = () => {
  227. super();
  228. assert.areEqual(1,super[1](), "confirm we can make the the method call on class A's method");
  229. assert.areEqual(2, super[2](), "confirm we can make the the method call on class A's method");
  230. }
  231. super_arrow();
  232. }
  233. }
  234. var bar = new B();
  235. }
  236. },
  237. {
  238. name: "lamda super computed property double index calls",
  239. body: function ()
  240. {
  241. class B extends A {
  242. constructor() {
  243. var super_arrow = () => {
  244. super();
  245. assert.areEqual(2.1,super[2.1](), "confirm we can make the the method call on class A's method");
  246. }
  247. super_arrow();
  248. }
  249. }
  250. var bar = new B();
  251. }
  252. },
  253. {
  254. name: "lamda super computed property int index calls",
  255. body: function ()
  256. {
  257. class B extends A {
  258. constructor() {
  259. super();
  260. assert.areEqual(4,super[4](), "confirm we can make the the method call on class A's method");
  261. }
  262. }
  263. var bar = new B();
  264. }
  265. },
  266. {
  267. name: "lamda super computed property string concatenated to integer index calls",
  268. body: function ()
  269. {
  270. class B extends A {
  271. constructor() {
  272. var super_arrow = () => {
  273. super();
  274. assert.areEqual("foo1",super["foo1"](), "confirm we can make the the method call on class A's method");
  275. }
  276. super_arrow();
  277. }
  278. }
  279. var bar = new B();
  280. }
  281. },
  282. {
  283. name: "lamda super computed property Symbol index calls",
  284. body: function ()
  285. {
  286. class B extends A {
  287. constructor() {
  288. var super_arrow = () => {
  289. super();
  290. assert.areEqual("bart",super[sym1](), "confirm we can make the the method call on class A's method");
  291. }
  292. super_arrow();
  293. }
  294. }
  295. var bar = new B();
  296. }
  297. },
  298. {
  299. name: "regular super dot calls",
  300. body: function ()
  301. {
  302. count = 0;
  303. class B extends A {
  304. constructor() {
  305. super();
  306. assert.areEqual(1,super.getCount(), "confirm we can make the the method call on class A's method");
  307. super.increment();
  308. assert.areEqual(2, super.getCount(), "confirm we can make the the method call on class A's method");
  309. super.decrement();
  310. assert.areEqual(1, super.getCount(), "confirm we can make the the method call on class A's method");
  311. }
  312. }
  313. var bar = new B();
  314. }
  315. },
  316. {
  317. name: "regular super string index calls",
  318. body: function ()
  319. {
  320. count = 0;
  321. class B extends A {
  322. constructor() {
  323. super();
  324. assert.areEqual(1,super["getCount"](), "confirm we can make the the method call on class A's method");
  325. super["increment"]();
  326. assert.areEqual(2, super["getCount"](), "confirm we can make the the method call on class A's method");
  327. super["decrement"]();
  328. assert.areEqual(1, super["getCount"](), "confirm we can make the the method call on class A's method");
  329. }
  330. }
  331. var bar = new B();
  332. }
  333. },
  334. {
  335. name: "regular super double index calls",
  336. body: function ()
  337. {
  338. class B extends A {
  339. constructor() {
  340. super();
  341. assert.areEqual(1.1,super[1.1](), "confirm we can make the the method call on class A's method");
  342. assert.areEqual(2.2, super[2.2](), "confirm we can make the the method call on class A's method");
  343. }
  344. }
  345. var bar = new B();
  346. }
  347. },
  348. {
  349. name: "regular super int index calls",
  350. body: function ()
  351. {
  352. class B extends A {
  353. constructor() {
  354. super();
  355. assert.areEqual(1,super[1](), "confirm we can make the the method call on class A's method");
  356. assert.areEqual(2, super[2](), "confirm we can make the the method call on class A's method");
  357. }
  358. }
  359. var bar = new B();
  360. }
  361. },
  362. {
  363. name: "regular super computed property double index calls",
  364. body: function ()
  365. {
  366. class B extends A {
  367. constructor() {
  368. super();
  369. assert.areEqual(2.1,super[2.1](), "confirm we can make the the method call on class A's method");
  370. }
  371. }
  372. var bar = new B();
  373. }
  374. },
  375. {
  376. name: "regular super computed property int index calls",
  377. body: function ()
  378. {
  379. class B extends A {
  380. constructor() {
  381. super();
  382. assert.areEqual(4,super[4](), "confirm we can make the the method call on class A's method");
  383. }
  384. }
  385. var bar = new B();
  386. }
  387. },
  388. {
  389. name: "regular super computed property string concatenated to integer index calls",
  390. body: function ()
  391. {
  392. class B extends A {
  393. constructor() {
  394. super();
  395. assert.areEqual("foo1",super["foo1"](), "confirm we can make the the method call on class A's method");
  396. }
  397. }
  398. var bar = new B();
  399. }
  400. },
  401. {
  402. name: "regular super computed property Symbol index calls",
  403. body: function ()
  404. {
  405. class B extends A {
  406. constructor() {
  407. super();
  408. assert.areEqual("bart",super[sym1](), "confirm we can make the the method call on class A's method");
  409. }
  410. }
  411. var bar = new B();
  412. }
  413. }
  414. ];
  415. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });