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 = {};
/*
* 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
@ -429,6 +446,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 )
{
@ -584,7 +610,10 @@ var extend = ( function( extending )
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()
{
return '[object #<' + cname + '>]';
@ -593,6 +622,7 @@ var extend = ( function( extending )
{
return '[object #<anonymous>]';
}
)
;
}
};

View File

@ -277,7 +277,7 @@ for ( var i = 0; i < class_count; i++ )
catch ( e )
{
assert.notEqual(
e.toString().match( args.length + ' given' ),
e.message.match( args.length + ' given' ),
null,
"Class invocation should give argument count on error"
);
@ -295,12 +295,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(

View File

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

View File

@ -26,7 +26,12 @@ var common = require( './common' ),
assert = require( 'assert' ),
Class = common.require( 'class' ),
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' ],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@
catch ( e )
{
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 ' +
'browser.</em></p>' +
'<p>If building ease.js, remember to run <tt>`make combine` ' +

View File

@ -99,32 +99,42 @@ if [ "$INC_TEST" ]; then
# note that not all tests are included
TEST_CASES=$( find $PATH_TEST \
\( -name 'test-*.js' \
-name 'inc-*.js' \
! -name 'test-combine.js' \
! -name 'test-index.js' \
-o -name 'inc-*.js' \
\) \
-exec basename {} \; \
| sort \
| grep -v 'test-\(combine\|index\).js' \
)
# include test combine template
cat "$TPL_TEST_PATH" | grep -v '^#' | $RMTRAIL
echo "/** TEST CASES **/"
echo "ns_exports.runTests = function ()"
echo "ns_exports.runTests = function()"
echo "{"
for testcase in $TEST_CASES; do
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
echo "/** TEST CASE: $testcase **/"
echo "( function()"
echo "( function( module, __dirname )"
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
cat $filename | $RMTRAIL
echo "} )();"
echo "} )( module['$module'] = {}, 'test' );"
done
echo "};"