Interface members may now only contain arg names that are valid var names
- This should apply to all abstract definitions. This will be resolved in the next commit. I am tired.perfodd
parent
e9cf630d0b
commit
50904390da
|
@ -1308,6 +1308,9 @@ The subtype must implement at least the number of arguments declared in
|
||||||
@var{args}, but the names needn't match.
|
@var{args}, but the names needn't match.
|
||||||
@itemize
|
@itemize
|
||||||
@item
|
@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.
|
The names are use purely for documentation and are not semantic.
|
||||||
@end itemize
|
@end itemize
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
|
@ -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(
|
member_builder.buildMethod(
|
||||||
members, null, name, value, keywords
|
members, null, name, value, keywords
|
||||||
);
|
);
|
||||||
|
|
|
@ -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' );
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue