org.mozilla.javascript.NativeArray.getElem()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 JavaScript  
字(10.4k)|赞(0)|评价(0)|浏览(185)

本文整理了Java中org.mozilla.javascript.NativeArray.getElem()方法的一些代码示例,展示了NativeArray.getElem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeArray.getElem()方法的具体详情如下:
包路径:org.mozilla.javascript.NativeArray
类名称:NativeArray
方法名:getElem

NativeArray.getElem介绍

暂无

代码示例

代码示例来源:origin: rhino/js

/** Version of heapsort that call getElem/setElem on target to query/assign
 * array elements instead of Java array access
 */
  private static void heapsort_extended(Context cx, Scriptable scope,
                     Scriptable target, long length,
                     Object cmp, Object[] cmpBuf)
  {
    if (length <= 1) Kit.codeBug();

    // Build heap
    for (long i = length / 2; i != 0;) {
      --i;
      Object pivot = getElem(cx, target, i);
      heapify_extended(cx, scope, pivot, target, i, length, cmp, cmpBuf);
    }

    // Sort heap
    for (long i = length; i != 1;) {
      --i;
      Object pivot = getElem(cx, target, i);
      setElem(cx, target, i, getElem(cx, target, 0));
      heapify_extended(cx, scope, pivot, target, 0, i, cmp, cmpBuf);
    }
  }

代码示例来源:origin: com.sun.phobos/phobos-rhino

/** Version of heapsort that call getElem/setElem on target to query/assign
 * array elements instead of Java array access
 */
  private static void heapsort_extended(Context cx, Scriptable scope,
                     Scriptable target, long length,
                     Object cmp, Object[] cmpBuf)
  {
    if (length <= 1) Kit.codeBug();

    // Build heap
    for (long i = length / 2; i != 0;) {
      --i;
      Object pivot = getElem(cx, target, i);
      heapify_extended(cx, scope, pivot, target, i, length, cmp, cmpBuf);
    }

    // Sort heap
    for (long i = length; i != 1;) {
      --i;
      Object pivot = getElem(cx, target, i);
      setElem(cx, target, i, getElem(cx, target, 0));
      heapify_extended(cx, scope, pivot, target, 0, i, cmp, cmpBuf);
    }
  }

代码示例来源:origin: com.sun.phobos/phobos-rhino

/**
 * See ECMA 15.4.4.4
 */
private static Scriptable js_reverse(Context cx, Scriptable thisObj,
                   Object[] args)
{
  long len = getLengthProperty(cx, thisObj);
  long half = len / 2;
  for(long i=0; i < half; i++) {
    long j = len - i - 1;
    Object temp1 = getElem(cx, thisObj, i);
    Object temp2 = getElem(cx, thisObj, j);
    setElem(cx, thisObj, i, temp2);
    setElem(cx, thisObj, j, temp1);
  }
  return thisObj;
}

代码示例来源:origin: rhino/js

/**
 * See ECMA 15.4.4.4
 */
private static Scriptable js_reverse(Context cx, Scriptable thisObj,
                   Object[] args)
{
  if (thisObj instanceof NativeArray) {
    NativeArray na = (NativeArray) thisObj;
    if (na.denseOnly) {
      for (int i=0, j=((int)na.length)-1; i < j; i++,j--) {
        Object temp = na.dense[i];
        na.dense[i] = na.dense[j];
        na.dense[j] = temp;
      }
      return thisObj;
    }
  }
  long len = getLengthProperty(cx, thisObj);
  long half = len / 2;
  for(long i=0; i < half; i++) {
    long j = len - i - 1;
    Object temp1 = getElem(cx, thisObj, i);
    Object temp2 = getElem(cx, thisObj, j);
    setElem(cx, thisObj, i, temp2);
    setElem(cx, thisObj, j, temp1);
  }
  return thisObj;
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

private static Object js_pop(Context cx, Scriptable thisObj,
               Object[] args)
{
  Object result;
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, length);
    // We don't need to delete the last property, because
    // setLength does that for us.
  } else {
    result = Undefined.instance;
  }
  // necessary to match js even when length < 0; js pop will give a
  // length property to any target it is called on.
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

