declare.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. //>>built
  7. define("dojo/_base/declare",["./kernel","../has","./lang"],function(_1,_2,_3){
  8. var _4=_3.mixin,op=Object.prototype,_5=op.toString,_6=new Function,_7=0,_8="constructor";
  9. function _9(_a,_b){
  10. throw new Error("declare"+(_b?" "+_b:"")+": "+_a);
  11. };
  12. function _c(_d,_e){
  13. var _f=[],_10=[{cls:0,refs:[]}],_11={},_12=1,l=_d.length,i=0,j,lin,_13,top,_14,rec,_15,_16;
  14. for(;i<l;++i){
  15. _13=_d[i];
  16. if(!_13){
  17. _9("mixin #"+i+" is unknown. Did you use dojo.require to pull it in?",_e);
  18. }else{
  19. if(_5.call(_13)!="[object Function]"){
  20. _9("mixin #"+i+" is not a callable constructor.",_e);
  21. }
  22. }
  23. lin=_13._meta?_13._meta.bases:[_13];
  24. top=0;
  25. for(j=lin.length-1;j>=0;--j){
  26. _14=lin[j].prototype;
  27. if(!_14.hasOwnProperty("declaredClass")){
  28. _14.declaredClass="uniqName_"+(_7++);
  29. }
  30. _15=_14.declaredClass;
  31. if(!_11.hasOwnProperty(_15)){
  32. _11[_15]={count:0,refs:[],cls:lin[j]};
  33. ++_12;
  34. }
  35. rec=_11[_15];
  36. if(top&&top!==rec){
  37. rec.refs.push(top);
  38. ++top.count;
  39. }
  40. top=rec;
  41. }
  42. ++top.count;
  43. _10[0].refs.push(top);
  44. }
  45. while(_10.length){
  46. top=_10.pop();
  47. _f.push(top.cls);
  48. --_12;
  49. while(_16=top.refs,_16.length==1){
  50. top=_16[0];
  51. if(!top||--top.count){
  52. top=0;
  53. break;
  54. }
  55. _f.push(top.cls);
  56. --_12;
  57. }
  58. if(top){
  59. for(i=0,l=_16.length;i<l;++i){
  60. top=_16[i];
  61. if(!--top.count){
  62. _10.push(top);
  63. }
  64. }
  65. }
  66. }
  67. if(_12){
  68. _9("can't build consistent linearization",_e);
  69. }
  70. _13=_d[0];
  71. _f[0]=_13?_13._meta&&_13===_f[_f.length-_13._meta.bases.length]?_13._meta.bases.length:1:0;
  72. return _f;
  73. };
  74. function _17(_18,a,f){
  75. var _19,_1a,_1b,_1c,_1d,_1e,_1f,opf,pos,_20=this._inherited=this._inherited||{};
  76. if(typeof _18=="string"){
  77. _19=_18;
  78. _18=a;
  79. a=f;
  80. }
  81. f=0;
  82. _1c=_18.callee;
  83. _19=_19||_1c.nom;
  84. if(!_19){
  85. _9("can't deduce a name to call inherited()",this.declaredClass);
  86. }
  87. _1d=this.constructor._meta;
  88. _1b=_1d.bases;
  89. pos=_20.p;
  90. if(_19!=_8){
  91. if(_20.c!==_1c){
  92. pos=0;
  93. _1e=_1b[0];
  94. _1d=_1e._meta;
  95. if(_1d.hidden[_19]!==_1c){
  96. _1a=_1d.chains;
  97. if(_1a&&typeof _1a[_19]=="string"){
  98. _9("calling chained method with inherited: "+_19,this.declaredClass);
  99. }
  100. do{
  101. _1d=_1e._meta;
  102. _1f=_1e.prototype;
  103. if(_1d&&(_1f[_19]===_1c&&_1f.hasOwnProperty(_19)||_1d.hidden[_19]===_1c)){
  104. break;
  105. }
  106. }while(_1e=_1b[++pos]);
  107. pos=_1e?pos:-1;
  108. }
  109. }
  110. _1e=_1b[++pos];
  111. if(_1e){
  112. _1f=_1e.prototype;
  113. if(_1e._meta&&_1f.hasOwnProperty(_19)){
  114. f=_1f[_19];
  115. }else{
  116. opf=op[_19];
  117. do{
  118. _1f=_1e.prototype;
  119. f=_1f[_19];
  120. if(f&&(_1e._meta?_1f.hasOwnProperty(_19):f!==opf)){
  121. break;
  122. }
  123. }while(_1e=_1b[++pos]);
  124. }
  125. }
  126. f=_1e&&f||op[_19];
  127. }else{
  128. if(_20.c!==_1c){
  129. pos=0;
  130. _1d=_1b[0]._meta;
  131. if(_1d&&_1d.ctor!==_1c){
  132. _1a=_1d.chains;
  133. if(!_1a||_1a.constructor!=="manual"){
  134. _9("calling chained constructor with inherited",this.declaredClass);
  135. }
  136. while(_1e=_1b[++pos]){
  137. _1d=_1e._meta;
  138. if(_1d&&_1d.ctor===_1c){
  139. break;
  140. }
  141. }
  142. pos=_1e?pos:-1;
  143. }
  144. }
  145. while(_1e=_1b[++pos]){
  146. _1d=_1e._meta;
  147. f=_1d?_1d.ctor:_1e;
  148. if(f){
  149. break;
  150. }
  151. }
  152. f=_1e&&f;
  153. }
  154. _20.c=f;
  155. _20.p=pos;
  156. if(f){
  157. return a===true?f:f.apply(this,a||_18);
  158. }
  159. };
  160. function _21(_22,_23){
  161. if(typeof _22=="string"){
  162. return this.__inherited(_22,_23,true);
  163. }
  164. return this.__inherited(_22,true);
  165. };
  166. function _24(_25,a1,a2){
  167. var f=this.getInherited(_25,a1);
  168. if(f){
  169. return f.apply(this,a2||a1||_25);
  170. }
  171. };
  172. var _26=_1.config.isDebug?_24:_17;
  173. function _27(cls){
  174. var _28=this.constructor._meta.bases;
  175. for(var i=0,l=_28.length;i<l;++i){
  176. if(_28[i]===cls){
  177. return true;
  178. }
  179. }
  180. return this instanceof cls;
  181. };
  182. function _29(_2a,_2b){
  183. for(var _2c in _2b){
  184. if(_2c!=_8&&_2b.hasOwnProperty(_2c)){
  185. _2a[_2c]=_2b[_2c];
  186. }
  187. }
  188. if(_2("bug-for-in-skips-shadowed")){
  189. for(var _2d=_3._extraNames,i=_2d.length;i;){
  190. _2c=_2d[--i];
  191. if(_2c!=_8&&_2b.hasOwnProperty(_2c)){
  192. _2a[_2c]=_2b[_2c];
  193. }
  194. }
  195. }
  196. };
  197. function _2e(_2f,_30){
  198. var _31,t;
  199. for(_31 in _30){
  200. t=_30[_31];
  201. if((t!==op[_31]||!(_31 in op))&&_31!=_8){
  202. if(_5.call(t)=="[object Function]"){
  203. t.nom=_31;
  204. }
  205. _2f[_31]=t;
  206. }
  207. }
  208. if(_2("bug-for-in-skips-shadowed")){
  209. for(var _32=_3._extraNames,i=_32.length;i;){
  210. _31=_32[--i];
  211. t=_30[_31];
  212. if((t!==op[_31]||!(_31 in op))&&_31!=_8){
  213. if(_5.call(t)=="[object Function]"){
  214. t.nom=_31;
  215. }
  216. _2f[_31]=t;
  217. }
  218. }
  219. }
  220. return _2f;
  221. };
  222. function _33(_34){
  223. _35.safeMixin(this.prototype,_34);
  224. return this;
  225. };
  226. function _36(_37,_38){
  227. return _35([this].concat(_37),_38||{});
  228. };
  229. function _39(_3a,_3b){
  230. return function(){
  231. var a=arguments,_3c=a,a0=a[0],f,i,m,l=_3a.length,_3d;
  232. if(!(this instanceof a.callee)){
  233. return _3e(a);
  234. }
  235. if(_3b&&(a0&&a0.preamble||this.preamble)){
  236. _3d=new Array(_3a.length);
  237. _3d[0]=a;
  238. for(i=0;;){
  239. a0=a[0];
  240. if(a0){
  241. f=a0.preamble;
  242. if(f){
  243. a=f.apply(this,a)||a;
  244. }
  245. }
  246. f=_3a[i].prototype;
  247. f=f.hasOwnProperty("preamble")&&f.preamble;
  248. if(f){
  249. a=f.apply(this,a)||a;
  250. }
  251. if(++i==l){
  252. break;
  253. }
  254. _3d[i]=a;
  255. }
  256. }
  257. for(i=l-1;i>=0;--i){
  258. f=_3a[i];
  259. m=f._meta;
  260. f=m?m.ctor:f;
  261. if(f){
  262. f.apply(this,_3d?_3d[i]:a);
  263. }
  264. }
  265. f=this.postscript;
  266. if(f){
  267. f.apply(this,_3c);
  268. }
  269. };
  270. };
  271. function _3f(_40,_41){
  272. return function(){
  273. var a=arguments,t=a,a0=a[0],f;
  274. if(!(this instanceof a.callee)){
  275. return _3e(a);
  276. }
  277. if(_41){
  278. if(a0){
  279. f=a0.preamble;
  280. if(f){
  281. t=f.apply(this,t)||t;
  282. }
  283. }
  284. f=this.preamble;
  285. if(f){
  286. f.apply(this,t);
  287. }
  288. }
  289. if(_40){
  290. _40.apply(this,a);
  291. }
  292. f=this.postscript;
  293. if(f){
  294. f.apply(this,a);
  295. }
  296. };
  297. };
  298. function _42(_43){
  299. return function(){
  300. var a=arguments,i=0,f,m;
  301. if(!(this instanceof a.callee)){
  302. return _3e(a);
  303. }
  304. for(;f=_43[i];++i){
  305. m=f._meta;
  306. f=m?m.ctor:f;
  307. if(f){
  308. f.apply(this,a);
  309. break;
  310. }
  311. }
  312. f=this.postscript;
  313. if(f){
  314. f.apply(this,a);
  315. }
  316. };
  317. };
  318. function _44(_45,_46,_47){
  319. return function(){
  320. var b,m,f,i=0,_48=1;
  321. if(_47){
  322. i=_46.length-1;
  323. _48=-1;
  324. }
  325. for(;b=_46[i];i+=_48){
  326. m=b._meta;
  327. f=(m?m.hidden:b.prototype)[_45];
  328. if(f){
  329. f.apply(this,arguments);
  330. }
  331. }
  332. };
  333. };
  334. function _49(_4a){
  335. _6.prototype=_4a.prototype;
  336. var t=new _6;
  337. _6.prototype=null;
  338. return t;
  339. };
  340. function _3e(_4b){
  341. var _4c=_4b.callee,t=_49(_4c);
  342. _4c.apply(t,_4b);
  343. return t;
  344. };
  345. function _35(_4d,_4e,_4f){
  346. if(typeof _4d!="string"){
  347. _4f=_4e;
  348. _4e=_4d;
  349. _4d="";
  350. }
  351. _4f=_4f||{};
  352. var _50,i,t,_51,_52,_53,_54,_55=1,_56=_4e;
  353. if(_5.call(_4e)=="[object Array]"){
  354. _53=_c(_4e,_4d);
  355. t=_53[0];
  356. _55=_53.length-t;
  357. _4e=_53[_55];
  358. }else{
  359. _53=[0];
  360. if(_4e){
  361. if(_5.call(_4e)=="[object Function]"){
  362. t=_4e._meta;
  363. _53=_53.concat(t?t.bases:_4e);
  364. }else{
  365. _9("base class is not a callable constructor.",_4d);
  366. }
  367. }else{
  368. if(_4e!==null){
  369. _9("unknown base class. Did you use dojo.require to pull it in?",_4d);
  370. }
  371. }
  372. }
  373. if(_4e){
  374. for(i=_55-1;;--i){
  375. _50=_49(_4e);
  376. if(!i){
  377. break;
  378. }
  379. t=_53[i];
  380. (t._meta?_29:_4)(_50,t.prototype);
  381. _51=new Function;
  382. _51.superclass=_4e;
  383. _51.prototype=_50;
  384. _4e=_50.constructor=_51;
  385. }
  386. }else{
  387. _50={};
  388. }
  389. _35.safeMixin(_50,_4f);
  390. t=_4f.constructor;
  391. if(t!==op.constructor){
  392. t.nom=_8;
  393. _50.constructor=t;
  394. }
  395. for(i=_55-1;i;--i){
  396. t=_53[i]._meta;
  397. if(t&&t.chains){
  398. _54=_4(_54||{},t.chains);
  399. }
  400. }
  401. if(_50["-chains-"]){
  402. _54=_4(_54||{},_50["-chains-"]);
  403. }
  404. t=!_54||!_54.hasOwnProperty(_8);
  405. _53[0]=_51=(_54&&_54.constructor==="manual")?_42(_53):(_53.length==1?_3f(_4f.constructor,t):_39(_53,t));
  406. _51._meta={bases:_53,hidden:_4f,chains:_54,parents:_56,ctor:_4f.constructor};
  407. _51.superclass=_4e&&_4e.prototype;
  408. _51.extend=_33;
  409. _51.createSubclass=_36;
  410. _51.prototype=_50;
  411. _50.constructor=_51;
  412. _50.getInherited=_21;
  413. _50.isInstanceOf=_27;
  414. _50.inherited=_26;
  415. _50.__inherited=_17;
  416. if(_4d){
  417. _50.declaredClass=_4d;
  418. _3.setObject(_4d,_51);
  419. }
  420. if(_54){
  421. for(_52 in _54){
  422. if(_50[_52]&&typeof _54[_52]=="string"&&_52!=_8){
  423. t=_50[_52]=_44(_52,_53,_54[_52]==="after");
  424. t.nom=_52;
  425. }
  426. }
  427. }
  428. return _51;
  429. };
  430. _1.safeMixin=_35.safeMixin=_2e;
  431. _1.declare=_35;
  432. return _35;
  433. });