本文整理了Java中org.mozilla.javascript.NativeArray.setElem()
方法的一些代码示例,展示了NativeArray.setElem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeArray.setElem()
方法的具体详情如下:
包路径:org.mozilla.javascript.NativeArray
类名称:NativeArray
方法名:setElem
暂无
代码示例来源:origin: io.apigee/rhino
private static void setRawElem(Context cx, Scriptable target, long index,
Object value) {
if (value == NOT_FOUND) {
deleteElem(target, index);
} else {
setElem(cx, target, index, value);
}
}
代码示例来源:origin: ro.isdc.wro4j/rhino
private static void setRawElem(Context cx, Scriptable target, long index,
Object value) {
if (value == NOT_FOUND) {
deleteElem(target, index);
} else {
setElem(cx, target, index, value);
}
}
代码示例来源:origin: geogebra/geogebra
private static void setRawElem(Context cx, Scriptable target, long index,
Object value) {
if (value == NOT_FOUND) {
deleteElem(target, index);
} else {
setElem(cx, target, index, value);
}
}
代码示例来源:origin: com.github.tntim96/rhino
private static void setRawElem(Context cx, Scriptable target, long index,
Object value) {
if (value == NOT_FOUND) {
deleteElem(target, index);
} else {
setElem(cx, target, index, value);
}
}
代码示例来源: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: 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: 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: 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: com.sun.phobos/phobos-rhino
/**
* Non-ECMA methods.
*/
private static Object js_push(Context cx, Scriptable thisObj,
Object[] args)
{
long length = getLengthProperty(cx, thisObj);
for (int i = 0; i < args.length; i++) {
setElem(cx, thisObj, length + i, args[i]);
}
length += args.length;
Object lengthObj = setLengthProperty(cx, thisObj, length);
/*
* If JS1.2, follow Perl4 by returning the last thing pushed.
* Otherwise, return the new array length.
*/
if (cx.getLanguageVersion() == Context.VERSION_1_2)
// if JS1.2 && no arguments, return undefined.
return args.length == 0
? Undefined.instance
: args[args.length - 1];
else
return lengthObj;
}
代码示例来源: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
setElem(cx, thisObj, length + i, args[i]);
代码示例来源:origin: io.apigee/rhino
setElem(cx, thisObj, length + i, args[i]);
代码示例来源:origin: geogebra/geogebra
setElem(cx, thisObj, length + i, args[i]);
代码示例来源: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: 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: ro.isdc.wro4j/rhino
private Scriptable js_slice(Context cx, Scriptable thisObj,
Object[] args)
{
Scriptable scope = getTopLevelScope(this);
Scriptable result = cx.newArray(scope, 0);
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 = getRawElem(thisObj, slot);
if (temp != NOT_FOUND) {
setElem(cx, result, slot - begin, temp);
}
}
setLengthProperty(cx, result, Math.max(0, end - begin));
return result;
}
代码示例来源:origin: com.github.tntim96/rhino
private Scriptable js_slice(Context cx, Scriptable thisObj,
Object[] args)
{
Scriptable scope = getTopLevelScope(this);
Scriptable result = cx.newArray(scope, 0);
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 = getRawElem(thisObj, slot);
if (temp != NOT_FOUND) {
setElem(cx, result, slot - begin, temp);
}
}
setLengthProperty(cx, result, Math.max(0, end - begin));
return result;
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!