private static Object js_shift(Context cx, Scriptable thisObj,
                Object[] args)
{
  Object result;
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    long i = 0;
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, i);
    /*
     * Slide down the array above the first element.  Leave i
     * set to point to the last element.
     */
    if (length > 0) {
      for (i = 1; i <= length; i++) {
        Object temp = getElem(cx, thisObj, i);
        setElem(cx, thisObj, i - 1, temp);
      }
    }
    // We don't need to delete the last property, because
    // setLength does that for us.
  } else {
    result = Undefined.instance;
  }
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: rhino/js

result = getElem(cx, thisObj, i);
    Object temp = getElem(cx, thisObj, i);
    setElem(cx, thisObj, i - 1, temp);

代码示例来源:origin: rhino/js

private static void heapify_extended(Context cx, Scriptable scope,
                   Object pivot, Scriptable target,
                   long i, long end,
                   Object cmp, Object[] cmpBuf)
{
  for (;;) {
    long child = i * 2 + 1;
    if (child >= end) {
      break;
    }
    Object childVal = getElem(cx, target, child);
    if (child + 1 < end) {
      Object nextVal = getElem(cx, target, child + 1);
      if (isBigger(cx, scope, nextVal, childVal, cmp, cmpBuf)) {
        ++child; childVal = nextVal;
      }
    }
    if (!isBigger(cx, scope, childVal, pivot, cmp, cmpBuf)) {
      break;
    }
    setElem(cx, target, i, childVal);
    i = child;
  }
  setElem(cx, target, i, pivot);
}

代码示例来源:origin: rhino/js

private static Object js_pop(Context cx, Scriptable thisObj,
               Object[] args)
{
  Object result;
  if (thisObj instanceof NativeArray) {
    NativeArray na = (NativeArray) thisObj;
    if (na.denseOnly && na.length > 0) {
      na.length--;
      result = na.dense[(int)na.length];
      na.dense[(int)na.length] = NOT_FOUND;
      return result;
    }
  }
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, length);
    // We don't need to delete the last property, because
    // setLength does that for us.
  } else {
    result = Undefined.instance;
  }
  // necessary to match js even when length < 0; js pop will give a
  // length property to any target it is called on.
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

private static void heapify_extended(Context cx, Scriptable scope,
                   Object pivot, Scriptable target,
                   long i, long end,
                   Object cmp, Object[] cmpBuf)
{
  for (;;) {
    long child = i * 2 + 1;
    if (child >= end) {
      break;
    }
    Object childVal = getElem(cx, target, child);
    if (child + 1 < end) {
      Object nextVal = getElem(cx, target, child + 1);
      if (isBigger(cx, scope, nextVal, childVal, cmp, cmpBuf)) {
        ++child; childVal = nextVal;
      }
    }
    if (!isBigger(cx, scope, childVal, pivot, cmp, cmpBuf)) {
      break;
    }
    setElem(cx, target, i, childVal);
    i = child;
  }
  setElem(cx, target, i, pivot);
}

代码示例来源:origin: ro.isdc.wro4j/rhino

private static Object js_pop(Context cx, Scriptable thisObj,
               Object[] args)
{
  Object result;
  if (thisObj instanceof NativeArray) {
    NativeArray na = (NativeArray) thisObj;
    if (na.denseOnly && na.length > 0) {
      na.length--;
      result = na.dense[(int)na.length];
      na.dense[(int)na.length] = NOT_FOUND;
      return result;
    }
  }
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, length);
    // We don't need to delete the last property, because
    // setLength does that for us.
  } else {
    result = Undefined.instance;
  }
  // necessary to match js even when length < 0; js pop will give a
  // length property to any target it is called on.
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: com.github.tntim96/rhino

private static Object js_pop(Context cx, Scriptable thisObj,
               Object[] args)
{
  Object result;
  if (thisObj instanceof NativeArray) {
    NativeArray na = (NativeArray) thisObj;
    if (na.denseOnly && na.length > 0) {
      na.length--;
      result = na.dense[(int)na.length];
      na.dense[(int)na.length] = NOT_FOUND;
      return result;
    }
  }
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, length);
    // We don't need to delete the last property, because
    // setLength does that for us.
  } else {
    result = Undefined.instance;
  }
  // necessary to match js even when length < 0; js pop will give a
  // length property to any target it is called on.
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

