daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Dec 20th, 2018 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var pas = {};
  2.  
  3. var rtl = {
  4.  
  5.   version: 10301,
  6.  
  7.   quiet: false,
  8.   debug_load_units: false,
  9.   debug_rtti: false,
  10.  
  11.   debug: function () {
  12.     if (rtl.quiet || !console || !console.log) return;
  13.     console.log(arguments);
  14.   },
  15.  
  16.   error: function (s) {
  17.     rtl.debug("Error: ", s);
  18.     throw s;
  19.   },
  20.  
  21.   warn: function (s) {
  22.     rtl.debug("Warn: ", s);
  23.   },
  24.  
  25.   checkVersion: function (v) {
  26.     if (rtl.version != v) throw "expected rtl version " + v + ", but found " + rtl.version;
  27.   },
  28.  
  29.   hasString: function (s) {
  30.     return rtl.isString(s) && (s.length > 0);
  31.   },
  32.  
  33.   isArray: function (a) {
  34.     return Array.isArray(a);
  35.   },
  36.  
  37.   isFunction: function (f) {
  38.     return typeof (f) === "function";
  39.   },
  40.  
  41.   isModule: function (m) {
  42.     return rtl.isObject(m) && rtl.hasString(m.$name) && (pas[m.$name] === m);
  43.   },
  44.  
  45.   isImplementation: function (m) {
  46.     return rtl.isObject(m) && rtl.isModule(m.$module) && (m.$module.$impl === m);
  47.   },
  48.  
  49.   isNumber: function (n) {
  50.     return typeof (n) === "number";
  51.   },
  52.  
  53.   isObject: function (o) {
  54.     return (typeof (o) === "object") && (o != null);
  55.   },
  56.  
  57.   isString: function (s) {
  58.     return typeof (s) === "string";
  59.   },
  60.  
  61.   getNumber: function (n) {
  62.     return typeof (n) === "number" ? n : NaN;
  63.   },
  64.  
  65.   getChar: function (c) {
  66.     return ((typeof (c) === "string") && (c.length === 1)) ? c : "";
  67.   },
  68.  
  69.   getObject: function (o) {
  70.     return ((typeof (o) === "object") || (typeof (o) === "function")) ? o : null;
  71.   },
  72.  
  73.   isPasClass: function (type) {
  74.     return (rtl.isObject(type) && type.hasOwnProperty("$classname") && rtl.isObject(type.$module));
  75.   },
  76.  
  77.   isPasClassInstance: function (type) {
  78.     return (rtl.isObject(type) && rtl.isPasClass(type.$class));
  79.   },
  80.  
  81.   hexStr: function (n, digits) {
  82.     return ("000000000000000" + n.toString(16).toUpperCase()).slice(-digits);
  83.   },
  84.  
  85.   m_loading: 0,
  86.   m_loading_intf: 1,
  87.   m_intf_loaded: 2,
  88.   m_loading_impl: 3,
  89.   m_initializing: 4,
  90.   m_initialized: 5,
  91.  
  92.   module: function (module_name, intfuseslist, intfcode, impluseslist, implcode) {
  93.     if (rtl.debug_load_units) rtl.debug("rtl.module name=\"" + module_name + "\" intfuses=" + intfuseslist + " impluses=" + impluseslist + " hasimplcode=" + rtl.isFunction(implcode));
  94.     if (!rtl.hasString(module_name)) rtl.error("invalid module name \"" + module_name + "\"");
  95.     if (!rtl.isArray(intfuseslist)) rtl.error("invalid interface useslist of \"" + module_name + "\"");
  96.     if (!rtl.isFunction(intfcode)) rtl.error("invalid interface code of \"" + module_name + "\"");
  97.     if (!(impluseslist == undefined) && !rtl.isArray(impluseslist)) rtl.error("invalid implementation useslist of \"" + module_name + "\"");
  98.     if (!(implcode == undefined) && !rtl.isFunction(implcode)) rtl.error("invalid implementation code of \"" + module_name + "\"");
  99.  
  100.     if (pas[module_name])
  101.       rtl.error("module \"" + module_name + "\" is already registered");
  102.  
  103.     var module = pas[module_name] = {
  104.       $name: module_name,
  105.       $intfuseslist: intfuseslist,
  106.       $impluseslist: impluseslist,
  107.       $state: rtl.m_loading,
  108.       $intfcode: intfcode,
  109.       $implcode: implcode,
  110.       $impl: null,
  111.       $rtti: Object.create(rtl.tSectionRTTI)
  112.     };
  113.     module.$rtti.$module = module;
  114.     if (implcode) module.$impl = {
  115.       $module: module,
  116.       $rtti: module.$rtti
  117.     };
  118.   },
  119.  
  120.   exitcode: 0,
  121.  
  122.   run: function (module_name) {
  123.  
  124.     function doRun() {
  125.       if (!rtl.hasString(module_name)) module_name = "program";
  126.       if (rtl.debug_load_units) rtl.debug("rtl.run module=\"" + module_name + "\"");
  127.       rtl.initRTTI();
  128.       var module = pas[module_name];
  129.       if (!module) rtl.error("rtl.run module \"" + module_name + "\" missing");
  130.       rtl.loadintf(module);
  131.       rtl.loadimpl(module);
  132.       if (module_name == "program") {
  133.         if (rtl.debug_load_units) rtl.debug("running $main");
  134.         var r = pas.program.$main();
  135.         if (rtl.isNumber(r)) rtl.exitcode = r;
  136.       }
  137.     }
  138.  
  139.     if (rtl.showUncaughtExceptions) {
  140.       try {
  141.         doRun();
  142.       } catch (re) {
  143.         var errMsg = re.hasOwnProperty("$class") ? re.$class.$classname : "";
  144.         errMsg += ((errMsg) ? ": " : "") + (re.hasOwnProperty("fMessage") ? re.fMessage : re);
  145.         alert("Uncaught Exception : " + errMsg);
  146.         rtl.exitCode = 216;
  147.       }
  148.     } else {
  149.       doRun();
  150.     }
  151.     return rtl.exitcode;
  152.   },
  153.  
  154.   loadintf: function (module) {
  155.     if (module.$state > rtl.m_loading_intf) return;
  156.     if (rtl.debug_load_units) rtl.debug("loadintf: \"" + module.$name + "\"");
  157.     if (module.$state === rtl.m_loading_intf)
  158.       rtl.error("unit cycle detected \"" + module.$name + "\"");
  159.     module.$state = rtl.m_loading_intf;
  160.     rtl.loaduseslist(module, module.$intfuseslist, rtl.loadintf);
  161.     if (rtl.debug_load_units) rtl.debug("loadintf: run intf of \"" + module.$name + "\"");
  162.     module.$intfcode(module.$intfuseslist);
  163.     module.$state = rtl.m_intf_loaded;
  164.   },
  165.  
  166.   loaduseslist: function (module, useslist, f) {
  167.     if (useslist == undefined) return;
  168.     for (var i in useslist) {
  169.       var unitname = useslist[i];
  170.       if (rtl.debug_load_units) rtl.debug("loaduseslist of \"" + module.$name + "\" uses=\"" + unitname + "\"");
  171.       if (pas[unitname] == undefined)
  172.         rtl.error("module \"" + module.$name + "\" misses \"" + unitname + "\"");
  173.       f(pas[unitname]);
  174.     }
  175.   },
  176.  
  177.   loadimpl: function (module) {
  178.     if (module.$state >= rtl.m_loading_impl) return;
  179.     if (module.$state < rtl.m_intf_loaded) rtl.error("loadimpl: interface not loaded of \"" + module.$name + "\"");
  180.     if (rtl.debug_load_units) rtl.debug("loadimpl: load uses of \"" + module.$name + "\"");
  181.     module.$state = rtl.m_loading_impl;
  182.     rtl.loaduseslist(module, module.$impluseslist, rtl.loadintf);
  183.     rtl.loaduseslist(module, module.$intfuseslist, rtl.loadimpl);
  184.     rtl.loaduseslist(module, module.$impluseslist, rtl.loadimpl);
  185.     if (rtl.debug_load_units) rtl.debug("loadimpl: run impl of \"" + module.$name + "\"");
  186.     if (rtl.isFunction(module.$implcode)) module.$implcode(module.$impluseslist);
  187.     if (rtl.debug_load_units) rtl.debug("loadimpl: run init of \"" + module.$name + "\"");
  188.     module.$state = rtl.m_initializing;
  189.     if (rtl.isFunction(module.$init)) module.$init();
  190.     module.$state = rtl.m_initialized;
  191.   },
  192.  
  193.   createCallback: function (scope, fn) {
  194.     var cb;
  195.     if (typeof (fn) === "string") {
  196.       cb = function () {
  197.         return scope[fn].apply(scope, arguments);
  198.       };
  199.     } else {
  200.       cb = function () {
  201.         return fn.apply(scope, arguments);
  202.       };
  203.     }
  204.     cb.scope = scope;
  205.     cb.fn = fn;
  206.     return cb;
  207.   },
  208.  
  209.   cloneCallback: function (cb) {
  210.     return rtl.createCallback(cb.scope, cb.fn);
  211.   },
  212.  
  213.   eqCallback: function (a, b) {
  214.     if (a == b) {
  215.       return true;
  216.     } else {
  217.       return (a != null) && (b != null) && (a.fn) && (a.scope === b.scope) && (a.fn == b.fn);
  218.     }
  219.   },
  220.  
  221.   initClass: function (c, parent, name, initfn) {
  222.     parent[name] = c;
  223.     c.$class = c;
  224.     c.$classname = name;
  225.     if ((parent.$module) && (parent.$module.$impl === parent)) parent = parent.$module;
  226.     c.$parent = parent;
  227.     c.$fullname = parent.$name + "." + name;
  228.     if (rtl.isModule(parent)) {
  229.       c.$module = parent;
  230.       c.$name = name;
  231.     } else {
  232.       c.$module = parent.$module;
  233.       c.$name = parent.name + "." + name;
  234.     }
  235.     if (rtl.debug_rtti) rtl.debug("initClass " + c.$fullname);
  236.     var t = c.$module.$rtti.$Class(c.$name, {
  237.       "class": c,
  238.       module: parent
  239.     });
  240.     c.$rtti = t;
  241.     if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
  242.     if (!t.ancestor) t.ancestor = null;
  243.     initfn.call(c);
  244.   },
  245.  
  246.   createClass: function (parent, name, ancestor, initfn) {
  247.     var c = null;
  248.     if (ancestor != null) {
  249.       c = Object.create(ancestor);
  250.       c.$ancestor = ancestor;
  251.     } else {
  252.       c = {};
  253.       c.$create = function (fnname, args) {
  254.         if (args == undefined) args = [];
  255.         try {
  256.           var o = Object.create(this);
  257.           o.$init();
  258.           o[fnname].apply(o, args);
  259.           o.AfterConstruction();
  260.         } catch ($e) {
  261.           if (o.Destroy) o.Destroy();
  262.           o.$final();
  263.           throw $e;
  264.         }
  265.         return o;
  266.       };
  267.       c.$destroy = function (fnname) {
  268.         this.BeforeDestruction();
  269.         if (this[fnname]) this[fnname]();
  270.         this.$final();
  271.       };
  272.     }
  273.     rtl.initClass(c, parent, name, initfn);
  274.   },
  275.  
  276.   createClassExt: function (parent, name, ancestor, newinstancefnname, initfn) {
  277.     var c = null;
  278.     c = Object.create(ancestor);
  279.     c.$create = function (fnname, args) {
  280.       if (args == undefined) args = [];
  281.       var o = null;
  282.       if (newinstancefnname.length > 0) {
  283.         o = this[newinstancefnname](fnname, args);
  284.       } else {
  285.         o = Object.create(this);
  286.       }
  287.       if (o.$init) o.$init();
  288.       try {
  289.         o[fnname].apply(o, args);
  290.         if (o.AfterConstruction) o.AfterConstruction();
  291.       } catch ($e) {
  292.         if (o.Destroy) o.Destroy();
  293.         if (o.$final) this.$final();
  294.         throw $e;
  295.       }
  296.       return o;
  297.     };
  298.     c.$destroy = function (fnname) {
  299.       if (this.BeforeDestruction) this.BeforeDestruction();
  300.       if (this[fnname]) this[fnname]();
  301.       if (this.$final) this.$final();
  302.     };
  303.     rtl.initClass(c, parent, name, initfn);
  304.   },
  305.  
  306.   tObjectDestroy: "Destroy",
  307.  
  308.   free: function (obj, name) {
  309.     if (obj[name] == null) return;
  310.     obj[name].$destroy(rtl.tObjectDestroy);
  311.     obj[name] = null;
  312.   },
  313.  
  314.   freeLoc: function (obj) {
  315.     if (obj == null) return;
  316.     obj.$destroy(rtl.tObjectDestroy);
  317.     return null;
  318.   },
  319.  
  320.   is: function (instance, type) {
  321.     return type.isPrototypeOf(instance) || (instance === type);
  322.   },
  323.  
  324.   isExt: function (instance, type, mode) {
  325.     if (instance == null) return false;
  326.     if ((typeof (type) !== "object") && (typeof (type) !== "function")) return false;
  327.     if (instance === type) {
  328.       if (mode === 1) return false;
  329.       if (mode === 2) return rtl.isPasClass(instance);
  330.       return true;
  331.     }
  332.     if (type.isPrototypeOf && type.isPrototypeOf(instance)) {
  333.       if (mode === 1) return rtl.isPasClassInstance(instance);
  334.       if (mode === 2) return rtl.isPasClass(instance);
  335.       return true;
  336.     }
  337.     if ((typeof type == "function") && (instance instanceof type)) return true;
  338.     return false;
  339.   },
  340.  
  341.   Exception: null,
  342.   EInvalidCast: null,
  343.   EAbstractError: null,
  344.   ERangeError: null,
  345.  
  346.   raiseE: function (typename) {
  347.     var t = rtl[typename];
  348.     if (t == null) {
  349.       var mod = pas.SysUtils;
  350.       if (!mod) mod = pas.sysutils;
  351.       if (mod) {
  352.         t = mod[typename];
  353.         if (!t) t = mod[typename.toLowerCase()];
  354.         if (!t) t = mod["Exception"];
  355.         if (!t) t = mod["exception"];
  356.       }
  357.     }
  358.     if (t) {
  359.       if (t.Create) {
  360.         throw t.$create("Create");
  361.       } else if (t.create) {
  362.         throw t.$create("create");
  363.       }
  364.     }
  365.     if (typename === "EInvalidCast") throw "invalid type cast";
  366.     if (typename === "EAbstractError") throw "Abstract method called";
  367.     if (typename === "ERangeError") throw "range error";
  368.     throw typename;
  369.   },
  370.  
  371.   as: function (instance, type) {
  372.     if ((instance === null) || rtl.is(instance, type)) return instance;
  373.     rtl.raiseE("EInvalidCast");
  374.   },
  375.  
  376.   asExt: function (instance, type, mode) {
  377.     if ((instance === null) || rtl.isExt(instance, type, mode)) return instance;
  378.     rtl.raiseE("EInvalidCast");
  379.   },
  380.  
  381.   createInterface: function (module, name, guid, fnnames, ancestor, initfn) {
  382.     var i = ancestor ? Object.create(ancestor) : {};
  383.     module[name] = i;
  384.     i.$module = module;
  385.     i.$name = name;
  386.     i.$fullname = module.$name + "." + name;
  387.     i.$guid = guid;
  388.     i.$guidr = null;
  389.     i.$names = fnnames ? fnnames : [];
  390.     if (rtl.isFunction(initfn)) {
  391.       if (rtl.debug_rtti) rtl.debug("createInterface " + i.$fullname);
  392.       var t = i.$module.$rtti.$Interface(name, {
  393.         "interface": i,
  394.         module: module
  395.       });
  396.       i.$rtti = t;
  397.       if (ancestor) t.ancestor = ancestor.$rtti;
  398.       if (!t.ancestor) t.ancestor = null;
  399.       initfn.call(i);
  400.     }
  401.     return i;
  402.   },
  403.  
  404.   strToGUIDR: function (s, g) {
  405.     var p = 0;
  406.  
  407.     function n(l) {
  408.       var h = s.substr(p, l);
  409.       p += l;
  410.       return parseInt(h, 16);
  411.     }
  412.     p += 1;
  413.     g.D1 = n(8);
  414.     p += 1;
  415.     g.D2 = n(4);
  416.     p += 1;
  417.     g.D3 = n(4);
  418.     p += 1;
  419.     if (!g.D4) g.D4 = [];
  420.     g.D4[0] = n(2);
  421.     g.D4[1] = n(2);
  422.     p += 1;
  423.     for (var i = 2; i < 8; i++) g.D4[i] = n(2);
  424.     return g;
  425.   },
  426.  
  427.   guidrToStr: function (g) {
  428.     if (g.$intf) return g.$intf.$guid;
  429.     var h = rtl.hexStr;
  430.     var s = "{" + h(g.D1, 8) + "-" + h(g.D2, 4) + "-" + h(g.D3, 4) + "-" + h(g.D4[0], 2) + h(g.D4[1], 2) + "-";
  431.     for (var i = 2; i < 8; i++) s += h(g.D4[i], 2);
  432.     s += "}";
  433.     return s;
  434.   },
  435.  
  436.   createTGUID: function (guid) {
  437.     var TGuid = (pas.System) ? pas.System.TGuid : pas.system.tguid;
  438.     var g = rtl.strToGUIDR(guid, new TGuid());
  439.     return g;
  440.   },
  441.  
  442.   getIntfGUIDR: function (intfTypeOrVar) {
  443.     if (!intfTypeOrVar) return null;
  444.     if (!intfTypeOrVar.$guidr) {
  445.       var g = rtl.createTGUID(intfTypeOrVar.$guid);
  446.       if (!intfTypeOrVar.hasOwnProperty("$guid")) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
  447.       g.$intf = intfTypeOrVar;
  448.       intfTypeOrVar.$guidr = g;
  449.     }
  450.     return intfTypeOrVar.$guidr;
  451.   },
  452.  
  453.   addIntf: function (aclass, intf, map) {
  454.     function jmp(fn) {
  455.       if (typeof (fn) === "function") {
  456.         return function () {
  457.           return fn.apply(this.$o, arguments);
  458.         };
  459.       } else {
  460.         return function () {
  461.           rtl.raiseE("EAbstractError");
  462.         };
  463.       }
  464.     }
  465.     if (!map) map = {};
  466.     var t = intf;
  467.     var item = Object.create(t);
  468.     if (!aclass.hasOwnProperty("$intfmaps")) aclass.$intfmaps = {};
  469.     aclass.$intfmaps[intf.$guid] = item;
  470.     do {
  471.       var names = t.$names;
  472.       if (!names) break;
  473.       for (var i = 0; i < names.length; i++) {
  474.         var intfname = names[i];
  475.         var fnname = map[intfname];
  476.         if (!fnname) fnname = intfname;
  477.         item[intfname] = jmp(aclass[fnname]);
  478.       }
  479.       t = Object.getPrototypeOf(t);
  480.     } while (t != null);
  481.   },
  482.  
  483.   getIntfG: function (obj, guid, query) {
  484.     if (!obj) return null;
  485.     var maps = obj.$intfmaps;
  486.     if (!maps) return null;
  487.     var item = maps[guid];
  488.     if (!item) return null;
  489.     if (typeof item === "function") return item.call(obj);
  490.     var intf = null;
  491.     if (obj.$interfaces) {
  492.       intf = obj.$interfaces[guid];
  493.     }
  494.     if (!intf) {
  495.       intf = Object.create(item);
  496.       intf.$o = obj;
  497.       if (!obj.$interfaces) obj.$interfaces = {};
  498.       obj.$interfaces[guid] = intf;
  499.     }
  500.     if (typeof (query) === "object") {
  501.       var o = null;
  502.       if (intf.QueryInterface(rtl.getIntfGUIDR(query), {
  503.           get: function () {
  504.             return o;
  505.           },
  506.           set: function (v) {
  507.             o = v;
  508.           }
  509.         }) === 0) {
  510.         return o;
  511.       } else {
  512.         return null;
  513.       }
  514.     } else if (query === 2) {
  515.       if (intf.$kind === "com") intf._AddRef();
  516.     }
  517.     return intf;
  518.   },
  519.  
  520.   getIntfT: function (obj, intftype) {
  521.     return rtl.getIntfG(obj, intftype.$guid);
  522.   },
  523.  
  524.   queryIntfT: function (obj, intftype) {
  525.     return rtl.getIntfG(obj, intftype.$guid, intftype);
  526.   },
  527.  
  528.   queryIntfIsT: function (obj, intftype) {
  529.     var i = rtl.queryIntfG(obj, intftype.$guid);
  530.     if (!i) return false;
  531.     if (i.$kind === "com") i._Release();
  532.     return true;
  533.   },
  534.  
  535.   asIntfT: function (obj, intftype) {
  536.     var i = rtl.getIntfG(obj, intftype.$guid);
  537.     if (i !== null) return i;
  538.     rtl.raiseEInvalidCast();
  539.   },
  540.  
  541.   intfIsClass: function (intf, classtype) {
  542.     return (intf != null) && (rtl.is(intf.$o, classtype));
  543.   },
  544.  
  545.   intfAsClass: function (intf, classtype) {
  546.     if (intf == null) return null;
  547.     return rtl.as(intf.$o, classtype);
  548.   },
  549.  
  550.   intfToClass: function (intf, classtype) {
  551.     if ((intf !== null) && rtl.is(intf.$o, classtype)) return intf.$o;
  552.     return null;
  553.   },
  554.  
  555.   intfRefs: {
  556.     ref: function (id, intf) {
  557.       var old = this[id];
  558.       if (old) {
  559.         delete this[id];
  560.         old._Release();
  561.       }
  562.       this[id] = intf;
  563.       return intf;
  564.     },
  565.     free: function () {
  566.       for (var id in this) {
  567.         if (this.hasOwnProperty(id)) {
  568.           this[id]._Release();
  569.         }
  570.       }
  571.     }
  572.   },
  573.  
  574.   createIntfRefs: function () {
  575.     return Object.create(rtl.intfRefs);
  576.   },
  577.  
  578.   setIntfP: function (path, name, value, skipAddRef) {
  579.     var old = path[name];
  580.     if (old === value) return;
  581.     if (old !== null) {
  582.       path[name] = null;
  583.       old._Release();
  584.     }
  585.     if (value !== null) {
  586.       if (!skipAddRef) value._AddRef();
  587.       path[name] = value;
  588.     }
  589.   },
  590.  
  591.   setIntfL: function (old, value, skipAddRef) {
  592.     if (old !== value) {
  593.       if (value !== null) {
  594.         if (!skipAddRef) value._AddRef();
  595.       }
  596.       if (old !== null) {
  597.         old._Release();
  598.       }
  599.     } else if (skipAddRef) {
  600.       if (old !== null) {
  601.         old._Release();
  602.       }
  603.     }
  604.     return value;
  605.   },
  606.  
  607.   _AddRef: function (intf) {
  608.     if (intf) intf._AddRef();
  609.     return intf;
  610.   },
  611.  
  612.   _Release: function (intf) {
  613.     if (intf) intf._Release();
  614.     return intf;
  615.   },
  616.  
  617.   checkMethodCall: function (obj, type) {
  618.     if (rtl.isObject(obj) && rtl.is(obj, type)) return;
  619.     rtl.raiseE("EInvalidCast");
  620.   },
  621.  
  622.   rc: function (i, minval, maxval) {
  623.     if ((Math.floor(i) === i) && (i >= minval) && (i <= maxval)) return i;
  624.     rtl.raiseE("ERangeError");
  625.   },
  626.  
  627.   rcc: function (c, minval, maxval) {
  628.     if ((typeof (c) === "string") && (c.length === 1)) {
  629.       var i = c.charCodeAt(0);
  630.       if ((i >= minval) && (i <= maxval)) return c;
  631.     }
  632.     rtl.raiseE("ERangeError");
  633.   },
  634.  
  635.   rcSetCharAt: function (s, index, c) {
  636.     if ((typeof (s) !== "string") || (index < 0) || (index >= s.length)) rtl.raiseE("ERangeError");
  637.     return rtl.setCharAt(s, index, c);
  638.   },
  639.  
  640.   rcCharAt: function (s, index) {
  641.     if ((typeof (s) !== "string") || (index < 0) || (index >= s.length)) rtl.raiseE("ERangeError");
  642.     return s.charAt(index);
  643.   },
  644.  
  645.   rcArrR: function (arr, index) {
  646.     if (Array.isArray(arr) && (typeof (index) === "number") && (index >= 0) && (index < arr.length)) {
  647.       if (arguments.length > 2) {
  648.         arr = arr[index];
  649.         for (var i = 2; i < arguments.length; i++) arr = rtl.rcArrR(arr, arguments[i]);
  650.         return arr;
  651.       }
  652.       return arr[index];
  653.     }
  654.     rtl.raiseE("ERangeError");
  655.   },
  656.  
  657.   rcArrW: function (arr, index, value) {
  658.     for (var i = 3; i < arguments.length; i++) {
  659.       arr = rtl.rcArrR(arr, index);
  660.       index = arguments[i - 1];
  661.       value = arguments[i];
  662.     }
  663.     if (Array.isArray(arr) && (typeof (index) === "number") && (index >= 0) && (index < arr.length)) {
  664.       return arr[index] = value;
  665.     }
  666.     rtl.raiseE("ERangeError");
  667.   },
  668.  
  669.   length: function (arr) {
  670.     return (arr == null) ? 0 : arr.length;
  671.   },
  672.  
  673.   arraySetLength: function (arr, defaultvalue, newlength) {
  674.     if (arr == null) arr = [];
  675.     var p = arguments;
  676.  
  677.     function setLength(a, argNo) {
  678.       var oldlen = a.length;
  679.       var newlen = p[argNo];
  680.       if (oldlen !== newlength) {
  681.         a.length = newlength;
  682.         if (argNo === p.length - 1) {
  683.           if (rtl.isArray(defaultvalue)) {
  684.             for (var i = oldlen; i < newlen; i++) a[i] = [];
  685.           } else if (rtl.isFunction(defaultvalue)) {
  686.             for (var i = oldlen; i < newlen; i++) a[i] = new defaultvalue();
  687.           } else if (rtl.isObject(defaultvalue)) {
  688.             for (var i = oldlen; i < newlen; i++) a[i] = {};
  689.           } else {
  690.             for (var i = oldlen; i < newlen; i++) a[i] = defaultvalue;
  691.           }
  692.         } else {
  693.           for (var i = oldlen; i < newlen; i++) a[i] = [];
  694.         }
  695.       }
  696.       if (argNo < p.length - 1) {
  697.         for (var i = 0; i < newlen; i++) a[i] = setLength(a[i], argNo + 1);
  698.       }
  699.       return a;
  700.     }
  701.     return setLength(arr, 2);
  702.   },
  703.  
  704.   arrayEq: function (a, b) {
  705.     if (a === null) return b === null;
  706.     if (b === null) return false;
  707.     if (a.length !== b.length) return false;
  708.     for (var i = 0; i < a.length; i++)
  709.       if (a[i] !== b[i]) return false;
  710.     return true;
  711.   },
  712.  
  713.   arrayClone: function (type, src, srcpos, endpos, dst, dstpos) {
  714.     if (rtl.isFunction(type)) {
  715.       for (; srcpos < endpos; srcpos++) dst[dstpos++] = new type(src[srcpos]);
  716.     } else if (type === "refSet") {
  717.       for (; srcpos < endpos; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]);
  718.     } else {
  719.       for (; srcpos < endpos; srcpos++) dst[dstpos++] = src[srcpos];
  720.     }
  721.   },
  722.  
  723.   arrayConcat: function (type) {
  724.     var a = [];
  725.     var l = 0;
  726.     for (var i = 1; i < arguments.length; i++) {
  727.       var src = arguments[i];
  728.       if (src !== null) l += src.length;
  729.     }
  730.     a.length = l;
  731.     l = 0;
  732.     for (var i = 1; i < arguments.length; i++) {
  733.       var src = arguments[i];
  734.       if (src === null) continue;
  735.       rtl.arrayClone(type, src, 0, src.length, a, l);
  736.       l += src.length;
  737.     }
  738.     return a;
  739.   },
  740.  
  741.   arrayConcatN: function () {
  742.     var a = null;
  743.     for (var i = 1; i < arguments.length; i++) {
  744.       var src = arguments[i];
  745.       if (src === null) continue;
  746.       if (a === null) {
  747.         a = src;
  748.       } else {
  749.         a = a.concat(src);
  750.       }
  751.     }
  752.     return a;
  753.   },
  754.  
  755.   arrayCopy: function (type, srcarray, index, count) {
  756.     if (srcarray === null) return [];
  757.     if (index < 0) index = 0;
  758.     if (count === undefined) count = srcarray.length;
  759.     var end = index + count;
  760.     if (end > srcarray.length) end = srcarray.length;
  761.     if (index >= end) return [];
  762.     if (type === 0) {
  763.       return srcarray.slice(index, end);
  764.     } else {
  765.       var a = [];
  766.       a.length = end - index;
  767.       rtl.arrayClone(type, srcarray, index, end, a, 0);
  768.       return a;
  769.     }
  770.   },
  771.  
  772.   setCharAt: function (s, index, c) {
  773.     return s.substr(0, index) + c + s.substr(index + 1);
  774.   },
  775.  
  776.   getResStr: function (mod, name) {
  777.     var rs = mod.$resourcestrings[name];
  778.     return rs.current ? rs.current : rs.org;
  779.   },
  780.  
  781.   createSet: function () {
  782.     var s = {};
  783.     for (var i = 0; i < arguments.length; i++) {
  784.       if (arguments[i] != null) {
  785.         s[arguments[i]] = true;
  786.       } else {
  787.         var first = arguments[i += 1];
  788.         var last = arguments[i += 1];
  789.         for (var j = first; j <= last; j++) s[j] = true;
  790.       }
  791.     }
  792.     return s;
  793.   },
  794.  
  795.   cloneSet: function (s) {
  796.     var r = {};
  797.     for (var key in s) r[key] = true;
  798.     return r;
  799.   },
  800.  
  801.   refSet: function (s) {
  802.     Object.defineProperty(s, "$shared", {
  803.       enumerable: false,
  804.       configurable: true,
  805.       writable: true,
  806.       value: true
  807.     });
  808.     return s;
  809.   },
  810.  
  811.   includeSet: function (s, enumvalue) {
  812.     if (s.$shared) s = rtl.cloneSet(s);
  813.     s[enumvalue] = true;
  814.     return s;
  815.   },
  816.  
  817.   excludeSet: function (s, enumvalue) {
  818.     if (s.$shared) s = rtl.cloneSet(s);
  819.     delete s[enumvalue];
  820.     return s;
  821.   },
  822.  
  823.   diffSet: function (s, t) {
  824.     var r = {};
  825.     for (var key in s)
  826.       if (!t[key]) r[key] = true;
  827.     return r;
  828.   },
  829.  
  830.   unionSet: function (s, t) {
  831.     var r = {};
  832.     for (var key in s) r[key] = true;
  833.     for (var key in t) r[key] = true;
  834.     return r;
  835.   },
  836.  
  837.   intersectSet: function (s, t) {
  838.     var r = {};
  839.     for (var key in s)
  840.       if (t[key]) r[key] = true;
  841.     return r;
  842.   },
  843.  
  844.   symDiffSet: function (s, t) {
  845.     var r = {};
  846.     for (var key in s)
  847.       if (!t[key]) r[key] = true;
  848.     for (var key in t)
  849.       if (!s[key]) r[key] = true;
  850.     return r;
  851.   },
  852.  
  853.   eqSet: function (s, t) {
  854.     for (var key in s)
  855.       if (!t[key]) return false;
  856.     for (var key in t)
  857.       if (!s[key]) return false;
  858.     return true;
  859.   },
  860.  
  861.   neSet: function (s, t) {
  862.     return !rtl.eqSet(s, t);
  863.   },
  864.  
  865.   leSet: function (s, t) {
  866.     for (var key in s)
  867.       if (!t[key]) return false;
  868.     return true;
  869.   },
  870.  
  871.   geSet: function (s, t) {
  872.     for (var key in t)
  873.       if (!s[key]) return false;
  874.     return true;
  875.   },
  876.  
  877.   strSetLength: function (s, newlen) {
  878.     var oldlen = s.length;
  879.     if (oldlen > newlen) {
  880.       return s.substring(0, newlen);
  881.     } else if (s.repeat) {
  882.       return s + " ".repeat(newlen - oldlen);
  883.     } else {
  884.       while (oldlen < newlen) {
  885.         s += " ";
  886.         oldlen++;
  887.       }
  888.       return s;
  889.     }
  890.   },
  891.  
  892.   spaceLeft: function (s, width) {
  893.     var l = s.length;
  894.     if (l >= width) return s;
  895.     if (s.repeat) {
  896.       return " ".repeat(width - l) + s;
  897.     } else {
  898.       while (l < width) {
  899.         s = " " + s;
  900.         l++;
  901.       }
  902.     }
  903.   },
  904.  
  905.   floatToStr: function (d, w, p) {
  906.     if (arguments.length > 2) {
  907.       return rtl.spaceLeft(d.toFixed(p), w);
  908.     } else {
  909.       var pad = "";
  910.       var ad = Math.abs(d);
  911.       if (ad < 1.0e+10) {
  912.         pad = "00";
  913.       } else if (ad < 1.0e+100) {
  914.         pad = "0";
  915.       }
  916.       if (arguments.length < 2) {
  917.         w = 9;
  918.       } else if (w < 9) {
  919.         w = 9;
  920.       }
  921.       var p = w - 8;
  922.       var s = (d > 0 ? " " : "") + d.toExponential(p);
  923.       s = s.replace(/e(.)/, "E$1" + pad);
  924.       return rtl.spaceLeft(s, w);
  925.     }
  926.   },
  927.  
  928.   valEnum: function (s, enumType, setCodeFn) {
  929.     s = s.toLowerCase();
  930.     for (var key in enumType) {
  931.       if ((typeof (key) === "string") && (key.toLowerCase() === s)) {
  932.         setCodeFn(0);
  933.         return enumType[key];
  934.       }
  935.     }
  936.     setCodeFn(1);
  937.     return 0;
  938.   },
  939.  
  940.   initRTTI: function () {
  941.     if (rtl.debug_rtti) rtl.debug("initRTTI");
  942.  
  943.     rtl.tTypeInfo = {
  944.       name: "tTypeInfo"
  945.     };
  946.  
  947.     function newBaseTI(name, kind, ancestor) {
  948.       if (!ancestor) ancestor = rtl.tTypeInfo;
  949.       if (rtl.debug_rtti) rtl.debug("initRTTI.newBaseTI \"" + name + "\" " + kind + " (\"" + ancestor.name + "\")");
  950.       var t = Object.create(ancestor);
  951.       t.name = name;
  952.       t.kind = kind;
  953.       rtl[name] = t;
  954.       return t;
  955.     }
  956.  
  957.     function newBaseInt(name, minvalue, maxvalue, ordtype) {
  958.       var t = newBaseTI(name, 1, rtl.tTypeInfoInteger);
  959.       t.minvalue = minvalue;
  960.       t.maxvalue = maxvalue;
  961.       t.ordtype = ordtype;
  962.       return t;
  963.     }
  964.     newBaseTI("tTypeInfoInteger", 1);
  965.     newBaseInt("shortint", -0x80, 0x7f, 0);
  966.     newBaseInt("byte", 0, 0xff, 1);
  967.     newBaseInt("smallint", -0x8000, 0x7fff, 2);
  968.     newBaseInt("word", 0, 0xffff, 3);
  969.     newBaseInt("longint", -0x80000000, 0x7fffffff, 4);
  970.     newBaseInt("longword", 0, 0xffffffff, 5);
  971.     newBaseInt("nativeint", -0x10000000000000, 0xfffffffffffff, 6);
  972.     newBaseInt("nativeuint", 0, 0xfffffffffffff, 7);
  973.     newBaseTI("char", 2);
  974.     newBaseTI("string", 3);
  975.     newBaseTI("tTypeInfoEnum", 4, rtl.tTypeInfoInteger);
  976.     newBaseTI("tTypeInfoSet", 5);
  977.     newBaseTI("double", 6);
  978.     newBaseTI("boolean", 7);
  979.     newBaseTI("tTypeInfoProcVar", 8);
  980.     newBaseTI("tTypeInfoMethodVar", 9, rtl.tTypeInfoProcVar);
  981.     newBaseTI("tTypeInfoArray", 10);
  982.     newBaseTI("tTypeInfoDynArray", 11);
  983.     newBaseTI("tTypeInfoPointer", 15);
  984.     var t = newBaseTI("pointer", 15, rtl.tTypeInfoPointer);
  985.     t.reftype = null;
  986.     newBaseTI("jsvalue", 16);
  987.     newBaseTI("tTypeInfoRefToProcVar", 17, rtl.tTypeInfoProcVar);
  988.  
  989.     rtl.tTypeMember = {};
  990.  
  991.     function newMember(name, kind) {
  992.       var m = Object.create(rtl.tTypeMember);
  993.       m.name = name;
  994.       m.kind = kind;
  995.       rtl[name] = m;
  996.     }
  997.     newMember("tTypeMemberField", 1);
  998.     newMember("tTypeMemberMethod", 2);
  999.     newMember("tTypeMemberProperty", 3);
  1000.  
  1001.     rtl.tTypeMembers = {};
  1002.  
  1003.     var tis = newBaseTI("tTypeInfoStruct", 0);
  1004.     tis.$addMember = function (name, ancestor, options) {
  1005.       if (rtl.debug_rtti) {
  1006.         if (!rtl.hasString(name) || (name.charAt() === "$")) throw "invalid member \"" + name + "\", this=\"" + this.name + "\"";
  1007.         if (!rtl.is(ancestor, rtl.tTypeMember)) throw "invalid ancestor \"" + ancestor + ":" + ancestor.name + "\", \"" + this.name + "." + name + "\"";
  1008.         if ((options != undefined) && (typeof (options) != "object")) throw "invalid options \"" + options + "\", \"" + this.name + "." + name + "\"";
  1009.       }
  1010.       var t = Object.create(ancestor);
  1011.       t.name = name;
  1012.       this.members[name] = t;
  1013.       this.names.push(name);
  1014.       if (rtl.isObject(options)) {
  1015.         for (var key in options)
  1016.           if (options.hasOwnProperty(key)) t[key] = options[key];
  1017.       }
  1018.       return t;
  1019.     };
  1020.     tis.addField = function (name, type, options) {
  1021.       var t = this.$addMember(name, rtl.tTypeMemberField, options);
  1022.       if (rtl.debug_rtti) {
  1023.         if (!rtl.is(type, rtl.tTypeInfo)) throw "invalid type \"" + type + "\", \"" + this.name + "." + name + "\"";
  1024.       }
  1025.       t.typeinfo = type;
  1026.       this.fields.push(name);
  1027.       return t;
  1028.     };
  1029.     tis.addFields = function () {
  1030.       var i = 0;
  1031.       while (i < arguments.length) {
  1032.         var name = arguments[i++];
  1033.         var type = arguments[i++];
  1034.         if ((i < arguments.length) && (typeof (arguments[i]) === "object")) {
  1035.           this.addField(name, type, arguments[i++]);
  1036.         } else {
  1037.           this.addField(name, type);
  1038.         }
  1039.       }
  1040.     };
  1041.     tis.addMethod = function (name, methodkind, params, result, options) {
  1042.       var t = this.$addMember(name, rtl.tTypeMemberMethod, options);
  1043.       t.methodkind = methodkind;
  1044.       t.procsig = rtl.newTIProcSig(params);
  1045.       t.procsig.resulttype = result ? result : null;
  1046.       this.methods.push(name);
  1047.       return t;
  1048.     };
  1049.     tis.addProperty = function (name, flags, result, getter, setter, options) {
  1050.       var t = this.$addMember(name, rtl.tTypeMemberProperty, options);
  1051.       t.flags = flags;
  1052.       t.typeinfo = result;
  1053.       t.getter = getter;
  1054.       t.setter = setter;
  1055.       if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
  1056.       this.properties.push(name);
  1057.       if (!rtl.isString(t.stored)) t.stored = "";
  1058.       return t;
  1059.     };
  1060.     tis.getField = function (index) {
  1061.       return this.members[this.fields[index]];
  1062.     };
  1063.     tis.getMethod = function (index) {
  1064.       return this.members[this.methods[index]];
  1065.     };
  1066.     tis.getProperty = function (index) {
  1067.       return this.members[this.properties[index]];
  1068.     };
  1069.  
  1070.     newBaseTI("tTypeInfoRecord", 12, rtl.tTypeInfoStruct);
  1071.     newBaseTI("tTypeInfoClass", 13, rtl.tTypeInfoStruct);
  1072.     newBaseTI("tTypeInfoClassRef", 14);
  1073.     newBaseTI("tTypeInfoInterface", 15, rtl.tTypeInfoStruct);
  1074.   },
  1075.  
  1076.   tSectionRTTI: {
  1077.     $module: null,
  1078.     $inherited: function (name, ancestor, o) {
  1079.       if (rtl.debug_rtti) {
  1080.         rtl.debug("tSectionRTTI.newTI \"" + (this.$module ? this.$module.$name : "(no module)") +
  1081.           "\".\"" + name + "\" (" + ancestor.name + ") " + (o ? "init" : "forward"));
  1082.       }
  1083.       var t = this[name];
  1084.       if (t) {
  1085.         if (!t.$forward) throw "duplicate type \"" + name + "\"";
  1086.         if (!ancestor.isPrototypeOf(t)) throw "typeinfo ancestor mismatch \"" + name + "\" ancestor=\"" + ancestor.name + "\" t.name=\"" + t.name + "\"";
  1087.       } else {
  1088.         t = Object.create(ancestor);
  1089.         t.name = name;
  1090.         t.$module = this.$module;
  1091.         this[name] = t;
  1092.       }
  1093.       if (o) {
  1094.         delete t.$forward;
  1095.         for (var key in o)
  1096.           if (o.hasOwnProperty(key)) t[key] = o[key];
  1097.       } else {
  1098.         t.$forward = true;
  1099.       }
  1100.       return t;
  1101.     },
  1102.     $Scope: function (name, ancestor, o) {
  1103.       var t = this.$inherited(name, ancestor, o);
  1104.       t.members = {};
  1105.       t.names = [];
  1106.       t.fields = [];
  1107.       t.methods = [];
  1108.       t.properties = [];
  1109.       return t;
  1110.     },
  1111.     $TI: function (name, kind, o) {
  1112.       var t = this.$inherited(name, rtl.tTypeInfo, o);
  1113.       t.kind = kind;
  1114.       return t;
  1115.     },
  1116.     $Int: function (name, o) {
  1117.       return this.$inherited(name, rtl.tTypeInfoInteger, o);
  1118.     },
  1119.     $Enum: function (name, o) {
  1120.       return this.$inherited(name, rtl.tTypeInfoEnum, o);
  1121.     },
  1122.     $Set: function (name, o) {
  1123.       return this.$inherited(name, rtl.tTypeInfoSet, o);
  1124.     },
  1125.     $StaticArray: function (name, o) {
  1126.       return this.$inherited(name, rtl.tTypeInfoArray, o);
  1127.     },
  1128.     $DynArray: function (name, o) {
  1129.       return this.$inherited(name, rtl.tTypeInfoDynArray, o);
  1130.     },
  1131.     $ProcVar: function (name, o) {
  1132.       return this.$inherited(name, rtl.tTypeInfoProcVar, o);
  1133.     },
  1134.     $RefToProcVar: function (name, o) {
  1135.       return this.$inherited(name, rtl.tTypeInfoRefToProcVar, o);
  1136.     },
  1137.     $MethodVar: function (name, o) {
  1138.       return this.$inherited(name, rtl.tTypeInfoMethodVar, o);
  1139.     },
  1140.     $Record: function (name, o) {
  1141.       return this.$Scope(name, rtl.tTypeInfoRecord, o);
  1142.     },
  1143.     $Class: function (name, o) {
  1144.       return this.$Scope(name, rtl.tTypeInfoClass, o);
  1145.     },
  1146.     $ClassRef: function (name, o) {
  1147.       return this.$inherited(name, rtl.tTypeInfoClassRef, o);
  1148.     },
  1149.     $Pointer: function (name, o) {
  1150.       return this.$inherited(name, rtl.tTypeInfoPointer, o);
  1151.     },
  1152.     $Interface: function (name, o) {
  1153.       return this.$Scope(name, rtl.tTypeInfoInterface, o);
  1154.     }
  1155.   },
  1156.  
  1157.   newTIParam: function (param) {
  1158.     var t = {
  1159.       name: param[0],
  1160.       typeinfo: param[1],
  1161.       flags: (rtl.isNumber(param[2]) ? param[2] : 0)
  1162.     };
  1163.     return t;
  1164.   },
  1165.  
  1166.   newTIParams: function (list) {
  1167.     var params = [];
  1168.     if (rtl.isArray(list)) {
  1169.       for (var i = 0; i < list.length; i++) params.push(rtl.newTIParam(list[i]));
  1170.     }
  1171.     return params;
  1172.   },
  1173.  
  1174.   newTIProcSig: function (params, result, flags) {
  1175.     var s = {
  1176.       params: rtl.newTIParams(params),
  1177.       resulttype: result,
  1178.       flags: flags
  1179.     };
  1180.     return s;
  1181.   }
  1182. };
  1183. rtl.module("System", [], function () {
  1184.   "use strict";
  1185.   var $mod = this;
  1186.   this.LineEnding = "\n";
  1187.   this.sLineBreak = "\n";
  1188.   this.MaxLongint = 0x7fffffff;
  1189.   this.Maxint = 2147483647;
  1190.   rtl.createClass($mod, "TObject", null, function () {
  1191.     this.$init = function () {};
  1192.     this.$final = function () {};
  1193.     this.Create = function () {};
  1194.     this.AfterConstruction = function () {};
  1195.     this.BeforeDestruction = function () {};
  1196.   });
  1197.   this.IsConsole = true;
  1198.   this.OnParamCount = null;
  1199.   this.OnParamStr = null;
  1200.   this.ParamStr = function (Index) {
  1201.     var Result = "";
  1202.     if ($mod.OnParamStr != null) {
  1203.       Result = $mod.OnParamStr(Index);
  1204.     } else if (Index === 0) {
  1205.       Result = "js";
  1206.     } else Result = "";
  1207.     return Result;
  1208.   };
  1209.   this.upcase = function (c) {
  1210.     return c.toUpperCase();
  1211.   };
  1212.   this.StringOfChar = function (c, l) {
  1213.     var Result = "";
  1214.     var i = 0;
  1215.     if ((l > 0) && c.repeat) return c.repeat(l);
  1216.     Result = "";
  1217.     for (var $l1 = 1, $end2 = l; $l1 <= $end2; $l1++) {
  1218.       i = $l1;
  1219.       Result = Result + c;
  1220.     }
  1221.     return Result;
  1222.   };
  1223.   $mod.$init = function () {
  1224.     rtl.exitcode = 0;
  1225.   };
  1226. });
  1227. rtl.module("Types", ["System"], function () {
  1228.   "use strict";
  1229.   var $mod = this;
  1230. });
  1231. rtl.module("JS", ["System", "Types"], function () {
  1232.   "use strict";
  1233.   var $mod = this;
  1234. });
  1235. rtl.module("NodeJS", ["System", "JS", "Types"], function () {
  1236.   "use strict";
  1237.   var $mod = this;
  1238.   this.NJS_OS = null;
  1239.   $mod.$init = function () {
  1240.     $mod.NJS_OS = rtl.getObject(require("os"));
  1241.     pas.System.LineEnding = $mod.NJS_OS.EOL;
  1242.     pas.System.sLineBreak = $mod.NJS_OS.EOL;
  1243.   };
  1244. });
  1245. rtl.module("SysUtils", ["System", "JS"], function () {
  1246.   "use strict";
  1247.   var $mod = this;
  1248.   this.TrimLeft = function (S) {
  1249.     return S.replace(/^[\s\uFEFF\xA0\x00-\x1f]+/, "");
  1250.   };
  1251.   this.OnGetEnvironmentVariable = null;
  1252.   this.OnGetEnvironmentString = null;
  1253.   this.OnGetEnvironmentVariableCount = null;
  1254.   rtl.createClass($mod, "TFormatSettings", pas.System.TObject, function () {});
  1255.   this.FormatSettings = null;
  1256.   $mod.$init = function () {
  1257.     $mod.FormatSettings = $mod.TFormatSettings.$create("Create");
  1258.   };
  1259. });
  1260. rtl.module("Classes", ["System", "Types", "SysUtils"], function () {
  1261.   "use strict";
  1262.   var $mod = this;
  1263.   var $impl = $mod.$impl;
  1264.   $mod.$init = function () {
  1265.     $impl.ClassList = Object.create(null);
  1266.   };
  1267. }, ["JS"], function () {
  1268.   "use strict";
  1269.   var $mod = this;
  1270.   var $impl = $mod.$impl;
  1271.   $impl.ClassList = null;
  1272. });
  1273. rtl.module("NodeJSApp", ["System", "NodeJS", "Classes", "SysUtils", "Types", "JS"], function () {
  1274.   "use strict";
  1275.   var $mod = this;
  1276.   var $impl = $mod.$impl;
  1277.   this.ReloadEnvironmentStrings = function () {
  1278.     $impl.EnvNames = Object.getOwnPropertyNames(process.env);
  1279.   };
  1280.   $mod.$init = function () {
  1281.     pas.System.IsConsole = true;
  1282.     pas.System.OnParamCount = $impl.GetParamCount;
  1283.     pas.System.OnParamStr = $impl.GetParamStr;
  1284.     $mod.ReloadEnvironmentStrings();
  1285.     pas.SysUtils.OnGetEnvironmentVariable = $impl.MyGetEnvironmentVariable;
  1286.     pas.SysUtils.OnGetEnvironmentVariableCount = $impl.MyGetEnvironmentVariableCount;
  1287.     pas.SysUtils.OnGetEnvironmentString = $impl.MyGetEnvironmentString;
  1288.   };
  1289. }, null, function () {
  1290.   "use strict";
  1291.   var $mod = this;
  1292.   var $impl = $mod.$impl;
  1293.   $impl.EnvNames = [];
  1294.   $impl.GetParamCount = function () {
  1295.     var Result = 0;
  1296.     Result = rtl.length(process.argv) - 2;
  1297.     return Result;
  1298.   };
  1299.   $impl.GetParamStr = function (Index) {
  1300.     var Result = "";
  1301.     Result = process.argv[Index + 1];
  1302.     return Result;
  1303.   };
  1304.   $impl.MyGetEnvironmentVariable = function (EnvVar) {
  1305.     var Result = "";
  1306.     Result = "" + process.env[EnvVar];
  1307.     return Result;
  1308.   };
  1309.   $impl.MyGetEnvironmentVariableCount = function () {
  1310.     var Result = 0;
  1311.     Result = rtl.length($impl.EnvNames);
  1312.     return Result;
  1313.   };
  1314.   $impl.MyGetEnvironmentString = function (Index) {
  1315.     var Result = "";
  1316.     Result = $impl.EnvNames[Index];
  1317.     return Result;
  1318.   };
  1319. });
  1320. rtl.module("StrUtils", ["System", "SysUtils"], function () {
  1321.   "use strict";
  1322.   var $mod = this;
  1323.   var $impl = $mod.$impl;
  1324.   this.ReverseString = function (AText) {
  1325.     var Result = "";
  1326.     var i = 0;
  1327.     var j = 0;
  1328.     Result = rtl.strSetLength(Result, AText.length);
  1329.     i = 1;
  1330.     j = AText.length;
  1331.     while (i <= j) {
  1332.       Result = rtl.setCharAt(Result, i - 1, AText.charAt(((j - i) + 1) - 1));
  1333.       i += 1;
  1334.     }
  1335.     return Result;
  1336.   };
  1337.   this.Soundex = function (AText, ALength) {
  1338.     var Result = "";
  1339.     var S = "";
  1340.     var PS = "";
  1341.     var I = 0;
  1342.     var L = 0;
  1343.     Result = "";
  1344.     PS = "\x00";
  1345.     if (AText.length > 0) {
  1346.       Result = pas.System.upcase(AText.charAt(0));
  1347.       I = 2;
  1348.       L = AText.length;
  1349.       while ((I <= L) && (Result.length < ALength)) {
  1350.         S = $impl.SScore.charAt(AText.charCodeAt(I - 1) - 1);
  1351.         if (!(S.charCodeAt() in rtl.createSet(48, 105, PS.charCodeAt()))) Result = Result + S;
  1352.         if (S !== "i") PS = S;
  1353.         I += 1;
  1354.       }
  1355.     }
  1356.     L = Result.length;
  1357.     if (L < ALength) Result = Result + pas.System.StringOfChar("0", ALength - L);
  1358.     return Result;
  1359.   };
  1360.   this.SoundexSimilar = function (AText, AOther, ALength) {
  1361.     var Result = false;
  1362.     Result = $mod.Soundex(AText, ALength) === $mod.Soundex(AOther, ALength);
  1363.     return Result;
  1364.   };
  1365.   this.SoundexSimilar$1 = function (AText, AOther) {
  1366.     var Result = false;
  1367.     Result = $mod.SoundexSimilar(AText, AOther, 4);
  1368.     return Result;
  1369.   };
  1370.   this.SoundexProc = function (AText, AOther) {
  1371.     var Result = false;
  1372.     Result = $mod.SoundexSimilar$1(AText, AOther);
  1373.     return Result;
  1374.   };
  1375.   this.AnsiResemblesProc = null;
  1376.   $mod.$init = function () {
  1377.     $mod.AnsiResemblesProc = $mod.SoundexProc;
  1378.   };
  1379. }, ["JS"], function () {
  1380.   "use strict";
  1381.   var $mod = this;
  1382.   var $impl = $mod.$impl;
  1383.   $impl.SScore = (((((((("00000000000000000000000000000000" + "00000000000000000000000000000000") + "0123012i02245501262301i2i2") + "000000") + "0123012i02245501262301i2i2") + "00000000000000000000000000000000") + "00000000000000000000000000000000") + "00000000000000000000000000000000") + "00000000000000000000000000000000") + "00000";
  1384. });
  1385. rtl.module("program", ["System", "NodeJS", "NodeJSApp", "SysUtils", "StrUtils"], function () {
  1386.   "use strict";
  1387.   var $mod = this;
  1388.   this.Exaggerate = function (S) {
  1389.     var Result = "";
  1390.     var C = "";
  1391.     for (var $in1 = S, $l2 = 0, $end3 = $in1.length - 1; $l2 <= $end3; $l2++) {
  1392.       C = $in1.charAt($l2);
  1393.       Result = (Result + C) + " ";
  1394.     }
  1395.     return Result;
  1396.   };
  1397.   this.I = 0;
  1398.   this.Jerk = "";
  1399.   this.Exaggerated = "";
  1400.   this.Space = "";
  1401.   $mod.$main = function () {
  1402.     $mod.Jerk = pas.System.ParamStr(1);
  1403.     if ($mod.Jerk === "") return;
  1404.     $mod.Exaggerated = $mod.Exaggerate($mod.Jerk);
  1405.     console.log($mod.Exaggerated);
  1406.     $mod.Space = pas.System.StringOfChar(" ", ($mod.Jerk.length * 2) - 3);
  1407.     for (var $l1 = 2, $end2 = $mod.Jerk.length - 1; $l1 <= $end2; $l1++) {
  1408.       $mod.I = $l1;
  1409.       console.log(($mod.Jerk.charAt($mod.I - 1) + $mod.Space) + $mod.Jerk.charAt(((($mod.Jerk.length - 1) + 2) - $mod.I) - 1));
  1410.     }
  1411.     console.log(pas.SysUtils.TrimLeft(pas.StrUtils.ReverseString($mod.Exaggerated)));
  1412.   };
  1413. });
  1414. rtl.run();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top