From 903a1a135c9f4cbbc3eb1f1c66e8bf20b6a889d9 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 26 Oct 2015 22:17:28 -0400 Subject: [PATCH] Prevent mixin failure on null/undefined supertype properties --- lib/Trait.js | 2 +- test/Trait/ClassExtendTest.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Trait.js b/lib/Trait.js index 7794b84..0304a6b 100644 --- a/lib/Trait.js +++ b/lib/Trait.js @@ -735,7 +735,7 @@ function mixMethods( src, dest, vis, iname, inparent ) // TODO: this is a kluge; we'll use proper reflection eventually, // but for now, this is how we determine if this is an actual method // vs. something that just happens to be on the visibility object - if ( !( src[ f ].___$$keywords$$ ) ) + if ( !( src[ f ] && src[ f ].___$$keywords$$ ) ) { continue; } diff --git a/test/Trait/ClassExtendTest.js b/test/Trait/ClassExtendTest.js index ceea701..cfcc0cf 100644 --- a/test/Trait/ClassExtendTest.js +++ b/test/Trait/ClassExtendTest.js @@ -167,6 +167,28 @@ require( 'common' ).testCase( }, + /** + * This test unfortunately relies on certain implementation details; + * we're testing at a high level here. + * + * When determining what methods need to be proxied for a mixin, ease.js + * checks certain properties of the supertype. If the value is + * null/undefined, then it is not an object, and cannot have any such + * properties. + */ + 'Trait mixin handles supertype null values': function() + { + // note the null value + var C = this.Class( { foo: null, bar: undefined } ), + T = this.Sut.extend( C, {} ); + + this.assertDoesNotThrow( function() + { + C.use( T )(); + } ); + }, + + /** * This is a corollary, but is still worth testing for assurance. *