diff --git a/doc/classes.texi b/doc/classes.texi index 4573b5a..9dc4e10 100644 --- a/doc/classes.texi +++ b/doc/classes.texi @@ -1308,6 +1308,9 @@ The subtype must implement at least the number of arguments declared in @var{args}, but the names needn't match. @itemize @item + Each name in @var{args} must be a valid variable name, as satisfied by the + regular expression @code{/^[a-z][a-z0-9]*$/i}. + @item The names are use purely for documentation and are not semantic. @end itemize @end itemize diff --git a/lib/interface.js b/lib/interface.js index 0f2b6ae..35efa7d 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -235,6 +235,23 @@ 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 ); diff --git a/test/test-interface-name.js b/test/test-interface-name.js index ba1bd09..5a21efe 100644 --- a/test/test-interface-name.js +++ b/test/test-interface-name.js @@ -243,3 +243,27 @@ 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' ); +} )(); +