2010-11-10 22:19:50 -05:00
|
|
|
/**
|
|
|
|
* Tests class parent invocation
|
|
|
|
*
|
2013-12-20 00:49:06 -05:00
|
|
|
* Copyright (C) 2010, 2011, 2013 Mike Gerwitz
|
2010-11-10 22:19:50 -05:00
|
|
|
*
|
2013-12-22 09:37:21 -05:00
|
|
|
* This file is part of GNU ease.js.
|
2010-11-10 22:19:50 -05:00
|
|
|
*
|
|
|
|
* ease.js is free software: you can redistribute it and/or modify it under the
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
2010-11-10 22:19:50 -05:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2010-11-10 22:19:50 -05:00
|
|
|
*
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-10 22:19:50 -05:00
|
|
|
*
|
|
|
|
* @author Mike Gerwitz
|
|
|
|
*/
|
|
|
|
|
2010-12-21 23:25:12 -05:00
|
|
|
var common = require( './common' ),
|
|
|
|
assert = require( 'assert' ),
|
2011-12-10 11:06:34 -05:00
|
|
|
Class = common.require( 'class' ),
|
2010-11-10 22:19:50 -05:00
|
|
|
|
2011-03-02 07:51:18 -05:00
|
|
|
// we store these outside of the class to ensure that visibility bugs do not
|
|
|
|
// get in the way of our assertions
|
|
|
|
hitMethod = false,
|
|
|
|
hitMethod2 = false,
|
2013-04-20 21:54:29 -04:00
|
|
|
hitDouble = false,
|
2011-03-02 07:51:18 -05:00
|
|
|
method2Arg = null,
|
2010-11-10 22:19:50 -05:00
|
|
|
|
2011-03-02 07:51:18 -05:00
|
|
|
Foo = Class.extend(
|
2010-11-10 22:19:50 -05:00
|
|
|
{
|
2011-06-08 01:11:53 -04:00
|
|
|
'virtual myMethod': function()
|
2011-03-02 07:51:18 -05:00
|
|
|
{
|
|
|
|
hitMethod = true;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2011-06-08 01:11:53 -04:00
|
|
|
'virtual myMethod2': function( arg )
|
2011-03-02 07:51:18 -05:00
|
|
|
{
|
|
|
|
hitMethod2 = true;
|
|
|
|
method2Arg = arg;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
2013-04-20 21:54:29 -04:00
|
|
|
|
|
|
|
'virtual double': function()
|
|
|
|
{
|
|
|
|
hitDouble = true;
|
|
|
|
}
|
2011-03-02 07:51:18 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
SubFoo = Foo.extend(
|
2010-11-10 22:54:24 -05:00
|
|
|
{
|
2011-08-04 00:32:10 -04:00
|
|
|
'override myMethod': function()
|
2011-03-02 07:51:18 -05:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2011-08-04 00:32:10 -04:00
|
|
|
'override myMethod2': function( arg )
|
2011-03-02 07:51:18 -05:00
|
|
|
{
|
|
|
|
return this.__super( arg );
|
|
|
|
},
|
2013-04-20 21:54:29 -04:00
|
|
|
|
|
|
|
'override double': function()
|
|
|
|
{
|
|
|
|
this.myMethod();
|
|
|
|
this.__super();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
2011-03-02 07:51:18 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
foo = new Foo(),
|
|
|
|
sub_foo = new SubFoo()
|
|
|
|
;
|
2010-11-10 22:19:50 -05:00
|
|
|
|
|
|
|
// make sure we're working properly before we run the important assertions
|
|
|
|
foo.myMethod().myMethod2();
|
|
|
|
assert.equal(
|
2011-03-02 07:51:18 -05:00
|
|
|
hitMethod,
|
2010-11-10 22:19:50 -05:00
|
|
|
true,
|
|
|
|
"Sanity check"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2011-03-02 07:51:18 -05:00
|
|
|
hitMethod2,
|
2010-11-10 22:19:50 -05:00
|
|
|
true,
|
|
|
|
"Sanity check"
|
|
|
|
);
|
|
|
|
|
2011-03-02 07:51:18 -05:00
|
|
|
hitMethod = hitMethod2 = false;
|
|
|
|
|
2010-11-10 22:49:27 -05:00
|
|
|
var arg = 'foobar';
|
2013-04-20 21:54:29 -04:00
|
|
|
sub_foo.myMethod().myMethod2( arg ).double();
|
2010-11-10 22:49:27 -05:00
|
|
|
|
2010-11-10 22:19:50 -05:00
|
|
|
// myMethod overrides without calling parent
|
|
|
|
assert.equal(
|
2011-03-02 07:51:18 -05:00
|
|
|
hitMethod,
|
2010-11-10 22:19:50 -05:00
|
|
|
false,
|
|
|
|
"Subtype should be able to override parent properties"
|
|
|
|
);
|
|
|
|
|
2010-11-10 22:49:27 -05:00
|
|
|
// myMethod2 overrides parent then calls super method
|
2010-11-10 22:19:50 -05:00
|
|
|
assert.equal(
|
2011-03-02 07:51:18 -05:00
|
|
|
hitMethod2,
|
2010-11-10 22:19:50 -05:00
|
|
|
true,
|
|
|
|
"Subtype should be able to call parent method"
|
|
|
|
);
|
|
|
|
|
2010-11-10 22:49:27 -05:00
|
|
|
assert.equal(
|
2011-03-02 07:51:18 -05:00
|
|
|
method2Arg,
|
2010-11-10 22:49:27 -05:00
|
|
|
arg,
|
|
|
|
"Arguments should be passed to super method via _super argument list"
|
|
|
|
);
|
|
|
|
|
2011-12-04 19:26:53 -05:00
|
|
|
assert['throws']( function()
|
2010-11-10 23:42:26 -05:00
|
|
|
{
|
|
|
|
Foo.extend(
|
|
|
|
{
|
|
|
|
// overriding method with scalar; shouldn't be allowed
|
|
|
|
myMethod: 'scalar',
|
|
|
|
});
|
|
|
|
}, TypeError, "Methods must be overridden with a Function" );
|
|
|
|
|
2013-04-20 21:54:29 -04:00
|
|
|
// ensure that __super is not cleared after a call to an override
|
|
|
|
assert.equal(
|
|
|
|
hitDouble,
|
|
|
|
true,
|
|
|
|
"__super is maintained in a stack-like manner"
|
|
|
|
);
|