rtl.js 37 KB

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