| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
- var sym1 = Symbol("bart");
- var count = 0;
- class A {
- constructor() {
- count++;
- }
- increment() {
- count++;
- }
- decrement() {
- count--;
- }
- getCount()
- {
- return count;
- }
- 1() { return 1; }
- 2() { return 2; }
- 1.1() { return 1.1; }
- 2.2() { return 2.2; }
- [1+3]() { return 4; }
- [1.1+1]() { return 2.1; }
- ["foo"+1]() { return "foo1"; }
- [sym1](){return "bart";}
- }
- A.prototype.x = 42;
- A.prototype["y"] = 30;
- A.prototype[10] = 10;
- A.prototype[10.1] = 10.1;
- Object.defineProperty(A.prototype, "length", {writable : true, value : 2 });
- Object.defineProperty(A, "length", {writable : true, value : -1 });
- var tests = [
- {
- name: "Access length",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(2, super.length, "confirm we can make dot property call to access A.prototype.length");
- var super_arrow = () => {
- assert.areEqual(2, super.length, "confirm we can make dot property call to access A.prototype.length when it is in a lambda");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "Access of property fields on super",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(42, super.x, "confirm we can make dot property calls on non function types");
- assert.areEqual(42, super["x"], "confirm we can make index property calls of properties defined as dot properties");
- assert.areEqual(30, super["y"], "confirm we can make index property calls on string properties promoted to dot properties");
- assert.areEqual(10, super[10], "confirm we can make index property calls on integer properties");
- assert.areEqual(10.1, super[10.1], "confirm we can make index property calls on float point properties");
- assert.areEqual(10, super["10"], "confirm we can make index property calls on integer properties accessed as strings");
- assert.areEqual(10.1, super["10.1"], "confirm we can make index property calls on float point properties accessed as strings");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "Access of property fields on super in a lambda",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- var super_arrow = () => {
- assert.areEqual(42, super.x, "confirm we can make dot property calls on non function types");
- assert.areEqual(42, super["x"], "confirm we can make index property calls of properties defined as dot properties");
- assert.areEqual(30, super["y"], "confirm we can make index property calls on string properties promoted to dot properties");
- assert.areEqual(10, super[10], "confirm we can make index property calls on integer properties");
- assert.areEqual(10.1, super[10.1], "confirm we can make index property calls on float point properties");
- assert.areEqual(10, super["10"], "confirm we can make index property calls on integer properties accessed as strings");
- assert.areEqual(10.1, super["10.1"], "confirm we can make index property calls on float point properties accessed as strings");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "Access of property fields on super in a lambda with super also inside the lambda",
- body: function ()
- {
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual(42, super.x, "confirm we can make dot property calls on non function types");
- assert.areEqual(42, super["x"], "confirm we can make index property calls of properties defined as dot properties");
- assert.areEqual(30, super["y"], "confirm we can make index property calls on string properties promoted to dot properties");
- assert.areEqual(10, super[10], "confirm we can make index property calls on integer properties");
- assert.areEqual(10.1, super[10.1], "confirm we can make index property calls on float point properties");
- assert.areEqual(10, super["10"], "confirm we can make index property calls on integer properties accessed as strings");
- assert.areEqual(10.1, super["10.1"], "confirm we can make index property calls on float point properties accessed as strings");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda call on super before making a super call",
- body: function ()
- {
- count = 0;
- class B extends A {
- constructor() {
- var super_arrow = () => {
- assert.throws(()=>{ super.increment(); }, ReferenceError, "Use before declaration");
- assert.areEqual(0,count,"We should not have incremented");
- assert.throws(()=>{ super.increment.call(5); }, ReferenceError, "Use before declaration");
- assert.throws(()=>{ super[1](); }, ReferenceError, "Use before declaration");
- assert.throws(()=>{ super[1].call(5); }, ReferenceError, "Use before declaration");
- super();
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "super.<method>.call",
- body: function ()
- {
- count = 0;
- class B extends A {
- constructor() {
- super();
- var super_arrow = () => {
- super.increment.call(this);
- assert.areEqual(2,super.getCount.call(this), "confirm we can make the the method call on class A's method inside a lambda");
- assert.areEqual(1,super[1].call(this), "confirm we can make index method call on class A's method inside a lambda");
- }
- super_arrow();
- super.decrement.call(this);
- assert.areEqual(1,super.getCount.call(this),"confirm we can make the the method call on class A's method");
- assert.areEqual(2,super[2].call(this), "confirm we can make index method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda super dot calls",
- body: function ()
- {
- count = 0;
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual(1,super.getCount(),"confirm we can make the the method call on class A's method");
- super.increment();
- assert.areEqual(2, super.getCount(), "confirm we can make the the method call on class A's method");
- super.decrement();
- assert.areEqual(1, super.getCount(), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda super string index calls",
- body: function ()
- {
- count = 0;
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual(1,super["getCount"](), "confirm we can make the the method call on class A's method");
- super["increment"]();
- assert.areEqual(2, super["getCount"](), "confirm we can make the the method call on class A's method");
- super["decrement"]();
- assert.areEqual(1, super["getCount"](), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lambda super double index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual(1.1,super[1.1](), "confirm we can make the the method call on class A's method");
- assert.areEqual(2.2, super[2.2](), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lambda super int index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual(1,super[1](), "confirm we can make the the method call on class A's method");
- assert.areEqual(2, super[2](), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda super computed property double index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual(2.1,super[2.1](), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda super computed property int index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(4,super[4](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda super computed property string concatenated to integer index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual("foo1",super["foo1"](), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "lamda super computed property Symbol index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- var super_arrow = () => {
- super();
- assert.areEqual("bart",super[sym1](), "confirm we can make the the method call on class A's method");
- }
- super_arrow();
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super dot calls",
- body: function ()
- {
- count = 0;
- class B extends A {
- constructor() {
- super();
- assert.areEqual(1,super.getCount(), "confirm we can make the the method call on class A's method");
- super.increment();
- assert.areEqual(2, super.getCount(), "confirm we can make the the method call on class A's method");
- super.decrement();
- assert.areEqual(1, super.getCount(), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super string index calls",
- body: function ()
- {
- count = 0;
- class B extends A {
- constructor() {
- super();
- assert.areEqual(1,super["getCount"](), "confirm we can make the the method call on class A's method");
- super["increment"]();
- assert.areEqual(2, super["getCount"](), "confirm we can make the the method call on class A's method");
- super["decrement"]();
- assert.areEqual(1, super["getCount"](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super double index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(1.1,super[1.1](), "confirm we can make the the method call on class A's method");
- assert.areEqual(2.2, super[2.2](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super int index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(1,super[1](), "confirm we can make the the method call on class A's method");
- assert.areEqual(2, super[2](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super computed property double index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(2.1,super[2.1](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super computed property int index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual(4,super[4](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super computed property string concatenated to integer index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual("foo1",super["foo1"](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- },
- {
- name: "regular super computed property Symbol index calls",
- body: function ()
- {
- class B extends A {
- constructor() {
- super();
- assert.areEqual("bart",super[sym1](), "confirm we can make the the method call on class A's method");
- }
- }
- var bar = new B();
- }
- }
- ];
- testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
|