1
0
Fork 0

Fix toString() override for IE

- All tests once again pass on IE6
closure/master
Mike Gerwitz 2011-03-06 12:38:31 -05:00
parent a1c1ddff74
commit 517b2be464
2 changed files with 42 additions and 11 deletions

View File

@ -34,6 +34,23 @@ var util = require( './util' ),
*/
var class_meta = {};
/**
* IE contains a nasty enumeration "bug" (poor implementation) that makes
* toString unenumerable. This means that, if you do obj.toString = foo,
* toString will NOT show up in `for` or hasOwnProperty(). This is a problem.
*
* This test will determine if this poor implementation exists.
*/
var enum_bug = (
Object.prototype.propertyIsEnumerable.call(
{ toString: function() {} },
'toString'
) === false
)
? true
: false
;
/**
* This module may be invoked in order to provide a more natural looking class
@ -419,6 +436,15 @@ var extend = ( function( extending )
delete props.__name;
}
// IE has problems with toString()
if ( enum_bug )
{
if ( props.toString !== Object.prototype.toString )
{
props.__toString = props.toString;
}
}
util.propParse( props, {
each: function( name, value, keywords )
{
@ -567,15 +593,19 @@ var extend = ( function( extending )
members[ 'public' ], 'toString'
) ) )
{
this.toString = ( cname )
? function()
{
return '[object #<' + cname + '>]';
}
: function()
{
return '[object #<anonymous>]';
}
// use __toString if available (see enum_bug), otherwise use
// our own defaults
this.toString = members[ 'public' ].__toString
|| ( ( cname )
? function()
{
return '[object #<' + cname + '>]';
}
: function()
{
return '[object #<anonymous>]';
}
)
;
}
};

View File

@ -292,12 +292,13 @@ for ( var i = 0; i < class_count; i++ )
result = ''
;
result = Class( 'Foo',
result = Class( 'FooToStr',
{
toString: function()
{
return str;
}
},
bla: function() {},
})().toString();
assert.equal(