本文整理了Java中com.eclipsesource.v8.V8Array.length()
方法的一些代码示例,展示了V8Array.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8Array.length()
方法的具体详情如下:
包路径:com.eclipsesource.v8.V8Array
类名称:V8Array
方法名:length
[英]Returns the length of this array.
[中]返回此数组的长度。
代码示例来源:origin: eclipsesource/J2V8
/**
* Returns the number of properties contained in this array.
*
* @return The length of this array.
*/
public int length() {
return v8Array.length();
}
代码示例来源:origin: jooby-project/jooby
private static JavaVoidCallback console(V8 v8, final Consumer<String> log) {
return (self, args) -> {
StringBuilder buff = new StringBuilder();
for (int i = 0; i < args.length(); i++) {
buff.append(args.get(i));
}
log.accept(buff.toString());
};
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings("unchecked")
private List<String> filter(final V8Array args, final int i) {
if (i < args.length()) {
Object value = V8ObjectUtils.getValue(args, i);
if (value == V8.getUndefined()) {
return Collections.emptyList();
}
List<String> filter = new ArrayList<>();
if (value instanceof Collection) {
filter.addAll((Collection<? extends String>) value);
} else {
filter.add(value.toString());
}
return filter;
}
return Collections.emptyList();
}
}
代码示例来源:origin: eclipsesource/J2V8
private void populateParamters(final V8Array parameters, final int varArgIndex, final Object[] args, final List<Object> varArgs, final boolean includeReceiver) {
int start = 0;
if (includeReceiver) {
start = 1;
}
for (int i = start; i < (parameters.length() + start); i++) {
if (i >= varArgIndex) {
varArgs.add(getArrayItem(parameters, i - start));
} else {
args[i] = getArrayItem(parameters, i - start);
}
}
}
代码示例来源:origin: jooby-project/jooby
private List<AssetProblem> problems(final V8Array array) {
ImmutableList.Builder<AssetProblem> result = ImmutableList.builder();
for (int i = 0; i < array.length(); i++) {
result.add(problem(register(v8, array.getObject(i))));
}
return result.build();
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Returns a count of all the breakpoints
*
* @return A V8Array of Breakpoints.
*/
public int getScriptBreakPointCount() {
V8Array breakPoints = debugObject.executeArrayFunction(SCRIPT_BREAK_POINTS, null);
try {
return breakPoints.length();
} finally {
breakPoints.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Get all the BreakPoint IDs as an array.
*
* @return A list of BreakPoint IDs.
*/
public int[] getScriptBreakPointIDs() {
V8Array breakPoints = debugObject.executeArrayFunction(SCRIPT_BREAK_POINTS, null);
try {
int[] result = new int[breakPoints.length()];
for (int i = 0; i < breakPoints.length(); i++) {
V8Object breakPoint = breakPoints.getObject(i);
try {
result[i] = breakPoint.executeIntegerFunction(NUMBER, null);
} finally {
breakPoint.close();
}
}
return result;
} finally {
breakPoints.close();
}
}
代码示例来源:origin: eclipsesource/J2V8
/**
* Creates a Java array from a V8Array. The type of the Array must be specified.
* Currently, only INTEGER, DOUBLE, BOOLEAN and STRING are supported.
* The V8Array must only contain elements of type 'arrayType'.
*
* This method will use J2V8's bulk array copy making it faster than iterating over
* all the elements in the array.
*
* @param array The V8Array to convert to a Java Array.
* @param arrayType The type of the V8Array to convert.
*
* @return A Java array representing a V8Array.
*/
public static Object getTypedArray(final V8Array array, final int arrayType) {
int length = array.length();
if (arrayType == V8Value.INTEGER) {
return array.getIntegers(0, length);
} else if (arrayType == V8Value.DOUBLE) {
return array.getDoubles(0, length);
} else if (arrayType == V8Value.BOOLEAN) {
return array.getBooleans(0, length);
} else if (arrayType == V8Value.STRING) {
return array.getStrings(0, length);
}
throw new RuntimeException("Unsupported bulk load type: " + arrayType);
}
代码示例来源:origin: eclipsesource/J2V8
@SuppressWarnings("unchecked")
private static List<? super Object> toList(final V8Array array, final V8Map<Object> cache, final TypeAdapter adapter) {
if (array == null) {
return Collections.emptyList();
}
if (cache.containsKey(array)) {
return (List<? super Object>) cache.get(array);
}
List<? super Object> result = new ArrayList<Object>();
cache.put(array, result);
for (int i = 0; i < array.length(); i++) {
Object object = null;
int type = V8Value.UNDEFINED;
try {
object = array.get(i);
type = array.getType(i);
Object value = getValue(object, type, cache, adapter);
if (value != IGNORE) {
result.add(value);
}
} finally {
if (object instanceof Releasable) {
((Releasable) object).release();
}
}
}
return result;
}
代码示例来源:origin: eclipsesource/J2V8
int length = array.length();
if (arrayType == V8Value.INTEGER) {
int[] intArray = (int[]) result;
代码示例来源:origin: eclipsesource/J2V8
/**
* Returns all the property names for the given object.
*
* @param kind Indicate whether named, indexed or both kinds of properties are requested.
* @param limit Limit the number of properties returned to the specified value
* @return All the property names for a given object
*/
public String[] getPropertyNames(final PropertyKind kind, final int limit) {
V8Array parameters = new V8Array(v8Object.getRuntime());
parameters.push(kind.index);
parameters.push(limit);
V8Array propertyNames = null;
try {
propertyNames = v8Object.executeArrayFunction(PROPERTY_NAMES, parameters);
String[] result = new String[propertyNames.length()];
for (int i = 0; i < result.length; i++) {
result[i] = propertyNames.getString(i);
}
return result;
} finally {
parameters.close();
if (propertyNames != null) {
propertyNames.close();
}
}
}
代码示例来源:origin: eclipsesource/J2V8
@Override
public Boolean answer(final InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
int arrayLength = ((V8Array) args[0]).length();
int result = 0;
for (int i = 0; i < arrayLength; i++) {
result += ((V8Array) args[0]).getInteger(i);
}
return result > 10;
}
}).when(callback).booleanMethodWithArrayParameter(any(V8Array.class));
代码示例来源:origin: eclipsesource/J2V8
/*** Array Function ***/
@Test
public void testSimpleArrayFunction() {
v8.executeVoidScript("function foo() {return [1,2,3];}");
V8Array result = v8.executeArrayFunction("foo", null);
assertEquals(3, result.length());
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testArrayFunctionCallNullParameters() {
v8.executeVoidScript("function foo() {return [1,2];}");
V8Array result = v8.executeArrayFunction("foo", null);
assertEquals(2, result.length());
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testLargeArrayGetInt() {
V8Array array = v8.executeArrayScript("foo = []; for ( var i = 0; i < 10000; i++) {foo[i] = i;}; foo");
assertEquals(10000, array.length());
for (int i = 0; i < 10000; i++) {
assertEquals(i, array.getInteger(i));
}
array.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testGetTypedRangeArrayValue() {
V8Array result = (V8Array) v8.executeScript("var buf = new ArrayBuffer(100); var ints = new Int32Array(buf); for(var i = 0; i < 25; i++) {ints[i] = i;}; ints");
assertEquals(25, result.length());
int[] ints = result.getIntegers(0, 25);
for (int i = 0; i < ints.length; i++) {
assertEquals(i, ints[i]);
}
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAddNull() {
V8Array v8Array = new V8Array(v8);
v8Array.pushNull();
assertEquals(1, v8Array.length());
assertEquals(NULL, v8Array.getType(0));
assertNull(v8Array.getObject(0));
v8Array.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAnyScriptReturnsV8Array() {
V8Array result = (V8Array) v8.executeScript("[1,2,3];");
assertEquals(3, result.length());
assertEquals(1, result.get(0));
assertEquals(2, result.get(1));
assertEquals(3, result.get(2));
result.close();
}
代码示例来源:origin: eclipsesource/J2V8
@Test
public void testAddBoolean() {
V8Array array = new V8Array(v8);
array.push(true);
array.push(false);
assertEquals(2, array.length());
assertTrue(array.getBoolean(0));
assertFalse(array.getBoolean(1));
array.close();
}
代码示例来源:origin: eclipsesource/J2V8
/**** Mixed Array ****/
@Test
public void testMixedArray() {
V8Array array = v8.executeArrayScript("['a', 3, 3.1, true];");
assertEquals(4, array.length());
assertEquals("a", array.getString(0));
assertEquals(3, array.getInteger(1));
assertEquals(3.1, array.getDouble(2), 0.00001);
assertTrue(array.getBoolean(3));
array.close();
}
内容来源于网络,如有侵权,请联系作者删除!