'abstract' keyword no longer required for interface method declarations
- A warning is not yet being thrown for redundancy if the abstract keyword is explicitly specifiedclosure/master
parent
91db43d21d
commit
4fe20762c8
|
@ -209,12 +209,12 @@ be considered abstract and must be declared as such.
|
||||||
|
|
||||||
### Interfaces
|
### Interfaces
|
||||||
Interfaces can be declared in a very similar manner to classes. All members of
|
Interfaces can be declared in a very similar manner to classes. All members of
|
||||||
an interface must be declared as abstract.
|
an interface are implicitly abstract.
|
||||||
|
|
||||||
````javascript
|
````javascript
|
||||||
var MyType = Interface(
|
var MyType = Interface(
|
||||||
{
|
{
|
||||||
'abstract public foo': []
|
'public foo': []
|
||||||
});
|
});
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
|
@ -210,34 +210,22 @@ var extend = ( function( extending )
|
||||||
var new_interface = createInterface( iname );
|
var new_interface = createInterface( iname );
|
||||||
|
|
||||||
util.propParse( props, {
|
util.propParse( props, {
|
||||||
|
assumeAbstract: true,
|
||||||
|
|
||||||
property: function()
|
property: function()
|
||||||
{
|
{
|
||||||
throw TypeError(
|
// should never get to this point because of assumeAbstract
|
||||||
"Property not permitted within definition of " +
|
throw TypeError( 'Unexpected internal error' );
|
||||||
"Interface '" + iname + "' (did you forget the " +
|
|
||||||
"'abstract' keyword?)"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getset: function()
|
getset: function()
|
||||||
{
|
{
|
||||||
throw TypeError(
|
// should never get to this point because of assumeAbstract
|
||||||
"Getters/setters are not permitter within definition " +
|
throw TypeError( 'Unexpected internal error' );
|
||||||
"of Interface '" + iname + "'"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
method: function( name, value, is_abstract, keywords )
|
method: function( name, value, is_abstract, keywords )
|
||||||
{
|
{
|
||||||
if ( !is_abstract )
|
|
||||||
{
|
|
||||||
throw TypeError(
|
|
||||||
"Concrete method not permitted in declaration of " +
|
|
||||||
"Interface '" + iname + "'; please declare as " +
|
|
||||||
"abstract."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// all members must be public
|
// all members must be public
|
||||||
if ( keywords[ 'protected' ] || keywords[ 'private' ] )
|
if ( keywords[ 'protected' ] || keywords[ 'private' ] )
|
||||||
{
|
{
|
||||||
|
|
|
@ -297,7 +297,7 @@ exports.propParse = function( data, options )
|
||||||
name = parse_data.name || prop;
|
name = parse_data.name || prop;
|
||||||
keywords = parse_data.keywords || {};
|
keywords = parse_data.keywords || {};
|
||||||
|
|
||||||
if ( keywords['abstract'] )
|
if ( options.assumeAbstract || keywords['abstract'] )
|
||||||
{
|
{
|
||||||
if ( !( value instanceof Array ) )
|
if ( !( value instanceof Array ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,11 +38,11 @@ common.testCase(
|
||||||
this.baseTypes = [
|
this.baseTypes = [
|
||||||
Interface.extend(
|
Interface.extend(
|
||||||
{
|
{
|
||||||
'abstract method': [],
|
method: [],
|
||||||
} ),
|
} ),
|
||||||
|
|
||||||
Interface( {
|
Interface( {
|
||||||
'abstract method': [],
|
method: [],
|
||||||
} )
|
} )
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -113,14 +113,20 @@ common.testCase(
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
'Abstract method declarations are permitted': function()
|
/**
|
||||||
|
* Declaring (but not defining) methods by specifying their arguments as
|
||||||
|
* arrays is supported, much like one would would declare an abstract method
|
||||||
|
* in a class. We do not require the abstract keyword, as it would be
|
||||||
|
* redundant.
|
||||||
|
*/
|
||||||
|
'Method declarations (using arrays) are permitted': function()
|
||||||
{
|
{
|
||||||
this.assertDoesNotThrow(
|
this.assertDoesNotThrow(
|
||||||
function()
|
function()
|
||||||
{
|
{
|
||||||
Interface.extend(
|
Interface.extend(
|
||||||
{
|
{
|
||||||
'abstract method': [],
|
method: [],
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
TypeError,
|
TypeError,
|
||||||
|
@ -200,7 +206,7 @@ common.testCase(
|
||||||
{
|
{
|
||||||
var SubType = Interface.extend( T,
|
var SubType = Interface.extend( T,
|
||||||
{
|
{
|
||||||
'abstract second': [],
|
second: [],
|
||||||
} );
|
} );
|
||||||
|
|
||||||
this.assertOk(
|
this.assertOk(
|
||||||
|
@ -247,7 +253,7 @@ common.testCase(
|
||||||
{
|
{
|
||||||
var SubType = T.extend(
|
var SubType = T.extend(
|
||||||
{
|
{
|
||||||
'abstract second': [],
|
second: [],
|
||||||
} );
|
} );
|
||||||
|
|
||||||
this.assertOk(
|
this.assertOk(
|
||||||
|
@ -319,7 +325,7 @@ common.testCase(
|
||||||
{
|
{
|
||||||
// am = access modifier
|
// am = access modifier
|
||||||
var dfn = {};
|
var dfn = {};
|
||||||
dfn[ 'abstract ' + am + ' foo' ] = [];
|
dfn[ am + ' foo' ] = [];
|
||||||
|
|
||||||
Interface( dfn );
|
Interface( dfn );
|
||||||
}, Error, "Interface members should not be able to be " + am );
|
}, Error, "Interface members should not be able to be " + am );
|
||||||
|
|
Loading…
Reference in New Issue