1
0
Fork 0

Interface name is included in declaration errors, if available

closure/master
Mike Gerwitz 2011-03-05 17:27:02 -05:00
parent 2967cc7a9a
commit 6f7dabe35e
2 changed files with 83 additions and 6 deletions

View File

@ -203,22 +203,25 @@ var extend = ( function( extending )
property: function() property: function()
{ {
throw TypeError( throw TypeError(
"Properties are not permitted within Interface " + "Property not permitted within definition of " +
"definitions (did you forget the 'abstract' keyword?)" "Interface '" + iname + "' (did you forget the " +
"'abstract' keyword?)"
); );
}, },
getter: function() getter: function()
{ {
throw TypeError( throw TypeError(
"Getters are not permitted within Interface definitions" "Getter not permitter within definition of Interface '" +
iname + "'"
); );
}, },
setter: function() setter: function()
{ {
throw TypeError( throw TypeError(
"Setters are not permitted within Interface definitions" "Setter within definition of Interface '" +
iname + "'"
); );
}, },
@ -227,8 +230,9 @@ var extend = ( function( extending )
if ( !is_abstract ) if ( !is_abstract )
{ {
throw TypeError( throw TypeError(
"Only abstract methods are permitted within " + "Concrete method not permitted in declaration of " +
"Interface definitions" "Interface '" + iname + "'; please declare as " +
"abstract."
); );
} }

View File

@ -145,3 +145,76 @@ var common = require( './common' ),
); );
} )(); } )();
( function testDeclarationErrorsProvideInterfaceNameIsAvailable()
{
var name = 'Foo',
// functions used to cause the various errors
tries = [
// properties
function()
{
Interface( name, { prop: 'str' } );
},
// methods
function()
{
Interface( name, { method: function() {} } );
},
]
;
// if we have getter/setter support, add those to the tests
if ( Object.defineProperty )
{
// getter
tries.push( function()
{
var obj = {};
Object.defineProperty( obj, 'getter', {
get: function() {},
enumerable: true,
} );
Interface( name, obj );
} );
// setter
tries.push( function()
{
var obj = {};
Object.defineProperty( obj, 'setter', {
set: function() {},
enumerable: true,
} );
Interface( name, obj );
} );
}
// gather the error strings
var i = tries.length;
while ( i-- )
{
try
{
// cause the error
tries[ i ]();
// we shouldn't get to this point...
assert.fail( "Expected error. Something's wrong." );
}
catch ( e )
{
// ensure the error string contains the interface name
assert.notEqual(
e.toString().match( name ),
null,
"Error contains interface name when available (" + i + ")"
);
}
}
} )();