1
0
Fork 0

Resolved bug that was causing the system to think that Object prototype members were part of the abstract member list when attempting to define a method with the same name

closure/master
Mike Gerwitz 2011-03-01 12:11:36 -05:00
parent e3561a492f
commit e239352fc0
2 changed files with 33 additions and 2 deletions

View File

@ -210,7 +210,9 @@ var extend = ( function( extending )
var args = Array.prototype.slice.call( arguments ), var args = Array.prototype.slice.call( arguments ),
props = args.pop() || {}, props = args.pop() || {},
base = args.pop() || Class, base = args.pop() || Class,
prototype = new base(); prototype = new base(),
hasOwn = Array.prototype.hasOwnProperty;
var properties = {}, var properties = {},
members = member_builder.initMembers( members = member_builder.initMembers(
@ -266,7 +268,7 @@ var extend = ( function( extending )
abstract_methods[ name ] = true; abstract_methods[ name ] = true;
abstract_methods.__length++; abstract_methods.__length++;
} }
else if ( ( abstract_methods[ name ] ) else if ( ( hasOwn.call( abstract_methods, name ) )
&& ( is_abstract === false ) && ( is_abstract === false )
) )
{ {

View File

@ -192,3 +192,32 @@ assert.throws( function()
); );
} )(); } )();
/**
* There was an issue where the object holding the abstract methods list was not
* checking for methods by using hasOwnProperty(). Therefore, if a method such
* as toString() was defined, it would be matched in the abstract methods list.
* As such, the abstract methods count would be decreased, even though it was
* not an abstract method to begin with (nor was it removed from the list,
* because it was never defined in the first place outside of the prototype).
*
* This negative number !== 0, which causes a problem when checking to ensure
* that there are 0 abstract methods. We check explicitly for 0 for two reasons:
* (a) it's faster than <, and (b - most importantly) if it's non-zero, then
* it's either abstract or something is wrong. Negative is especially wrong. It
* should never be negative!
*/
( function testDoesNotRecognizeObjectPrototypeMembersAsAbstractWhenDefining()
{
assert.doesNotThrow( function()
{
SubAbstractFoo.extend( {
// concrete, so the result would otherwise not be abstract
'method': function( one, two, three ) {},
// the problem
'toString': function() {},
})();
}, Error, "Should not throw error if overriding a prototype method" );
} )();