1
0
Fork 0

Abstract member declaration parameter name restrictions now apply to all abstract member declarations, not just interfaces

perfodd
Mike Gerwitz 2011-12-21 20:12:05 -05:00
parent 50904390da
commit a10cf82a12
4 changed files with 53 additions and 41 deletions

View File

@ -235,23 +235,6 @@ var extend = ( function( extending )
);
}
var dfn = value.definition,
i = dfn.length;
// only permit valid names for argument list (in the future,
// we may add additional functionality, so it's important to
// restrict this as much as possible for the time being)
while ( i-- )
{
if ( dfn[ i ].match( /^[a-z][a-z0-9]*$/i ) === null )
{
throw SyntaxError(
iname + " member " + name +
" contains invalid argument: '" + name + "'"
);
}
}
member_builder.buildMethod(
members, null, name, value, keywords
);

View File

@ -313,6 +313,7 @@ exports.propParse = function( data, options )
);
}
verifyAbstractNames( name, value );
value = exports.createAbstractMethod.apply( this, value );
}
@ -349,6 +350,33 @@ exports.propParse = function( data, options )
};
/**
* Only permit valid names for parameter list
*
* In the future, we may add additional functionality, so it's important to
* restrict this as much as possible for the time being.
*
* @param {string} name name of abstract member (for error)
* @param {Object} params parameter list to check
*
* @return {undefined}
*/
function verifyAbstractNames( name, params )
{
var i = params.length;
while ( i-- )
{
if ( params[ i ].match( /^[a-z][a-z0-9]*$/i ) === null )
{
throw SyntaxError(
"Member " + name + " contains invalid parameter: '" +
params[ i ] + "'"
);
}
}
}
/**
* Creates an abstract method
*

View File

@ -243,27 +243,3 @@ var common = require( './common' ),
}
} )();
/**
* At this point in time, we are unsure what we will allow within interface
* definitions in the future (e.g. possible type hinting). As such, we will
* simply allow only valid variable names for now (like a function definition).
*/
( function testTriggersErrorIfInvalidVarNamesAreUsedAsArgumentNames()
{
assert['throws']( function()
{
Interface( { foo: [ 'invalid name' ] } );
}, SyntaxError, 'Only var names should be permitted in interface dfns' );
assert['throws']( function()
{
Interface( { foo: [ '1invalid' ] } );
}, SyntaxError, 'Only var names should be permitted in interface dfns: 2' );
assert.doesNotThrow( function()
{
Interface( { foo: [ 'valid' ] } );
}, SyntaxError, 'Valid var names as args should not throw exceptions' );
} )();

View File

@ -184,3 +184,28 @@ assert.equal(
"propParse should ignore prototype properties of instances"
);
/**
* At this point in time, we are unsure what we will allow within abstract
* member declarations in the future (e.g. possible type hinting). As such, we
* will simply allow only valid variable names for now (like a function
* definition).
*/
( function testTriggersErrorIfInvalidVarNamesAreUsedAsParameterNames()
{
assert['throws']( function()
{
util.propParse( { 'abstract foo': [ 'invalid name' ] }, {} );
}, SyntaxError, 'Only var names should be permitted in interface dfns' );
assert['throws']( function()
{
util.propParse( { 'abstract foo': [ '1invalid' ] }, {} );
}, SyntaxError, 'Only var names should be permitted in interface dfns: 2' );
assert.doesNotThrow( function()
{
util.propParse( { 'abstract foo': [ 'valid' ] }, {} );
}, SyntaxError, 'Valid var names as args should not throw exceptions' );
} )();