From 9dbd0d1fb3feebec0ab5b454a2f695b7dd5f15bf Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 17 Jan 2012 23:36:01 -0500 Subject: [PATCH] Added constructor property to reserved members list --- lib/ClassBuilder.js | 5 +++- .../test-class_builder-member-restrictions.js | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index a31d935..f8335e7 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -55,7 +55,10 @@ var util = require( __dirname + '/util' ), * * @type {Object.} */ - reserved_members = { '__initProps': true }, + reserved_members = { + '__initProps': true, + 'constructor': true, + }, /** * Hash of methods that must be public diff --git a/test/test-class_builder-member-restrictions.js b/test/test-class_builder-member-restrictions.js index 2411058..1b7c3c5 100644 --- a/test/test-class_builder-member-restrictions.js +++ b/test/test-class_builder-member-restrictions.js @@ -75,6 +75,36 @@ var common = require( './common' ), } )(); +/** + * This test is to ensure that nobody (a) removes reserved members without + * understanding the consequences or (b) adds reserved members without properly + * documenting them. + */ +( function testProperMembersAreReserved() +{ + var chk = [ '__initProps', 'constructor' ], + i = chk.length, + reserved = ClassBuilder.getReservedMembers(); + + while ( i-- ) + { + var cur = chk[ i ]; + + assert.ok( reserved.hasOwnProperty( cur ), + "Member '" + cur + "' should be reserved" + ); + + delete reserved[ cur ]; + } + + // ensure there are no others that we didn't expect + for ( var name in reserved ) + { + assert.fail( "Untested reserved member found: " + name ); + } +} )(); + + /** * Ensure that each of the reserved members will throw an exception if they are * used.