1
0
Fork 0

Merge branch 'master' into visibility/master

Conflicts:
	lib/class.js
closure/master
Mike Gerwitz 2011-03-06 12:39:26 -05:00
commit 5d8fdc5204
11 changed files with 83 additions and 31 deletions

View File

@ -44,6 +44,23 @@ var class_meta = {};
*/ */
var class_instance = {}; var class_instance = {};
/*
* 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 * This module may be invoked in order to provide a more natural looking class
@ -429,6 +446,15 @@ var extend = ( function( extending )
delete props.__name; delete props.__name;
} }
// IE has problems with toString()
if ( enum_bug )
{
if ( props.toString !== Object.prototype.toString )
{
props.__toString = props.toString;
}
}
util.propParse( props, { util.propParse( props, {
each: function( name, value, keywords ) each: function( name, value, keywords )
{ {
@ -584,7 +610,10 @@ var extend = ( function( extending )
members[ 'public' ], 'toString' members[ 'public' ], 'toString'
) ) ) ) ) )
{ {
this.toString = ( cname ) // use __toString if available (see enum_bug), otherwise use
// our own defaults
this.toString = members[ 'public' ].__toString
|| ( ( cname )
? function() ? function()
{ {
return '[object #<' + cname + '>]'; return '[object #<' + cname + '>]';
@ -593,6 +622,7 @@ var extend = ( function( extending )
{ {
return '[object #<anonymous>]'; return '[object #<anonymous>]';
} }
)
; ;
} }
}; };

View File

@ -277,7 +277,7 @@ for ( var i = 0; i < class_count; i++ )
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( args.length + ' given' ), e.message.match( args.length + ' given' ),
null, null,
"Class invocation should give argument count on error" "Class invocation should give argument count on error"
); );
@ -295,12 +295,13 @@ for ( var i = 0; i < class_count; i++ )
result = '' result = ''
; ;
result = Class( 'Foo', result = Class( 'FooToStr',
{ {
toString: function() toString: function()
{ {
return str; return str;
} },
bla: function() {},
})().toString(); })().toString();
assert.equal( assert.equal(

View File

@ -66,7 +66,7 @@ var common = require( './common' ),
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( name ), e.message.match( name ),
null, null,
"Class definition argument count error string contains class name" "Class definition argument count error string contains class name"
); );
@ -96,7 +96,7 @@ var common = require( './common' ),
} }
catch ( e ) catch ( e )
{ {
var errstr = e.toString(); var errstr = e.message;
assert.notEqual( assert.notEqual(
errstr.match( name ), errstr.match( name ),
@ -256,7 +256,7 @@ var common = require( './common' ),
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( name ), e.message.match( name ),
null, null,
"Abstract class instantiation error should contain class name" "Abstract class instantiation error should contain class name"
); );
@ -276,7 +276,7 @@ var common = require( './common' ),
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( '(anonymous)' ), e.message.match( '(anonymous)' ),
null, null,
"Abstract class instantiation error should recognize that class " + "Abstract class instantiation error should recognize that class " +
"is anonymous if no name was given" "is anonymous if no name was given"

View File

@ -26,7 +26,12 @@ var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
Class = common.require( 'class' ), Class = common.require( 'class' ),
Script = process.binding( 'evals' ).Script, Script = process.binding( 'evals' ).Script,
sandbox = {};
// sandbox in which combined script will be run
sandbox = {
// stub document.write() so we don't blow up
document: { write: function() {} },
};
var files = [ 'ease.js', 'ease-full.js' ], var files = [ 'ease.js', 'ease-full.js' ],

View File

@ -192,7 +192,7 @@ for ( var i = 0; i < base_types.length; i++ )
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( args.length + ' given' ), e.message.match( args.length + ' given' ),
null, null,
"Interface invocation should give argument count on error" "Interface invocation should give argument count on error"
); );

View File

@ -67,7 +67,7 @@ var common = require( './common' ),
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( name ), e.message.match( name ),
null, null,
"Interface definition argument count error string contains " + "Interface definition argument count error string contains " +
"interface name" "interface name"
@ -98,7 +98,7 @@ var common = require( './common' ),
} }
catch ( e ) catch ( e )
{ {
var errstr = e.toString(); var errstr = e.message;
assert.notEqual( assert.notEqual(
errstr.match( name ), errstr.match( name ),
@ -210,7 +210,7 @@ var common = require( './common' ),
{ {
// ensure the error string contains the interface name // ensure the error string contains the interface name
assert.notEqual( assert.notEqual(
e.toString().match( name ), e.message.match( name ),
null, null,
"Error contains interface name when available (" + i + ")" "Error contains interface name when available (" + i + ")"
); );
@ -234,7 +234,7 @@ var common = require( './common' ),
catch ( e ) catch ( e )
{ {
assert.notEqual( assert.notEqual(
e.toString().match( name ), e.message.match( name ),
null, null,
"Interface name is included in instantiation error message" "Interface name is included in instantiation error message"
); );

View File

@ -22,6 +22,12 @@
* @package test * @package test
*/ */
// no need to test getters/setters in browsers that do not support them
if ( !Object.defineProperty )
{
return;
}
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),

