/** * Create a Java Object from a result from V8 using a {@link TypeAdapter} to convert * objects. V8 can return basic Java types or V8Values (V8Object, V8Array, etc...). This * method will attempt to convert the result into a pure Java object using * a deep copy. * * If the input is basic Java type (Integer, Double, Boolean, String) * it will be returned. If the input is a V8Value, it will be converted. * * All elements in the V8Object are released after they are accessed. * However, the root object itself is not released. * * @param v8Object The input to convert. * @param adapter The {@link TypeAdapter} to use for the object conversions. * @return A Java object representing the input. */ public static Object getValue(final Object v8Object, final TypeAdapter adapter) { V8Map<Object> cache = new V8Map<Object>(); try { if (v8Object instanceof V8Value) { int type = ((V8Value) v8Object).getV8Type(); return getValue(v8Object, type, cache, adapter); } else { return v8Object; } } finally { cache.close(); } }
/** * Create a Java Object from a result from V8 using a {@link TypeAdapter} to convert * objects. V8 can return basic Java types or V8Values (V8Object, V8Array, etc...). This * method will attempt to convert the result into a pure Java object using * a deep copy. * * If the input is basic Java type (Integer, Double, Boolean, String) * it will be returned. If the input is a V8Value, it will be converted. * * All elements in the V8Object are released after they are accessed. * However, the root object itself is not released. * * @param v8Object The input to convert. * @param adapter The {@link TypeAdapter} to use for the object conversions. * @return A Java object representing the input. */ public static Object getValue(final Object v8Object, final TypeAdapter adapter) { V8Map<Object> cache = new V8Map<Object>(); try { if (v8Object instanceof V8Value) { int type = ((V8Value) v8Object).getV8Type(); return getValue(v8Object, type, cache, adapter); } else { return v8Object; } } finally { cache.close(); } }
@Test public void testGetType_Undefined() { assertEquals(V8Value.UNDEFINED, V8.getUndefined().getV8Type()); }