rtl.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. var pas = {};
  2. var rtl = {
  3. version: 10301,
  4. quiet: false,
  5. debug_load_units: false,
  6. debug_rtti: false,
  7. debug: function(){
  8. if (rtl.quiet || !console || !console.log) return;
  9. console.log(arguments);
  10. },
  11. error: function(s){
  12. rtl.debug('Error: ',s);
  13. throw s;
  14. },
  15. warn: function(s){
  16. rtl.debug('Warn: ',s);
  17. },
  18. checkVersion: function(v){
  19. if (rtl.version != v) throw "expected rtl version "+v+", but found "+rtl.version;
  20. },
  21. hasString: function(s){
  22. return rtl.isString(s) && (s.length>0);
  23. },
  24. isArray: function(a) {
  25. return Array.isArray(a);
  26. },
  27. isFunction: function(f){
  28. return typeof(f)==="function";
  29. },
  30. isModule: function(m){
  31. return rtl.isObject(m) && rtl.hasString(m.$name) && (pas[m.$name]===m);
  32. },
  33. isImplementation: function(m){
  34. return rtl.isObject(m) && rtl.isModule(m.$module) && (m.$module.$impl===m);
  35. },
  36. isNumber: function(n){
  37. return typeof(n)==="number";
  38. },
  39. isObject: function(o){
  40. var s=typeof(o);
  41. return (typeof(o)==="object") && (o!=null);
  42. },
  43. isString: function(s){
  44. return typeof(s)==="string";
  45. },
  46. getNumber: function(n){
  47. return typeof(n)==="number"?n:NaN;
  48. },
  49. getChar: function(c){
  50. return ((typeof(c)==="string") && (c.length===1)) ? c : "";
  51. },
  52. getObject: function(o){
  53. return ((typeof(o)==="object") || (typeof(o)==='function')) ? o : null;
  54. },
  55. isTRecord: function(type){
  56. return (rtl.isObject(type) && type.hasOwnProperty('$new') && (typeof(type.$new)==='function'));
  57. },
  58. isPasClass: function(type){
  59. return (rtl.isObject(type) && type.hasOwnProperty('$classname') && rtl.isObject(type.$module));
  60. },
  61. isPasClassInstance: function(type){
  62. return (rtl.isObject(type) && rtl.isPasClass(type.$class));
  63. },
  64. hexStr: function(n,digits){
  65. return ("000000000000000"+n.toString(16).toUpperCase()).slice(-digits);
  66. },
  67. m_loading: 0,
  68. m_loading_intf: 1,
  69. m_intf_loaded: 2,
  70. m_loading_impl: 3, // loading all used unit
  71. m_initializing: 4, // running initialization
  72. m_initialized: 5,
  73. module: function(module_name, intfuseslist, intfcode, impluseslist, implcode){
  74. if (rtl.debug_load_units) rtl.debug('rtl.module name="'+module_name+'" intfuses='+intfuseslist+' impluses='+impluseslist+' hasimplcode='+rtl.isFunction(implcode));
  75. if (!rtl.hasString(module_name)) rtl.error('invalid module name "'+module_name+'"');
  76. if (!rtl.isArray(intfuseslist)) rtl.error('invalid interface useslist of "'+module_name+'"');
  77. if (!rtl.isFunction(intfcode)) rtl.error('invalid interface code of "'+module_name+'"');
  78. if (!(impluseslist==undefined) && !rtl.isArray(impluseslist)) rtl.error('invalid implementation useslist of "'+module_name+'"');
  79. if (!(implcode==undefined) && !rtl.isFunction(implcode)) rtl.error('invalid implementation code of "'+module_name+'"');
  80. if (pas[module_name])
  81. rtl.error('module "'+module_name+'" is already registered');
  82. var module = pas[module_name] = {
  83. $name: module_name,
  84. $intfuseslist: intfuseslist,
  85. $impluseslist: impluseslist,
  86. $state: rtl.m_loading,
  87. $intfcode: intfcode,
  88. $implcode: implcode,
  89. $impl: null,
  90. $rtti: Object.create(rtl.tSectionRTTI)
  91. };
  92. module.$rtti.$module = module;
  93. if (implcode) module.$impl = {
  94. $module: module,
  95. $rtti: module.$rtti
  96. };
  97. },
  98. exitcode: 0,
  99. run: function(module_name){
  100. function doRun(){
  101. if (!rtl.hasString(module_name)) module_name='program';
  102. if (rtl.debug_load_units) rtl.debug('rtl.run module="'+module_name+'"');
  103. rtl.initRTTI();
  104. var module = pas[module_name];
  105. if (!module) rtl.error('rtl.run module "'+module_name+'" missing');
  106. rtl.loadintf(module);
  107. rtl.loadimpl(module);
  108. if (module_name=='program'){
  109. if (rtl.debug_load_units) rtl.debug('running $main');
  110. var r = pas.program.$main();
  111. if (rtl.isNumber(r)) rtl.exitcode = r;
  112. }
  113. }
  114. if (rtl.showUncaughtExceptions) {
  115. try{
  116. doRun();
  117. } catch(re) {
  118. var errMsg = rtl.hasString(re.$classname) ? re.$classname : '';
  119. errMsg += ((errMsg) ? ': ' : '') + (re.hasOwnProperty('fMessage') ? re.fMessage : re);
  120. alert('Uncaught Exception : '+errMsg);
  121. rtl.exitCode = 216;
  122. }
  123. } else {
  124. doRun();
  125. }
  126. return rtl.exitcode;
  127. },
  128. loadintf: function(module){
  129. if (module.$state>rtl.m_loading_intf) return; // already finished
  130. if (rtl.debug_load_units) rtl.debug('loadintf: "'+module.$name+'"');
  131. if (module.$state===rtl.m_loading_intf)
  132. rtl.error('unit cycle detected "'+module.$name+'"');
  133. module.$state=rtl.m_loading_intf;
  134. // load interfaces of interface useslist
  135. rtl.loaduseslist(module,module.$intfuseslist,rtl.loadintf);
  136. // run interface
  137. if (rtl.debug_load_units) rtl.debug('loadintf: run intf of "'+module.$name+'"');
  138. module.$intfcode(module.$intfuseslist);
  139. // success
  140. module.$state=rtl.m_intf_loaded;
  141. // Note: units only used in implementations are not yet loaded (not even their interfaces)
  142. },
  143. loaduseslist: function(module,useslist,f){
  144. if (useslist==undefined) return;
  145. for (var i in useslist){
  146. var unitname=useslist[i];
  147. if (rtl.debug_load_units) rtl.debug('loaduseslist of "'+module.$name+'" uses="'+unitname+'"');
  148. if (pas[unitname]==undefined)
  149. rtl.error('module "'+module.$name+'" misses "'+unitname+'"');
  150. f(pas[unitname]);
  151. }
  152. },
  153. loadimpl: function(module){
  154. if (module.$state>=rtl.m_loading_impl) return; // already processing
  155. if (module.$state<rtl.m_intf_loaded) rtl.error('loadimpl: interface not loaded of "'+module.$name+'"');
  156. if (rtl.debug_load_units) rtl.debug('loadimpl: load uses of "'+module.$name+'"');
  157. module.$state=rtl.m_loading_impl;
  158. // load interfaces of implementation useslist
  159. rtl.loaduseslist(module,module.$impluseslist,rtl.loadintf);
  160. // load implementation of interfaces useslist
  161. rtl.loaduseslist(module,module.$intfuseslist,rtl.loadimpl);
  162. // load implementation of implementation useslist
  163. rtl.loaduseslist(module,module.$impluseslist,rtl.loadimpl);
  164. // Note: At this point all interfaces used by this unit are loaded. If
  165. // there are implementation uses cycles some used units might not yet be
  166. // initialized. This is by design.
  167. // run implementation
  168. if (rtl.debug_load_units) rtl.debug('loadimpl: run impl of "'+module.$name+'"');
  169. if (rtl.isFunction(module.$implcode)) module.$implcode(module.$impluseslist);
  170. // run initialization
  171. if (rtl.debug_load_units) rtl.debug('loadimpl: run init of "'+module.$name+'"');
  172. module.$state=rtl.m_initializing;
  173. if (rtl.isFunction(module.$init)) module.$init();
  174. // unit initialized
  175. module.$state=rtl.m_initialized;
  176. },
  177. createCallback: function(scope, fn){
  178. var cb;
  179. if (typeof(fn)==='string'){
  180. cb = function(){
  181. return scope[fn].apply(scope,arguments);
  182. };
  183. } else {
  184. cb = function(){
  185. return fn.apply(scope,arguments);
  186. };
  187. };
  188. cb.scope = scope;
  189. cb.fn = fn;
  190. return cb;
  191. },
  192. cloneCallback: function(cb){
  193. return rtl.createCallback(cb.scope,cb.fn);
  194. },
  195. eqCallback: function(a,b){
  196. // can be a function or a function wrapper
  197. if (a==b){
  198. return true;
  199. } else {
  200. return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn==b.fn);
  201. }
  202. },
  203. initStruct: function(c,parent,name){
  204. if ((parent.$module) && (parent.$module.$impl===parent)) parent=parent.$module;
  205. c.$parent = parent;
  206. if (rtl.isModule(parent)){
  207. c.$module = parent;
  208. c.$name = name;
  209. } else {
  210. c.$module = parent.$module;
  211. c.$name = parent.$name+'.'+name;
  212. };
  213. return parent;
  214. },
  215. initClass: function(c,parent,name,initfn){
  216. parent[name] = c;
  217. c.$class = c; // Note: o.$class === Object.getPrototypeOf(o)
  218. c.$classname = name;
  219. parent = rtl.initStruct(c,parent,name);
  220. c.$fullname = parent.$name+'.'+name;
  221. // rtti
  222. if (rtl.debug_rtti) rtl.debug('initClass '+c.$fullname);
  223. var t = c.$module.$rtti.$Class(c.$name,{ "class": c });
  224. c.$rtti = t;
  225. if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
  226. if (!t.ancestor) t.ancestor = null;
  227. // init members
  228. initfn.call(c);
  229. },
  230. createClass: function(parent,name,ancestor,initfn){
  231. // create a normal class,
  232. // ancestor must be null or a normal class,
  233. // the root ancestor can be an external class
  234. var c = null;
  235. if (ancestor != null){
  236. c = Object.create(ancestor);
  237. c.$ancestor = ancestor;
  238. // Note:
  239. // if root is an "object" then c.$ancestor === Object.getPrototypeOf(c)
  240. // if root is a "function" then c.$ancestor === c.__proto__, Object.getPrototypeOf(c) returns the root
  241. } else {
  242. c = {};
  243. c.$create = function(fn,args){
  244. if (args == undefined) args = [];
  245. var o = Object.create(this);
  246. o.$init();
  247. try{
  248. if (typeof(fn)==="string"){
  249. o[fn].apply(o,args);
  250. } else {
  251. fn.apply(o,args);
  252. };
  253. o.AfterConstruction();
  254. } catch($e){
  255. // do not call BeforeDestruction
  256. if (o.Destroy) o.Destroy();
  257. o.$final();
  258. throw $e;
  259. }
  260. return o;
  261. };
  262. c.$destroy = function(fnname){
  263. this.BeforeDestruction();
  264. if (this[fnname]) this[fnname]();
  265. this.$final();
  266. };
  267. };
  268. rtl.initClass(c,parent,name,initfn);
  269. },
  270. createClassExt: function(parent,name,ancestor,newinstancefnname,initfn){
  271. // Create a class using an external ancestor.
  272. // If newinstancefnname is given, use that function to create the new object.
  273. // If exist call BeforeDestruction and AfterConstruction.
  274. var c = Object.create(ancestor);
  275. c.$create = function(fn,args){
  276. if (args == undefined) args = [];
  277. var o = null;
  278. if (newinstancefnname.length>0){
  279. o = this[newinstancefnname](fn,args);
  280. } else {
  281. o = Object.create(this);
  282. }
  283. if (o.$init) o.$init();
  284. try{
  285. if (typeof(fn)==="string"){
  286. o[fn].apply(o,args);
  287. } else {
  288. fn.apply(o,args);
  289. };
  290. if (o.AfterConstruction) o.AfterConstruction();
  291. } catch($e){
  292. // do not call BeforeDestruction
  293. if (o.Destroy) o.Destroy();
  294. if (o.$final) this.$final();
  295. throw $e;
  296. }
  297. return o;
  298. };
  299. c.$destroy = function(fnname){
  300. if (this.BeforeDestruction) this.BeforeDestruction();
  301. if (this[fnname]) this[fnname]();
  302. if (this.$final) this.$final();
  303. };
  304. rtl.initClass(c,parent,name,initfn);
  305. },
  306. tObjectDestroy: "Destroy",
  307. free: function(obj,name){
  308. if (obj[name]==null) return;
  309. obj[name].$destroy(rtl.tObjectDestroy);
  310. obj[name]=null;
  311. },
  312. freeLoc: function(obj){
  313. if (obj==null) return;
  314. obj.$destroy(rtl.tObjectDestroy);
  315. return null;
  316. },
  317. recNewT: function(parent,name,initfn,full){
  318. var t = {};
  319. if (parent) parent[name] = t;
  320. function hide(prop){
  321. Object.defineProperty(t,prop,{enumerable:false});
  322. }
  323. if (full){
  324. rtl.initStruct(t,parent,name);
  325. t.$record = t;
  326. hide('$record');
  327. hide('$name');
  328. hide('$parent');
  329. hide('$module');
  330. }
  331. initfn.call(t);
  332. if (!t.$new){
  333. t.$new = function(){ return Object.create(this); };
  334. }
  335. t.$clone = function(r){ return this.$new().$assign(r); };
  336. hide('$new');
  337. hide('$clone');
  338. hide('$eq');
  339. hide('$assign');
  340. return t;
  341. },
  342. is: function(instance,type){
  343. return type.isPrototypeOf(instance) || (instance===type);
  344. },
  345. isExt: function(instance,type,mode){
  346. // mode===1 means instance must be a Pascal class instance
  347. // mode===2 means instance must be a Pascal class
  348. // Notes:
  349. // isPrototypeOf and instanceof return false on equal
  350. // isPrototypeOf does not work for Date.isPrototypeOf(new Date())
  351. // so if isPrototypeOf is false test with instanceof
  352. // instanceof needs a function on right side
  353. if (instance == null) return false; // Note: ==null checks for undefined too
  354. if ((typeof(type) !== 'object') && (typeof(type) !== 'function')) return false;
  355. if (instance === type){
  356. if (mode===1) return false;
  357. if (mode===2) return rtl.isPasClass(instance);
  358. return true;
  359. }
  360. if (type.isPrototypeOf && type.isPrototypeOf(instance)){
  361. if (mode===1) return rtl.isPasClassInstance(instance);
  362. if (mode===2) return rtl.isPasClass(instance);
  363. return true;
  364. }
  365. if ((typeof type == 'function') && (instance instanceof type)) return true;
  366. return false;
  367. },
  368. Exception: null,
  369. EInvalidCast: null,
  370. EAbstractError: null,
  371. ERangeError: null,
  372. raiseE: function(typename){
  373. var t = rtl[typename];
  374. if (t==null){
  375. var mod = pas.SysUtils;
  376. if (!mod) mod = pas.sysutils;
  377. if (mod){
  378. t = mod[typename];
  379. if (!t) t = mod[typename.toLowerCase()];
  380. if (!t) t = mod['Exception'];
  381. if (!t) t = mod['exception'];
  382. }
  383. }
  384. if (t){
  385. if (t.Create){
  386. throw t.$create("Create");
  387. } else if (t.create){
  388. throw t.$create("create");
  389. }
  390. }
  391. if (typename === "EInvalidCast") throw "invalid type cast";
  392. if (typename === "EAbstractError") throw "Abstract method called";
  393. if (typename === "ERangeError") throw "range error";
  394. throw typename;
  395. },
  396. as: function(instance,type){
  397. if((instance === null) || rtl.is(instance,type)) return instance;
  398. rtl.raiseE("EInvalidCast");
  399. },
  400. asExt: function(instance,type,mode){
  401. if((instance === null) || rtl.isExt(instance,type,mode)) return instance;
  402. rtl.raiseE("EInvalidCast");
  403. },
  404. createInterface: function(module, name, guid, fnnames, ancestor, initfn){
  405. //console.log('createInterface name="'+name+'" guid="'+guid+'" names='+fnnames);
  406. var i = ancestor?Object.create(ancestor):{};
  407. module[name] = i;
  408. i.$module = module;
  409. i.$name = name;
  410. i.$fullname = module.$name+'.'+name;
  411. i.$guid = guid;
  412. i.$guidr = null;
  413. i.$names = fnnames?fnnames:[];
  414. if (rtl.isFunction(initfn)){
  415. // rtti
  416. if (rtl.debug_rtti) rtl.debug('createInterface '+i.$fullname);
  417. var t = i.$module.$rtti.$Interface(name,{ "interface": i, module: module });
  418. i.$rtti = t;
  419. if (ancestor) t.ancestor = ancestor.$rtti;
  420. if (!t.ancestor) t.ancestor = null;
  421. initfn.call(i);
  422. }
  423. return i;
  424. },
  425. strToGUIDR: function(s,g){
  426. var p = 0;
  427. function n(l){
  428. var h = s.substr(p,l);
  429. p+=l;
  430. return parseInt(h,16);
  431. }
  432. p+=1; // skip {
  433. g.D1 = n(8);
  434. p+=1; // skip -
  435. g.D2 = n(4);
  436. p+=1; // skip -
  437. g.D3 = n(4);
  438. p+=1; // skip -
  439. if (!g.D4) g.D4=[];
  440. g.D4[0] = n(2);
  441. g.D4[1] = n(2);
  442. p+=1; // skip -
  443. for(var i=2; i<8; i++) g.D4[i] = n(2);
  444. return g;
  445. },
  446. guidrToStr: function(g){
  447. if (g.$intf) return g.$intf.$guid;
  448. var h = rtl.hexStr;
  449. var s='{'+h(g.D1,8)+'-'+h(g.D2,4)+'-'+h(g.D3,4)+'-'+h(g.D4[0],2)+h(g.D4[1],2)+'-';
  450. for (var i=2; i<8; i++) s+=h(g.D4[i],2);
  451. s+='}';
  452. return s;
  453. },
  454. createTGUID: function(guid){
  455. var TGuid = (pas.System)?pas.System.TGuid:pas.system.tguid;
  456. var g = rtl.strToGUIDR(guid,TGuid.$new());
  457. return g;
  458. },
  459. getIntfGUIDR: function(intfTypeOrVar){
  460. if (!intfTypeOrVar) return null;
  461. if (!intfTypeOrVar.$guidr){
  462. var g = rtl.createTGUID(intfTypeOrVar.$guid);
  463. if (!intfTypeOrVar.hasOwnProperty('$guid')) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
  464. g.$intf = intfTypeOrVar;
  465. intfTypeOrVar.$guidr = g;
  466. }
  467. return intfTypeOrVar.$guidr;
  468. },
  469. addIntf: function (aclass, intf, map){
  470. function jmp(fn){
  471. if (typeof(fn)==="function"){
  472. return function(){ return fn.apply(this.$o,arguments); };
  473. } else {
  474. return function(){ rtl.raiseE('EAbstractError'); };
  475. }
  476. }
  477. if(!map) map = {};
  478. var t = intf;
  479. var item = Object.create(t);
  480. if (!aclass.hasOwnProperty('$intfmaps')) aclass.$intfmaps = {};
  481. aclass.$intfmaps[intf.$guid] = item;
  482. do{
  483. var names = t.$names;
  484. if (!names) break;
  485. for (var i=0; i<names.length; i++){
  486. var intfname = names[i];
  487. var fnname = map[intfname];
  488. if (!fnname) fnname = intfname;
  489. //console.log('addIntf: intftype='+t.$name+' index='+i+' intfname="'+intfname+'" fnname="'+fnname+'" old='+typeof(item[intfname]));
  490. item[intfname] = jmp(aclass[fnname]);
  491. }
  492. t = Object.getPrototypeOf(t);
  493. }while(t!=null);
  494. },
  495. getIntfG: function (obj, guid, query){
  496. if (!obj) return null;
  497. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query);
  498. // search
  499. var maps = obj.$intfmaps;
  500. if (!maps) return null;
  501. var item = maps[guid];
  502. if (!item) return null;
  503. // check delegation
  504. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query+' item='+typeof(item));
  505. if (typeof item === 'function') return item.call(obj); // delegate. Note: COM contains _AddRef
  506. // check cache
  507. var intf = null;
  508. if (obj.$interfaces){
  509. intf = obj.$interfaces[guid];
  510. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' cache='+typeof(intf));
  511. }
  512. if (!intf){ // intf can be undefined!
  513. intf = Object.create(item);
  514. intf.$o = obj;
  515. if (!obj.$interfaces) obj.$interfaces = {};
  516. obj.$interfaces[guid] = intf;
  517. }
  518. if (typeof(query)==='object'){
  519. // called by queryIntfT
  520. var o = null;
  521. if (intf.QueryInterface(rtl.getIntfGUIDR(query),
  522. {get:function(){ return o; }, set:function(v){ o=v; }}) === 0){
  523. return o;
  524. } else {
  525. return null;
  526. }
  527. } else if(query===2){
  528. // called by TObject.GetInterfaceByStr
  529. if (intf.$kind === 'com') intf._AddRef();
  530. }
  531. return intf;
  532. },
  533. getIntfT: function(obj,intftype){
  534. return rtl.getIntfG(obj,intftype.$guid);
  535. },
  536. queryIntfT: function(obj,intftype){
  537. return rtl.getIntfG(obj,intftype.$guid,intftype);
  538. },
  539. queryIntfIsT: function(obj,intftype){
  540. var i = rtl.queryIntfG(obj,intftype.$guid);
  541. if (!i) return false;
  542. if (i.$kind === 'com') i._Release();
  543. return true;
  544. },
  545. asIntfT: function (obj,intftype){
  546. var i = rtl.getIntfG(obj,intftype.$guid);
  547. if (i!==null) return i;
  548. rtl.raiseEInvalidCast();
  549. },
  550. intfIsClass: function(intf,classtype){
  551. return (intf!=null) && (rtl.is(intf.$o,classtype));
  552. },
  553. intfAsClass: function(intf,classtype){
  554. if (intf==null) return null;
  555. return rtl.as(intf.$o,classtype);
  556. },
  557. intfToClass: function(intf,classtype){
  558. if ((intf!==null) && rtl.is(intf.$o,classtype)) return intf.$o;
  559. return null;
  560. },
  561. // interface reference counting
  562. intfRefs: { // base object for temporary interface variables
  563. ref: function(id,intf){
  564. // called for temporary interface references needing delayed release
  565. var old = this[id];
  566. //console.log('rtl.intfRefs.ref: id='+id+' old="'+(old?old.$name:'null')+'" intf="'+(intf?intf.$name:'null')+' $o='+(intf?intf.$o:'null'));
  567. if (old){
  568. // called again, e.g. in a loop
  569. delete this[id];
  570. old._Release(); // may fail
  571. }
  572. this[id]=intf;
  573. return intf;
  574. },
  575. free: function(){
  576. //console.log('rtl.intfRefs.free...');
  577. for (var id in this){
  578. if (this.hasOwnProperty(id)){
  579. //console.log('rtl.intfRefs.free: id='+id+' '+this[id].$name+' $o='+this[id].$o.$classname);
  580. this[id]._Release();
  581. }
  582. }
  583. }
  584. },
  585. createIntfRefs: function(){
  586. //console.log('rtl.createIntfRefs');
  587. return Object.create(rtl.intfRefs);
  588. },
  589. setIntfP: function(path,name,value,skipAddRef){
  590. var old = path[name];
  591. //console.log('rtl.setIntfP path='+path+' name='+name+' old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  592. if (old === value) return;
  593. if (old !== null){
  594. path[name]=null;
  595. old._Release();
  596. }
  597. if (value !== null){
  598. if (!skipAddRef) value._AddRef();
  599. path[name]=value;
  600. }
  601. },
  602. setIntfL: function(old,value,skipAddRef){
  603. //console.log('rtl.setIntfL old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  604. if (old !== value){
  605. if (value!==null){
  606. if (!skipAddRef) value._AddRef();
  607. }
  608. if (old!==null){
  609. old._Release(); // Release after AddRef, to avoid double Release if Release creates an exception
  610. }
  611. } else if (skipAddRef){
  612. if (old!==null){
  613. old._Release(); // value has an AddRef
  614. }
  615. }
  616. return value;
  617. },
  618. _AddRef: function(intf){
  619. //if (intf) console.log('rtl._AddRef intf="'+(intf?intf.$name:'null')+'"');
  620. if (intf) intf._AddRef();
  621. return intf;
  622. },
  623. _Release: function(intf){
  624. //if (intf) console.log('rtl._Release intf="'+(intf?intf.$name:'null')+'"');
  625. if (intf) intf._Release();
  626. return intf;
  627. },
  628. checkMethodCall: function(obj,type){
  629. if (rtl.isObject(obj) && rtl.is(obj,type)) return;
  630. rtl.raiseE("EInvalidCast");
  631. },
  632. rc: function(i,minval,maxval){
  633. // range check integer
  634. if ((Math.floor(i)===i) && (i>=minval) && (i<=maxval)) return i;
  635. rtl.raiseE('ERangeError');
  636. },
  637. rcc: function(c,minval,maxval){
  638. // range check char
  639. if ((typeof(c)==='string') && (c.length===1)){
  640. var i = c.charCodeAt(0);
  641. if ((i>=minval) && (i<=maxval)) return c;
  642. }
  643. rtl.raiseE('ERangeError');
  644. },
  645. rcSetCharAt: function(s,index,c){
  646. // range check setCharAt
  647. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  648. return rtl.setCharAt(s,index,c);
  649. },
  650. rcCharAt: function(s,index){
  651. // range check charAt
  652. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  653. return s.charAt(index);
  654. },
  655. rcArrR: function(arr,index){
  656. // range check read array
  657. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  658. if (arguments.length>2){
  659. // arr,index1,index2,...
  660. arr=arr[index];
  661. for (var i=2; i<arguments.length; i++) arr=rtl.rcArrR(arr,arguments[i]);
  662. return arr;
  663. }
  664. return arr[index];
  665. }
  666. rtl.raiseE('ERangeError');
  667. },
  668. rcArrW: function(arr,index,value){
  669. // range check write array
  670. // arr,index1,index2,...,value
  671. for (var i=3; i<arguments.length; i++){
  672. arr=rtl.rcArrR(arr,index);
  673. index=arguments[i-1];
  674. value=arguments[i];
  675. }
  676. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  677. return arr[index]=value;
  678. }
  679. rtl.raiseE('ERangeError');
  680. },
  681. length: function(arr){
  682. return (arr == null) ? 0 : arr.length;
  683. },
  684. arraySetLength: function(arr,defaultvalue,newlength){
  685. // multi dim: (arr,defaultvalue,dim1,dim2,...)
  686. if (arr == null) arr = [];
  687. var p = arguments;
  688. function setLength(a,argNo){
  689. var oldlen = a.length;
  690. var newlen = p[argNo];
  691. if (oldlen!==newlength){
  692. a.length = newlength;
  693. if (argNo === p.length-1){
  694. if (rtl.isArray(defaultvalue)){
  695. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  696. } else if (rtl.isObject(defaultvalue)) {
  697. if (rtl.isTRecord(defaultvalue)){
  698. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue.$new(); // e.g. record
  699. } else {
  700. for (var i=oldlen; i<newlen; i++) a[i]={}; // e.g. set
  701. }
  702. } else {
  703. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue;
  704. }
  705. } else {
  706. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  707. }
  708. }
  709. if (argNo < p.length-1){
  710. // multi argNo
  711. for (var i=0; i<newlen; i++) a[i]=setLength(a[i],argNo+1);
  712. }
  713. return a;
  714. }
  715. return setLength(arr,2);
  716. },
  717. arrayEq: function(a,b){
  718. if (a===null) return b===null;
  719. if (b===null) return false;
  720. if (a.length!==b.length) return false;
  721. for (var i=0; i<a.length; i++) if (a[i]!==b[i]) return false;
  722. return true;
  723. },
  724. arrayClone: function(type,src,srcpos,endpos,dst,dstpos){
  725. // type: 0 for references, "refset" for calling refSet(), a function for new type()
  726. // src must not be null
  727. // This function does not range check.
  728. if(type === 'refSet') {
  729. for (; srcpos<endpos; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]); // ref set
  730. } else if (rtl.isTRecord(type)){
  731. for (; srcpos<endpos; srcpos++) dst[dstpos++] = type.$clone(src[srcpos]); // clone record
  732. } else {
  733. for (; srcpos<endpos; srcpos++) dst[dstpos++] = src[srcpos]; // reference
  734. };
  735. },
  736. arrayConcat: function(type){
  737. // type: see rtl.arrayClone
  738. var a = [];
  739. var l = 0;
  740. for (var i=1; i<arguments.length; i++){
  741. var src = arguments[i];
  742. if (src !== null) l+=src.length;
  743. };
  744. a.length = l;
  745. l=0;
  746. for (var i=1; i<arguments.length; i++){
  747. var src = arguments[i];
  748. if (src === null) continue;
  749. rtl.arrayClone(type,src,0,src.length,a,l);
  750. l+=src.length;
  751. };
  752. return a;
  753. },
  754. arrayConcatN: function(){
  755. var a = null;
  756. for (var i=1; i<arguments.length; i++){
  757. var src = arguments[i];
  758. if (src === null) continue;
  759. if (a===null){
  760. a=src; // Note: concat(a) does not clone
  761. } else {
  762. a=a.concat(src);
  763. }
  764. };
  765. return a;
  766. },
  767. arrayCopy: function(type, srcarray, index, count){
  768. // type: see rtl.arrayClone
  769. // if count is missing, use srcarray.length
  770. if (srcarray === null) return [];
  771. if (index < 0) index = 0;
  772. if (count === undefined) count=srcarray.length;
  773. var end = index+count;
  774. if (end>srcarray.length) end = srcarray.length;
  775. if (index>=end) return [];
  776. if (type===0){
  777. return srcarray.slice(index,end);
  778. } else {
  779. var a = [];
  780. a.length = end-index;
  781. rtl.arrayClone(type,srcarray,index,end,a,0);
  782. return a;
  783. }
  784. },
  785. setCharAt: function(s,index,c){
  786. return s.substr(0,index)+c+s.substr(index+1);
  787. },
  788. getResStr: function(mod,name){
  789. var rs = mod.$resourcestrings[name];
  790. return rs.current?rs.current:rs.org;
  791. },
  792. createSet: function(){
  793. var s = {};
  794. for (var i=0; i<arguments.length; i++){
  795. if (arguments[i]!=null){
  796. s[arguments[i]]=true;
  797. } else {
  798. var first=arguments[i+=1];
  799. var last=arguments[i+=1];
  800. for(var j=first; j<=last; j++) s[j]=true;
  801. }
  802. }
  803. return s;
  804. },
  805. cloneSet: function(s){
  806. var r = {};
  807. for (var key in s) r[key]=true;
  808. return r;
  809. },
  810. refSet: function(s){
  811. Object.defineProperty(s, '$shared', {
  812. enumerable: false,
  813. configurable: true,
  814. writable: true,
  815. value: true
  816. });
  817. return s;
  818. },
  819. includeSet: function(s,enumvalue){
  820. if (s.$shared) s = rtl.cloneSet(s);
  821. s[enumvalue] = true;
  822. return s;
  823. },
  824. excludeSet: function(s,enumvalue){
  825. if (s.$shared) s = rtl.cloneSet(s);
  826. delete s[enumvalue];
  827. return s;
  828. },
  829. diffSet: function(s,t){
  830. var r = {};
  831. for (var key in s) if (!t[key]) r[key]=true;
  832. return r;
  833. },
  834. unionSet: function(s,t){
  835. var r = {};
  836. for (var key in s) r[key]=true;
  837. for (var key in t) r[key]=true;
  838. return r;
  839. },
  840. intersectSet: function(s,t){
  841. var r = {};
  842. for (var key in s) if (t[key]) r[key]=true;
  843. return r;
  844. },
  845. symDiffSet: function(s,t){
  846. var r = {};
  847. for (var key in s) if (!t[key]) r[key]=true;
  848. for (var key in t) if (!s[key]) r[key]=true;
  849. return r;
  850. },
  851. eqSet: function(s,t){
  852. for (var key in s) if (!t[key]) return false;
  853. for (var key in t) if (!s[key]) return false;
  854. return true;
  855. },
  856. neSet: function(s,t){
  857. return !rtl.eqSet(s,t);
  858. },
  859. leSet: function(s,t){
  860. for (var key in s) if (!t[key]) return false;
  861. return true;
  862. },
  863. geSet: function(s,t){
  864. for (var key in t) if (!s[key]) return false;
  865. return true;
  866. },
  867. strSetLength: function(s,newlen){
  868. var oldlen = s.length;
  869. if (oldlen > newlen){
  870. return s.substring(0,newlen);
  871. } else if (s.repeat){
  872. // Note: repeat needs ECMAScript6!
  873. return s+' '.repeat(newlen-oldlen);
  874. } else {
  875. while (oldlen<newlen){
  876. s+=' ';
  877. oldlen++;
  878. };
  879. return s;
  880. }
  881. },
  882. spaceLeft: function(s,width){
  883. var l=s.length;
  884. if (l>=width) return s;
  885. if (s.repeat){
  886. // Note: repeat needs ECMAScript6!
  887. return ' '.repeat(width-l) + s;
  888. } else {
  889. while (l<width){
  890. s=' '+s;
  891. l++;
  892. };
  893. };
  894. },
  895. floatToStr: function(d,w,p){
  896. // input 1-3 arguments: double, width, precision
  897. if (arguments.length>2){
  898. return rtl.spaceLeft(d.toFixed(p),w);
  899. } else {
  900. // exponent width
  901. var pad = "";
  902. var ad = Math.abs(d);
  903. if (ad<1.0e+10) {
  904. pad='00';
  905. } else if (ad<1.0e+100) {
  906. pad='0';
  907. }
  908. if (arguments.length<2) {
  909. w=9;
  910. } else if (w<9) {
  911. w=9;
  912. }
  913. var p = w-8;
  914. var s=(d>0 ? " " : "" ) + d.toExponential(p);
  915. s=s.replace(/e(.)/,'E$1'+pad);
  916. return rtl.spaceLeft(s,w);
  917. }
  918. },
  919. valEnum: function(s, enumType, setCodeFn){
  920. s = s.toLowerCase();
  921. for (var key in enumType){
  922. if((typeof(key)==='string') && (key.toLowerCase()===s)){
  923. setCodeFn(0);
  924. return enumType[key];
  925. }
  926. }
  927. setCodeFn(1);
  928. return 0;
  929. },
  930. initRTTI: function(){
  931. if (rtl.debug_rtti) rtl.debug('initRTTI');
  932. // base types
  933. rtl.tTypeInfo = { name: "tTypeInfo" };
  934. function newBaseTI(name,kind,ancestor){
  935. if (!ancestor) ancestor = rtl.tTypeInfo;
  936. if (rtl.debug_rtti) rtl.debug('initRTTI.newBaseTI "'+name+'" '+kind+' ("'+ancestor.name+'")');
  937. var t = Object.create(ancestor);
  938. t.name = name;
  939. t.kind = kind;
  940. rtl[name] = t;
  941. return t;
  942. };
  943. function newBaseInt(name,minvalue,maxvalue,ordtype){
  944. var t = newBaseTI(name,1 /* tkInteger */,rtl.tTypeInfoInteger);
  945. t.minvalue = minvalue;
  946. t.maxvalue = maxvalue;
  947. t.ordtype = ordtype;
  948. return t;
  949. };
  950. newBaseTI("tTypeInfoInteger",1 /* tkInteger */);
  951. newBaseInt("shortint",-0x80,0x7f,0);
  952. newBaseInt("byte",0,0xff,1);
  953. newBaseInt("smallint",-0x8000,0x7fff,2);
  954. newBaseInt("word",0,0xffff,3);
  955. newBaseInt("longint",-0x80000000,0x7fffffff,4);
  956. newBaseInt("longword",0,0xffffffff,5);
  957. newBaseInt("nativeint",-0x10000000000000,0xfffffffffffff,6);
  958. newBaseInt("nativeuint",0,0xfffffffffffff,7);
  959. newBaseTI("char",2 /* tkChar */);
  960. newBaseTI("string",3 /* tkString */);
  961. newBaseTI("tTypeInfoEnum",4 /* tkEnumeration */,rtl.tTypeInfoInteger);
  962. newBaseTI("tTypeInfoSet",5 /* tkSet */);
  963. newBaseTI("double",6 /* tkDouble */);
  964. newBaseTI("boolean",7 /* tkBool */);
  965. newBaseTI("tTypeInfoProcVar",8 /* tkProcVar */);
  966. newBaseTI("tTypeInfoMethodVar",9 /* tkMethod */,rtl.tTypeInfoProcVar);
  967. newBaseTI("tTypeInfoArray",10 /* tkArray */);
  968. newBaseTI("tTypeInfoDynArray",11 /* tkDynArray */);
  969. newBaseTI("tTypeInfoPointer",15 /* tkPointer */);
  970. var t = newBaseTI("pointer",15 /* tkPointer */,rtl.tTypeInfoPointer);
  971. t.reftype = null;
  972. newBaseTI("jsvalue",16 /* tkJSValue */);
  973. newBaseTI("tTypeInfoRefToProcVar",17 /* tkRefToProcVar */,rtl.tTypeInfoProcVar);
  974. // member kinds
  975. rtl.tTypeMember = {};
  976. function newMember(name,kind){
  977. var m = Object.create(rtl.tTypeMember);
  978. m.name = name;
  979. m.kind = kind;
  980. rtl[name] = m;
  981. };
  982. newMember("tTypeMemberField",1); // tmkField
  983. newMember("tTypeMemberMethod",2); // tmkMethod
  984. newMember("tTypeMemberProperty",3); // tmkProperty
  985. // base object for storing members: a simple object
  986. rtl.tTypeMembers = {};
  987. // tTypeInfoStruct - base object for tTypeInfoClass, tTypeInfoRecord, tTypeInfoInterface
  988. var tis = newBaseTI("tTypeInfoStruct",0);
  989. tis.$addMember = function(name,ancestor,options){
  990. if (rtl.debug_rtti){
  991. if (!rtl.hasString(name) || (name.charAt()==='$')) throw 'invalid member "'+name+'", this="'+this.name+'"';
  992. if (!rtl.is(ancestor,rtl.tTypeMember)) throw 'invalid ancestor "'+ancestor+':'+ancestor.name+'", "'+this.name+'.'+name+'"';
  993. if ((options!=undefined) && (typeof(options)!='object')) throw 'invalid options "'+options+'", "'+this.name+'.'+name+'"';
  994. };
  995. var t = Object.create(ancestor);
  996. t.name = name;
  997. this.members[name] = t;
  998. this.names.push(name);
  999. if (rtl.isObject(options)){
  1000. for (var key in options) if (options.hasOwnProperty(key)) t[key] = options[key];
  1001. };
  1002. return t;
  1003. };
  1004. tis.addField = function(name,type,options){
  1005. var t = this.$addMember(name,rtl.tTypeMemberField,options);
  1006. if (rtl.debug_rtti){
  1007. if (!rtl.is(type,rtl.tTypeInfo)) throw 'invalid type "'+type+'", "'+this.name+'.'+name+'"';
  1008. };
  1009. t.typeinfo = type;
  1010. this.fields.push(name);
  1011. return t;
  1012. };
  1013. tis.addFields = function(){
  1014. var i=0;
  1015. while(i<arguments.length){
  1016. var name = arguments[i++];
  1017. var type = arguments[i++];
  1018. if ((i<arguments.length) && (typeof(arguments[i])==='object')){
  1019. this.addField(name,type,arguments[i++]);
  1020. } else {
  1021. this.addField(name,type);
  1022. };
  1023. };
  1024. };
  1025. tis.addMethod = function(name,methodkind,params,result,options){
  1026. var t = this.$addMember(name,rtl.tTypeMemberMethod,options);
  1027. t.methodkind = methodkind;
  1028. t.procsig = rtl.newTIProcSig(params);
  1029. t.procsig.resulttype = result?result:null;
  1030. this.methods.push(name);
  1031. return t;
  1032. };
  1033. tis.addProperty = function(name,flags,result,getter,setter,options){
  1034. var t = this.$addMember(name,rtl.tTypeMemberProperty,options);
  1035. t.flags = flags;
  1036. t.typeinfo = result;
  1037. t.getter = getter;
  1038. t.setter = setter;
  1039. // Note: in options: params, stored, defaultvalue
  1040. if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
  1041. this.properties.push(name);
  1042. if (!rtl.isString(t.stored)) t.stored = "";
  1043. return t;
  1044. };
  1045. tis.getField = function(index){
  1046. return this.members[this.fields[index]];
  1047. };
  1048. tis.getMethod = function(index){
  1049. return this.members[this.methods[index]];
  1050. };
  1051. tis.getProperty = function(index){
  1052. return this.members[this.properties[index]];
  1053. };
  1054. newBaseTI("tTypeInfoRecord",12 /* tkRecord */,rtl.tTypeInfoStruct);
  1055. newBaseTI("tTypeInfoClass",13 /* tkClass */,rtl.tTypeInfoStruct);
  1056. newBaseTI("tTypeInfoClassRef",14 /* tkClassRef */);
  1057. newBaseTI("tTypeInfoInterface",15 /* tkInterface */,rtl.tTypeInfoStruct);
  1058. },
  1059. tSectionRTTI: {
  1060. $module: null,
  1061. $inherited: function(name,ancestor,o){
  1062. if (rtl.debug_rtti){
  1063. rtl.debug('tSectionRTTI.newTI "'+(this.$module?this.$module.$name:"(no module)")
  1064. +'"."'+name+'" ('+ancestor.name+') '+(o?'init':'forward'));
  1065. };
  1066. var t = this[name];
  1067. if (t){
  1068. if (!t.$forward) throw 'duplicate type "'+name+'"';
  1069. if (!ancestor.isPrototypeOf(t)) throw 'typeinfo ancestor mismatch "'+name+'" ancestor="'+ancestor.name+'" t.name="'+t.name+'"';
  1070. } else {
  1071. t = Object.create(ancestor);
  1072. t.name = name;
  1073. t.$module = this.$module;
  1074. this[name] = t;
  1075. }
  1076. if (o){
  1077. delete t.$forward;
  1078. for (var key in o) if (o.hasOwnProperty(key)) t[key]=o[key];
  1079. } else {
  1080. t.$forward = true;
  1081. }
  1082. return t;
  1083. },
  1084. $Scope: function(name,ancestor,o){
  1085. var t=this.$inherited(name,ancestor,o);
  1086. t.members = {};
  1087. t.names = [];
  1088. t.fields = [];
  1089. t.methods = [];
  1090. t.properties = [];
  1091. return t;
  1092. },
  1093. $TI: function(name,kind,o){ var t=this.$inherited(name,rtl.tTypeInfo,o); t.kind = kind; return t; },
  1094. $Int: function(name,o){ return this.$inherited(name,rtl.tTypeInfoInteger,o); },
  1095. $Enum: function(name,o){ return this.$inherited(name,rtl.tTypeInfoEnum,o); },
  1096. $Set: function(name,o){ return this.$inherited(name,rtl.tTypeInfoSet,o); },
  1097. $StaticArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoArray,o); },
  1098. $DynArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoDynArray,o); },
  1099. $ProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoProcVar,o); },
  1100. $RefToProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoRefToProcVar,o); },
  1101. $MethodVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoMethodVar,o); },
  1102. $Record: function(name,o){ return this.$Scope(name,rtl.tTypeInfoRecord,o); },
  1103. $Class: function(name,o){ return this.$Scope(name,rtl.tTypeInfoClass,o); },
  1104. $ClassRef: function(name,o){ return this.$inherited(name,rtl.tTypeInfoClassRef,o); },
  1105. $Pointer: function(name,o){ return this.$inherited(name,rtl.tTypeInfoPointer,o); },
  1106. $Interface: function(name,o){ return this.$Scope(name,rtl.tTypeInfoInterface,o); }
  1107. },
  1108. newTIParam: function(param){
  1109. // param is an array, 0=name, 1=type, 2=optional flags
  1110. var t = {
  1111. name: param[0],
  1112. typeinfo: param[1],
  1113. flags: (rtl.isNumber(param[2]) ? param[2] : 0)
  1114. };
  1115. return t;
  1116. },
  1117. newTIParams: function(list){
  1118. // list: optional array of [paramname,typeinfo,optional flags]
  1119. var params = [];
  1120. if (rtl.isArray(list)){
  1121. for (var i=0; i<list.length; i++) params.push(rtl.newTIParam(list[i]));
  1122. };
  1123. return params;
  1124. },
  1125. newTIProcSig: function(params,result,flags){
  1126. var s = {
  1127. params: rtl.newTIParams(params),
  1128. resulttype: result,
  1129. flags: flags
  1130. };
  1131. return s;
  1132. }
  1133. }