View File

@ -24,7 +24,7 @@
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
mb_common = require( './inc-member_builder-common' ) mb_common = require( __dirname + '/inc-member_builder-common' )
; ;
mb_common.funcVal = 'foobar'; mb_common.funcVal = 'foobar';

View File

@ -24,7 +24,7 @@
var common = require( './common' ), var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
mb_common = require( './inc-member_builder-common' ) mb_common = require( __dirname + '/inc-member_builder-common' )
; ;
mb_common.value = { bar: 'baz' }; mb_common.value = { bar: 'baz' };

View File

@ -24,7 +24,7 @@
catch ( e ) catch ( e )
{ {
body.style.color = 'red'; body.style.color = 'red';
body.innerHTML = '<p>' + e.toString() + '</p>' + body.innerHTML += '<p>' + e.message + '</p>' +
'<p><em>ease.js is not guaranteed to run properly within this ' + '<p><em>ease.js is not guaranteed to run properly within this ' +
'browser.</em></p>' + 'browser.</em></p>' +
'<p>If building ease.js, remember to run <tt>`make combine` ' + '<p>If building ease.js, remember to run <tt>`make combine` ' +

View File

@ -99,11 +99,11 @@ if [ "$INC_TEST" ]; then
# note that not all tests are included # note that not all tests are included
TEST_CASES=$( find $PATH_TEST \ TEST_CASES=$( find $PATH_TEST \
\( -name 'test-*.js' \ \( -name 'test-*.js' \
-name 'inc-*.js' \ -o -name 'inc-*.js' \
! -name 'test-combine.js' \
! -name 'test-index.js' \
\) \ \) \
-exec basename {} \; \ -exec basename {} \; \
| sort \
| grep -v 'test-\(combine\|index\).js' \
) )
# include test combine template # include test combine template
@ -116,15 +116,25 @@ if [ "$INC_TEST" ]; then
for testcase in $TEST_CASES; do for testcase in $TEST_CASES; do
filename="$PATH_TEST/$testcase" filename="$PATH_TEST/$testcase"
# generate the module name by removing path and extension, then
# prefixing it with "test/"
module="${filename%.*}"
module="test/${module##*/}"
# each module must be enclosed in a closure to emulate a module # each module must be enclosed in a closure to emulate a module
echo "/** TEST CASE: $testcase **/" echo "/** TEST CASE: $testcase **/"
echo "( function()" echo "( function( module, __dirname )"
echo "{" echo "{"
echo " var exports = module.exports = {};"
# write out current test to make debugging easier in browsers with very
# little debugging support
echo " document.write( '$module...<br />' )"
# add the module, removing trailing commas # add the module, removing trailing commas
cat $filename | $RMTRAIL cat $filename | $RMTRAIL
echo "} )();" echo "} )( module['$module'] = {}, 'test' );"
done done
echo "};" echo "};"