if (ScriptRuntime.shallowEq(getElem(cx, thisObj, i), compareTo)) {
  return new Long(i);
if (ScriptRuntime.shallowEq(getElem(cx, thisObj, i), compareTo)) {
  return new Long(i);

代码示例来源:origin: geogebra/geogebra

private static Object js_pop(Context cx, Scriptable thisObj,
               Object[] args)
{
  Object result;
  if (thisObj instanceof NativeArray) {
    NativeArray na = (NativeArray) thisObj;
    if (na.denseOnly && na.length > 0) {
      na.length--;
      result = na.dense[(int)na.length];
      na.dense[(int)na.length] = NOT_FOUND;
      return result;
    }
  }
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, length);
    // We need to delete the last property, because 'thisObj' may not
    // have setLength which does that for us.
    deleteElem(thisObj, length);
  } else {
    result = Undefined.instance;
  }
  // necessary to match js even when length < 0; js pop will give a
  // length property to any target it is called on.
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: io.apigee/rhino

private static Object js_pop(Context cx, Scriptable thisObj,
               Object[] args)
{
  Object result;
  if (thisObj instanceof NativeArray) {
    NativeArray na = (NativeArray) thisObj;
    if (na.denseOnly && na.length > 0) {
      na.length--;
      result = na.dense[(int)na.length];
      na.dense[(int)na.length] = NOT_FOUND;
      return result;
    }
  }
  long length = getLengthProperty(cx, thisObj);
  if (length > 0) {
    length--;
    // Get the to-be-deleted property's value.
    result = getElem(cx, thisObj, length);
    // We need to delete the last property, because 'thisObj' may not
    // have setLength which does that for us.
    deleteElem(thisObj, length);
  } else {
    result = Undefined.instance;
  }
  // necessary to match js even when length < 0; js pop will give a
  // length property to any target it is called on.
  setLengthProperty(cx, thisObj, length);
  return result;
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

working[i] = getElem(cx, thisObj, i);

代码示例来源:origin: com.sun.phobos/phobos-rhino

private static Object js_unshift(Context cx, Scriptable thisObj,
                 Object[] args)
{
  long length = getLengthProperty(cx, thisObj);
  int argc = args.length;
  if (args.length > 0) {
    /*  Slide up the array to make room for args at the bottom */
    if (length > 0) {
      for (long last = length - 1; last >= 0; last--) {
        Object temp = getElem(cx, thisObj, last);
        setElem(cx, thisObj, last + argc, temp);
      }
    }
    /* Copy from argv to the bottom of the array. */
    for (int i = 0; i < args.length; i++) {
      setElem(cx, thisObj, i, args[i]);
    }
    /* Follow Perl by returning the new array length. */
    length += args.length;
    return setLengthProperty(cx, thisObj, length);
  }
  return ScriptRuntime.wrapNumber(length);
}

代码示例来源:origin: rhino/js

Object temp = getElem(cx, thisObj, last);
setElem(cx, thisObj, last + argc, temp);

代码示例来源:origin: rhino/js

private Scriptable js_slice(Context cx, Scriptable thisObj,
              Object[] args)
{
  Scriptable scope = getTopLevelScope(this);
  Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null);
  long length = getLengthProperty(cx, thisObj);
  long begin, end;
  if (args.length == 0) {
    begin = 0;
    end = length;
  } else {
    begin = toSliceIndex(ScriptRuntime.toInteger(args[0]), length);
    if (args.length == 1) {
      end = length;
    } else {
      end = toSliceIndex(ScriptRuntime.toInteger(args[1]), length);
    }
  }
  for (long slot = begin; slot < end; slot++) {
    Object temp = getElem(cx, thisObj, slot);
    setElem(cx, result, slot - begin, temp);
  }
  return result;
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

private Scriptable js_slice(Context cx, Scriptable thisObj,
              Object[] args)
{
  Scriptable scope = getTopLevelScope(this);
  Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null);
  long length = getLengthProperty(cx, thisObj);
  long begin, end;
  if (args.length == 0) {
    begin = 0;
    end = length;
  } else {
    begin = toSliceIndex(ScriptRuntime.toInteger(args[0]), length);
    if (args.length == 1) {
      end = length;
    } else {
      end = toSliceIndex(ScriptRuntime.toInteger(args[1]), length);
    }
  }
  for (long slot = begin; slot < end; slot++) {
    Object temp = getElem(cx, thisObj, slot);
    setElem(cx, result, slot - begin, temp);
  }
  return result;
}

相关文章

微信公众号