/*
* pettanR system.js
- * version 0.5.42
+ * version 0.5.43
*
* gadgetOS
* author:
PRIVATE_DEF_LIST = [],
CONSTRUCTOR = 'Constructor',
GET_INDEX = Util.getIndex,
- abstractFlag = true,
- privateFlag = true,
- killPrivateFlag = true,
+ killPrivateFlag = false,
+ dataUser = null,
+ traits = null,
f = true,
c = Util.copyArray,
a; /* arguments */
* http://d.hatena.ne.jp/m-hiyama/20051018/1129605002
*/
function inherits( /* displayName, classSetting, opt_PrivateClass, props */ ){
- var args = c( arguments ),
- params = [],
- Super = this,
- superDef = getClassDef( Super ),
- displayName = args[ 0 ],
+ var args = c( arguments ),
+ params = [],
+ Super = this,
+ superDef = getClassDef( Super ),
+ displayName = args[ 0 ],
classSetting,
opt_super,
klass;
classSetting = args[ 0 ];
if( Type.isNumber( classSetting ) === true ){
+ if( superDef.isPrivate === true ) classSetting = classSetting | Class.PRIVATE_DATA;
opt_super = !!( classSetting & Class.SUPER_ACCESS );
- params.push( args.shift() );
+ params.push( classSetting );
+ args.shift();
};
- if( !getClass( args[ 0 ] ) ){
- params.push( superDef.privateClass || null );
- } else {
+ if( getClass( args[ 0 ] ) ){
params.push( args.shift() );
- };
- abstractFlag = false;
- params.push( override( new Super(), args[ 0 ], true ) ); /* props */
- abstractFlag = true;
-
- klass = Class.create.apply( Class, params );
+ } else
+ if( superDef.privateClass ){
+ params.push( superDef.privateClass );
+ };
+ params.push( args[ 0 ] ); /* props */
+ f = false;
+ traits = new Super();
+ f = true;
+ klass = Class.create.apply( Class, params );
+ traits = null;
if( opt_super === true ) getClassDef( klass ).Super = Super.prototype;
return klass;
};
/* Class.create で作られたクラスのインスタンスが共通で備えるメソッド */
- var ClassBase = {
+ var CommonProps = {
kill : function(){
var instance = this,
- klass = getClass( instance ),
- def = getClassDef( klass ),
- privateData, p, i;
- if( def.isPrivate === true && killPrivateFlag === true ){
+ klass = getClass( instance ),
+ def = getClassDef( klass ),
+ data, p, i;
+ if( def.isPrivate === true && killPrivateFlag === false ){
throw new Error( 'PrivateInstance.kill() work in PrivateUser.kill().' );
};
Type.isFunction( instance.onKill ) === true && instance.onKill();
def.pool.push( instance );
};
if( def.privateClass ){
- privateData = klass.getPrivateData( instance );
- if( privateData ){
- killPrivateFlag = false;
- privateData.kill();
+ i = GET_INDEX( def.userList, instance );
+ if( i !== -1 ){
+ data = klass.getPrivateData( instance );
killPrivateFlag = true;
- i = GET_INDEX( def.dataList, privateData );
+ data.kill();
+ killPrivateFlag = false;
def.dataList.splice( i, 1 );
def.userList.splice( i, 1 );
};
rList = def.callbackRegisterList = [];
};
i = GET_INDEX( iList, this );
- if( index === -1 ){
- index = iList.length;
+ if( i === -1 ){
cList = [];
iList.push( this );
rList.push( cList );
return myCallback;
},
releaseMyCallback : function( callback ){
- var def = getClassDef( this ),
- iList = def.callbackInstanceList,
- rList = def.callbackRegisterList,
- i, cList, myCallback;
+ var def = getClassDef( this ),
+ iList = def.callbackInstanceList,
+ rList = def.callbackRegisterList,
+ i, _i, cList;
if( !iList ) return;
i = GET_INDEX( iList, this );
- if( index === -1 ) return;
+ if( i === -1 ) return;
cList = rList[ i ];
- i = GET_INDEX( cList, callback );
- if( i !== -1 ) return;
- myCallback = cList[ i ];
- cList.splice( i, 1 );
- myCallback.kill();
+ _i = GET_INDEX( cList, callback );
+ if( _i === -1 ) return;
+ cList.splice( _i, 1 );
+ callback.kill();
+ if( cList.length !== 0 ) return;
+ iList.splice( i, 1 );
+ rList.splice( i, 1 );
+ if( iList.length !== 0 ) return;
+ delete def.callbackInstanceList;
+ delete def.callbackRegisterList;
}
};
if( i !== -1 ){
throw new Error( 'PrivateData already exist!' );
};
- privateFlag = false;
- data = new privateClass();
- privateFlag = false;
- def.dataList.push( data );
- def.userList.push( user );
- privateDef[ CONSTRUCTOR ] && privateDef[ CONSTRUCTOR ].apply( data, args );
+ dataUser = user;
+ data = new privateClass( args );
+ dataUser = null;
return data;
};
function getPrivateData( instance ){
* これにより pool された オブジェクト(破棄されたインスタンス) を再利用できる
*/
/* Constructor Real for GeneralClass */
- function G(){
+ function C( args ){
var klass = this,
def = getClassDef( klass ),
- instance;
+ instance,
+ userDef;
if( def.Abstract === true ){
- if( abstractFlag === true ){
- throw new Error( 'AbstractClass!' );
- };
- f = false;
- instance = new klass();
- f = true;
- return instance;
+ throw new Error( 'AbstractClass!' );
};
- if( def.pool && def.pool.length > 0 ){
- instance = def.pool.shift();
- } else {
- f = false;
- instance = new klass();
- f = true;
+ if( def.isPrivate === true && dataUser === null ){
+ throw new Error( 'use myClass.newPrivateData( instance, ...args )!' );
};
+ f = false;
+ instance = def.pool && def.pool.length > 0 ? def.pool.shift() : instance = new klass();
+ f = true;
if( def.Super && !instance.Super ){
instance.Super = def.Super;
};
- def.live && def.live.push( instance );
- def[ CONSTRUCTOR ] && def[ CONSTRUCTOR ].apply( instance, c( arguments ) );
- return instance;
- };
-
- /* Constructor Real for PrivateClass */
- function P(){
- var klass = this,
- def = getClassDef( klass ),
- instance;
- if( privateFlag === true ){
- throw new Error( 'use class.newPrivateData( instance, args )!' );
- };
- if( def.pool && def.pool.length > 0 ){
- instance = def.pool.shift();
+ if( def.isPrivate === true ){
+ userDef = getClassDef( dataUser );
+ userDef.dataList.push( instance );
+ userDef.userList.push( dataUser );
} else {
- f = false;
- instance = new klass();
- f = true;
- };
- if( def.Super && !instance.Super ){
- instance.Super = def.Super;
+ def.live && def.live.push( instance );
};
+ def[ CONSTRUCTOR ] && def[ CONSTRUCTOR ].apply( instance, dataUser === null ? c( arguments ) : args );
return instance;
};
};
args.shift();
};
- privateDef = getClassDef( args[ 0 ] );
- if( !privateDef ){
- args[ 0 ] === null && args.shift();
- } else {
+
+ if( GET_INDEX( PRIVATE_CLASS_LIST, args[ 0 ] ) !== -1 ){
+ privateDef = getClassDef( args[ 0 ] );
if( privateDef.isPrivate !== true ){
throw new Error( 'PrivateClass not found! please, Class.create( Class.PRIVATE, {...} ).' );
} else
if( Type.isFunction( props[ CONSTRUCTOR ] ) === true ){
classDef[ CONSTRUCTOR ] = props[ CONSTRUCTOR ];
- delete props[ CONSTRUCTOR ];
};
-
- if( opt_private === true ){
- klass = function(){ a = arguments; if( f ) return P.apply( a.callee, c( a ) )};
- if( opt_pool === true ) classDef.pool = [];
- } else {
- klass = function(){ a = arguments; if( f ) return G.apply( a.callee, c( a ) )};
- if( opt_pool === true ){
- classDef.pool = [];
- classDef.live = [];
- };
- if( opt_abstract === true ) classDef.Abstract = true;
- };
- klass.prototype = override( props, ClassBase, false );
+ klass = function(){ a = arguments; if( f ) return C.apply( a.callee, c( a ) )};
+ klass.prototype = override( override( traits || {}, props, true ), CommonProps, false );
+
+ if( opt_abstract === true ){
+ classDef.Abstract = true;
+ } else
+ if( opt_pool === true ){
+ classDef.pool = [];
+ if( opt_private === false )classDef.live = [];
+ };
if( opt_final === true ){
classDef.Final = true;
} else {