private Object indexOfHelper(Context cx,Scriptable thisObj,Object[] args,boolean isLast){
  Object compareTo=args.length > 0 ? args[0] : Undefined.instance;
  long length=getLengthProperty(cx,thisObj);
  long start;
  if (isLast) {
    if (args.length < 2) {
      start=length - 1;
    }
 else {
      start=ScriptRuntime.toInt32(ScriptRuntime.toNumber(args[1]));
      if (start >= length)       start=length - 1;
 else       if (start < 0)       start+=length;
    }
  }
 else {
    if (args.length < 2) {
      start=0;
    }
 else {
      start=ScriptRuntime.toInt32(ScriptRuntime.toNumber(args[1]));
      if (start < 0) {
        start+=length;
        if (start < 0)         start=0;
      }
    }
  }
  if (thisObj instanceof NativeArray) {
    NativeArray na=(NativeArray)thisObj;
    if (na.denseOnly) {
      if (isLast) {
        for (int i=(int)start; i >= 0; i--) {
          if (na.dense[i] != Scriptable.NOT_FOUND && ScriptRuntime.shallowEq(na.dense[i],compareTo)) {
            return Long.valueOf(i);
          }
        }
      }
 else {
        for (int i=(int)start; i < length; i++) {
          if (na.dense[i] != Scriptable.NOT_FOUND && ScriptRuntime.shallowEq(na.dense[i],compareTo)) {
            return Long.valueOf(i);
          }
        }
      }
      return NEGATIVE_ONE;
    }
  }
  if (isLast) {
    for (long i=start; i >= 0; i--) {
      if (ScriptRuntime.shallowEq(getElem(cx,thisObj,i),compareTo)) {
        return Long.valueOf(i);
      }
    }
  }
 else {
    for (long i=start; i < length; i++) {
      if (ScriptRuntime.shallowEq(getElem(cx,thisObj,i),compareTo)) {
        return Long.valueOf(i);
      }
    }
  }
  return NEGATIVE_ONE;
}

private Object indexOfHelper ( Context cx , Scriptable thisObj , Object [ ] args , boolean isLast ) { Object compareTo = args . length > 0 ? args [ 0 ] : Undefined . instance ; long length = getLengthProperty ( cx , thisObj ) ; long start ; if ( isLast ) { if ( args . length < 2 ) { start = length - 1 ; } else { start = ScriptRuntime . toInt32 ( ScriptRuntime . toNumber ( args [ 1 ] ) ) ; if ( start >= length ) start = length - 1 ; else if ( start < 0 ) start += length ; } } else { if ( args . length < 2 ) { start = 0 ; } else { start = ScriptRuntime . toInt32 ( ScriptRuntime . toNumber ( args [ 1 ] ) ) ; if ( start < 0 ) { start += length ; if ( start < 0 ) start = 0 ; } } } if ( thisObj instanceof NativeArray ) { NativeArray na = ( NativeArray ) thisObj ; if ( na . denseOnly ) { if ( isLast ) { for ( int i = ( int ) start ; i >= 0 ; i -- ) { if ( na . dense [ i ] != Scriptable . NOT_FOUND && ScriptRuntime . shallowEq ( na . dense [ i ] , compareTo ) ) { return Long . valueOf ( i ) ; } } } else { for ( int i = ( int ) start ; i < length ; i ++ ) { if ( na . dense [ i ] != Scriptable . NOT_FOUND && ScriptRuntime . shallowEq ( na . dense [ i ] , compareTo ) ) { return Long . valueOf ( i ) ; } } } return NEGATIVE_ONE ; } } if ( isLast ) { for ( long i = start ; i >= 0 ; i -- ) { if ( ScriptRuntime . shallowEq ( getElem ( cx , thisObj , i ) , compareTo ) ) { return Long . valueOf ( i ) ; } } } else { for ( long i = start ; i < length ; i ++ ) { if ( ScriptRuntime . shallowEq ( getElem ( cx , thisObj , i ) , compareTo ) ) { return Long . valueOf ( i ) ; } } } return NEGATIVE_ONE ; }
implements the methods " indexof " and " lastindexof " .
