Forbid trait extending of final classes
parent
c90fb6eb81
commit
4869d15b2b
13
lib/Trait.js
13
lib/Trait.js
|
@ -22,6 +22,7 @@
|
||||||
var AbstractClass = require( './class_abstract' ),
|
var AbstractClass = require( './class_abstract' ),
|
||||||
Class = require( './class' ),
|
Class = require( './class' ),
|
||||||
ClassBuilder = require( './ClassBuilder' ),
|
ClassBuilder = require( './ClassBuilder' ),
|
||||||
|
FinalClass = require( './class_final' ),
|
||||||
Interface = require( './interface' );
|
Interface = require( './interface' );
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,10 +124,20 @@ Trait.extend = function()
|
||||||
type = _getTraitType( dfn ),
|
type = _getTraitType( dfn ),
|
||||||
isparam = ( type === 'param' );
|
isparam = ( type === 'param' );
|
||||||
|
|
||||||
if ( has_extend && !Class.isClass( extend ) )
|
if ( has_extend )
|
||||||
|
{
|
||||||
|
if ( !Class.isClass( extend ) )
|
||||||
{
|
{
|
||||||
throw TypeError( "Trait " + name + " cannot extend non-class" );
|
throw TypeError( "Trait " + name + " cannot extend non-class" );
|
||||||
}
|
}
|
||||||
|
else if ( extend.___$$final$$ === true )
|
||||||
|
{
|
||||||
|
throw TypeError(
|
||||||
|
"Trait " + name + " cannot extend final class " +
|
||||||
|
extend.toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// augment the parser to handle our own oddities
|
// augment the parser to handle our own oddities
|
||||||
dfn.___$$parser$$ = {
|
dfn.___$$parser$$ = {
|
||||||
|
|
|
@ -25,6 +25,7 @@ require( 'common' ).testCase(
|
||||||
{
|
{
|
||||||
this.Sut = this.require( 'Trait' );
|
this.Sut = this.require( 'Trait' );
|
||||||
this.Class = this.require( 'class' );
|
this.Class = this.require( 'class' );
|
||||||
|
this.FinalClass = this.require( 'class_final' );
|
||||||
|
|
||||||
// nonsensical extend bases
|
// nonsensical extend bases
|
||||||
this.nonsense = [
|
this.nonsense = [
|
||||||
|
@ -259,4 +260,19 @@ require( 'common' ).testCase(
|
||||||
_self.Sut.extend( _self.Sut( {} ), {} );
|
_self.Sut.extend( _self.Sut( {} ), {} );
|
||||||
}, TypeError );
|
}, TypeError );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For consistency with the rest of the system, final classes are not
|
||||||
|
* permitted to be extended.
|
||||||
|
*/
|
||||||
|
'Traits cannot extend final classes': function()
|
||||||
|
{
|
||||||
|
var _self = this;
|
||||||
|
|
||||||
|
this.assertThrows( function()
|
||||||
|
{
|
||||||
|
_self.Sut.extend( _self.FinalClass( {} ), {} );
|
||||||
|
}, TypeError );
|
||||||
|
},
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue