Prohibiting trait getters/setters
parent
bfadd9fce9
commit
cc43f4b339
23
lib/Trait.js
23
lib/Trait.js
|
@ -99,6 +99,7 @@ Trait.extend = function( dfn )
|
||||||
dfn.___$$parser$$ = {
|
dfn.___$$parser$$ = {
|
||||||
each: _parseMember,
|
each: _parseMember,
|
||||||
property: _parseProps,
|
property: _parseProps,
|
||||||
|
getset: _parseGetSet,
|
||||||
};
|
};
|
||||||
|
|
||||||
// give the abstract trait class a distinctive name for debugging
|
// give the abstract trait class a distinctive name for debugging
|
||||||
|
@ -208,6 +209,28 @@ function _parseProps( name, value, keywords, h )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immediately throws an exception, as getters/setters are unsupported
|
||||||
|
*
|
||||||
|
* This is a temporary restriction; they will be supported in future
|
||||||
|
* releases.
|
||||||
|
*
|
||||||
|
* @param {string} name property name
|
||||||
|
* @param {*} value property value
|
||||||
|
* @param {Object} keywords property keywords
|
||||||
|
* @param {Function} h original handler that we replaced
|
||||||
|
*
|
||||||
|
* @return {undefined}
|
||||||
|
*/
|
||||||
|
function _parseGetSet( name, value, keywords, h )
|
||||||
|
{
|
||||||
|
throw Error(
|
||||||
|
"Cannot define property `" + name + "'; getters/setters are " +
|
||||||
|
"currently unsupported"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement one or more interfaces
|
* Implement one or more interfaces
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,6 +28,10 @@ require( 'common' ).testCase(
|
||||||
this.Interface = this.require( 'interface' );
|
this.Interface = this.require( 'interface' );
|
||||||
this.AbstractClass = this.require( 'class_abstract' );
|
this.AbstractClass = this.require( 'class_abstract' );
|
||||||
|
|
||||||
|
this.hasGetSet = !(
|
||||||
|
this.require( 'util' ).definePropertyFallback()
|
||||||
|
);
|
||||||
|
|
||||||
// means of creating anonymous traits
|
// means of creating anonymous traits
|
||||||
this.ctor = [
|
this.ctor = [
|
||||||
this.Sut.extend,
|
this.Sut.extend,
|
||||||
|
@ -413,4 +417,38 @@ require( 'common' ).testCase(
|
||||||
Sut( { 'static foo': function() {} } );
|
Sut( { 'static foo': function() {} } );
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the same reasons as static members (described immediately above),
|
||||||
|
* getters/setters are unsupported until future versions.
|
||||||
|
*
|
||||||
|
* Note that we use defineProperty instead of the short-hand object
|
||||||
|
* literal notation to avoid syntax errors in pre-ES5 environments.
|
||||||
|
*/
|
||||||
|
'Trait getters and setters are prohibited': function()
|
||||||
|
{
|
||||||
|
// perform these tests only when getters/setters are supported by
|
||||||
|
// our environment
|
||||||
|
if ( !( this.hasGetSet ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var Sut = this.Sut;
|
||||||
|
|
||||||
|
this.assertThrows( function()
|
||||||
|
{
|
||||||
|
var dfn = {};
|
||||||
|
Object.defineProperty( dfn, 'foo',
|
||||||
|
{
|
||||||
|
get: function() {},
|
||||||
|
set: function() {},
|
||||||
|
|
||||||
|
enumerable: true,
|
||||||
|
} );
|
||||||
|
|
||||||
|
Sut( dfn );
|
||||||
|
} );
|
||||||
|
},
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue