本文整理了Java中org.mozilla.javascript.NativeArray.getLengthProperty()
方法的一些代码示例,展示了NativeArray.getLengthProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeArray.getLengthProperty()
方法的具体详情如下:
包路径:org.mozilla.javascript.NativeArray
类名称:NativeArray
方法名:getLengthProperty
暂无
代码示例来源:origin: rhino/js
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
代码示例来源:origin: geogebra/geogebra
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
代码示例来源:origin: ro.isdc.wro4j/rhino
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
代码示例来源:origin: com.sun.phobos/phobos-rhino
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
代码示例来源:origin: com.github.tntim96/rhino
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
代码示例来源:origin: io.apigee/rhino
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
代码示例来源: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: 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
/**
* 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: 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: 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: geogebra/geogebra
/**
* 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 = getRawElem(thisObj, i);
Object temp2 = getRawElem(thisObj, j);
setRawElem(cx, thisObj, i, temp2);
setRawElem(cx, thisObj, j, temp1);
}
return thisObj;
}
代码示例来源: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: io.apigee/rhino
long length = getLengthProperty(cx, thisObj);
for (int i = 0; i < args.length; i++) {
setElem(cx, thisObj, length + i, args[i]);
代码示例来源:origin: geogebra/geogebra
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 || args[1] == Undefined.instance) {
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) {
defineElem(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: 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: 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;
}
内容来源于网络,如有侵权,请联系作者删除!