array push broken ?
Gary M
garym at oedata.com
Wed Dec 24 05:57:36 UTC 2014
Hi,
Sorry for the chatter, I had a typo in the code--- didn't have my glasses
couldn't see it..
have a good holiday..
On Tue, Dec 23, 2014 at 7:11 PM, Gary M <garym at oedata.com> wrote:
> hi,
>
> I'm new to nashorn and have bumped into some issues with arrays.
>
> Occasionally, arrays length property is undefined, values are returned as
> null and push doesn't always seem to work.
>
> I have this code I'm porting from C
>
> This is the output of the code:
> SchemeTest-> internal scheme identifier validator - sunny day: START
> entry:
> {"eid":"test_scheme0_test_dest0_test_acc0_test_evt0","sevt":"","priority":"0"}
> array: []
> array final: []
>
> The entry should have been pushed into the array, its not.
>
> the code is in the first for loop.
>
> All the other loops the arrays work correctly..
>
> I have changed var positions in the code, with no change.
>
> I have replaced the "_evti= new Array'" with "_evti= [];" with no
> change.
>
> any suggestions ?
>
> -g
>
> var buildpath = function (sids,dids,aids,eids,pris){
> var _sida;
> var _dida;
> var _aida;
> var _eida;
> var _pria;
> var _schi;
> var _dsti;
> var _acci;
> var _evti;
> // check if parameters are string, if they are make into array
> if ((sids)&&(typeof sids === 'string')) _sida= new Array(sids);
> if ((dids)&&(typeof dids === 'string')) _dida= new Array(dids);
> if ((aids)&&(typeof aids === 'string')) _aida= new Array(aids);
> if ((eids)&&(typeof eids === 'string')) _eida= new Array(eids);
> if ((eids)&&(typeof eids === 'string')) _eida= new Array(eids);
> if ((pris)&&(typeof pris === 'string')) _pria= new Array(pris);
>
>
> // start building the path sections from the bottom up
> if(_eida){
> _evti= new Array;
> // loop through the list
> for ( var i in _eida){
> var x = new Object;
> // set the event's identifier
> x.eid=_eida[i];
> // set the event event record type
> x.sevt="";
> // set the event priority
> x.priority=_pria[i];
> // add it to the list
> _evti.push[x];
> _evti.push["dog"];
> print ( "entry: " + JSON.stringify(x));
> print ( "array: " + JSON.stringify(_evti));
> }
> }
> print ( "array final: " + JSON.stringify(_evti));
>
>
>
> //build the accept list
> if(_aida){
> _acci= new Array;
> // loop through the list
> for ( var i in _aida){
> var x = new Object;
> // set the event's identifier
> x.aid=_aida[i];
> // set the event event record type
> x.sacc="";
> // set the event list
> x.evtli=new Array;
> if (_evti)
> x.evtli=_evti;
> // add it to the lis
> _acci.push(x);
> }
> }
>
> //build the destination
> if(_dida){
> _dsti= new Array;
> // loop through the list
> for ( var i in _dida){
> var x = new Object;
> // set the event's identifier
> x.did=_dida[i];
> // set the event event record type
> x.sdst="";
> // set the event event priority
> x.accli=new Array;
> if (_acci)
> x.accli=_acci;
> // add it to the lis
> _dsti.push(x);
> }
> }
> //build the scheme
> if(_sida){
> _schi= new Array;
> // loop through the list
> for ( var i in _sida){
> var x = new Object;
> // set the event's identifier
> x.sid=_sida[i];
> // set the event event record type
> x.ssch="";
> // set the destinations
> x.dstli=new Array;
> if (_dsti)
> x.dstli=_dsti;
> // add it to the lis
> _schi[i]= x;
> }
> }
> var rtnpath;
> // build the return path
> if (_schi) rtnpath=JSON.stringify(_schi);
> else if (_dsti)rtnpath=JSON.stringify(_dsti);
> else if (_acci)rtnpath=JSON.stringify(_acci);
> else if (_evti)rtnpath=JSON.stringify(_evti);
> return rtnpath;
> };
>
>
>
>
>
>
More information about the nashorn-dev
mailing list