From 188ad2f4eb1764658a362cf329a6ab770bc60fb1 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 24 Jan 2011 23:56:54 -0500 Subject: [PATCH] Getters/setters are not supported within interface definitions --- lib/interface.js | 14 +++++++++++++ test/test-interface-extend.js | 37 +++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/interface.js b/lib/interface.js index 94a9506..c6855cc 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -77,6 +77,20 @@ var extend = ( function( extending ) ); }, + getter: function() + { + throw TypeError( + "Getters are not permitted within Interface definitions" + ); + }, + + setter: function() + { + throw TypeError( + "Setters are not permitted within Interface definitions" + ); + }, + method: function( name, value, is_abstract, keywords ) { if ( !is_abstract ) diff --git a/test/test-interface-extend.js b/test/test-interface-extend.js index 7573536..385fe7c 100644 --- a/test/test-interface-extend.js +++ b/test/test-interface-extend.js @@ -27,14 +27,39 @@ var common = require( './common' ), Interface = common.require( 'interface' ); -assert.throws( function() +( function testPropertiesNotPermittedWithinInterfaces() { - Interface.extend( + assert.throws( function() { - // properties (non-methods) are not permitted - prop: 'not permitted', - }); -}, TypeError, "Properties are not permitted within Interface definitions" ); + Interface.extend( + { + // properties (non-methods) are not permitted + prop: 'not permitted', + }); + }, TypeError, "Properties are not permitted within Interface definitions" ); +} )(); + + +( function testGettersAndSettersNotPermittedWithinInterfaces() +{ + // don't perform this test if unsupported by environment + if ( Object.prototype.__defineGetter__ === undefined ) + { + return; + } + + // so we don't break browsers that do not support getters/setters in object + // notation + var data = {}; + data.__defineGetter__( 'foo', function() {} ); + data.__defineSetter__( 'foo', function() {} ); + + assert.throws( function() + { + Interface.extend( data ); + }, TypeError, "Getters/setters not permitted within Interfaces" ); +} )(); + assert.throws( function() {