1
0
Fork 0
easejs/test
Mike Gerwitz d9b86c1544
Support for trait class supertype overrides
Traits can now override methods of their class supertypes.  Previously, in
order to override a method of some class `C` by mixing in some trait `T`,
both had to implement a common interface.  This had two notable downsides:

  1. A trait that was only compatible with details of `C` could only work
     with `C#M` if it implemented an interface `I` that declared `I#M`.
     This required the author of `C` to create interfaces where they would
     otherwise not be necessary.

  2. As a corollary of #1---since methods of interfaces must be public, it
     was not possible for `T` to override any protected method of `C`; this
     meant that `C` would have to declare such methods public, which may
     break encapsulation or expose unnecessary concerns to the outside
     world.

Until documentation is available---hopefully in the near future---the test
cases provide detailed documentation of the behavior.  Stackable traits work
as you would expect:

```javascript
var C = Class(
{
    'virtual foo': function()
    {
        return 'C';
    },
} );

var T1 = Trait.extend( C,
{
    'virtual abstract override foo': function()
    {
        return 'T1' + this.__super();
    },
} );

var T2 = Trait.extend( C,
{
    'virtual abstract override foo': function()
    {
        return 'T2' + this.__super();
    },
} );

C.use( T1 )
    .use( T1 )
    .use( T2 )
    .use( T2 )
    .foo();
// result: "T2T2T1T1C"
```

If the `override` keyword is used without `abstract`, then the super method
is statically bound to the supertype, rather than being resolved at runtime:

```javascript
var C = Class(
{
    'virtual foo': function()
    {
        return 'C';
    },
} );

var T1 = Trait.extend( C,
{
    'virtual abstract override foo': function()
    {
        return 'T1' + this.__super();
    },
} );

var T2 = Trait.extend( C,
{
    // static override
    'virtual override foo': function()
    {
        return 'T2' + this.__super();
    },
} );

C.use( T1 )
    .use( T1 )
    .use( T2 )
    .use( T2 )
    .foo();
// result: "T2C"
```

This latter form should be discouraged in most circumstances (as it prevents
stackable traits), but the behavior is consistent with the rest of the
system.

Happy hacking.
2015-10-24 23:53:23 -04:00
..
Class Add test to ensure multiple constructors cannot be defined 2015-09-16 00:02:02 -04:00
ClassBuilder Alias `constructor` member to `__construct` 2015-09-16 00:02:00 -04:00
Interface Interface.isInstanceOf will account for interop compatibility 2014-08-06 23:07:44 -04:00
MemberBuilder Corrected test broken by Node.js v0.10.27 2014-08-07 00:01:59 -04:00
MemberBuilderValidator [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
Trait Support for trait class supertype overrides 2015-10-24 23:53:23 -04:00
Util [copyright] Copyright update 2015-05-28 01:01:51 -04:00
perf [copyright] Copyright update 2015-05-28 01:01:51 -04:00
warn Extracted warning handlers into their own prototypes 2014-06-11 23:42:20 -04:00
CombinePreEs5Test.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
CombineTest.js Exposing Trait in combined source files 2014-04-28 14:32:18 -04:00
FallbackMemberBuilderTest.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
FallbackVisibilityObjectFactoryTest.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
IndexTest.js Prototype wrapping using index function 2015-09-09 23:36:14 -04:00
MethodWrapperFactoryTest.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
MethodWrappersTest.js method.super references now ES3-compatible 2014-08-07 22:24:25 -04:00
PropParserKeywordsTest.js Exposing keyword bit values and bitmasks 2014-04-20 02:40:36 -04:00
VersionTest.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
VisibilityObjectFactoryFactoryTest.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
VisibilityObjectFactoryTest.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
common.js [copyright] Copyright update 2015-05-28 01:01:51 -04:00
inc-testcase.js Test case now allows for short-hand require of SUT 2014-07-24 01:11:55 -04:00
runner.in test/runner will now pass all option args to node 2014-07-27 01:53:34 -04:00
runner.js [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00
test-rmtrail [copyright] Copyright assignment to the FSF 2014-04-09 19:05:07 -04:00