/** * Returns the executor associated with the given key. * * @param key The key the executor was associated with. * @return The executor or null if it does not exist. */ public V8Executor getExecutor(final V8Object key) { checkThread(); if (executors == null) { return null; } return executors.get(key); }
@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; }
@SuppressWarnings("unchecked") private static Map<String, ? super Object> toMap(final V8Object v8Object, final V8Map<Object> cache, final TypeAdapter adapter) { if (v8Object == null) { return Collections.emptyMap(); } if (cache.containsKey(v8Object)) { return (Map<String, ? super Object>) cache.get(v8Object); } Map<String, ? super Object> result = new V8PropertyMap<Object>(); cache.put(v8Object, result); String[] keys = v8Object.getKeys(); for (String key : keys) { Object object = null; int type = V8Value.UNDEFINED; try { object = v8Object.get(key); type = v8Object.getType(key); Object value = getValue(object, type, cache, adapter); if (value != IGNORE) { result.put(key, value); } } finally { if (object instanceof Releasable) { ((Releasable) object).release(); } } } return result; }
/** * Returns the executor associated with the given key. * * @param key The key the executor was associated with. * @return The executor or null if it does not exist. */ public V8Executor getExecutor(final V8Object key) { checkThread(); if (executors == null) { return null; } return executors.get(key); }
@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; }
@SuppressWarnings("unchecked") private static Map<String, ? super Object> toMap(final V8Object v8Object, final V8Map<Object> cache, final TypeAdapter adapter) { if (v8Object == null) { return Collections.emptyMap(); } if (cache.containsKey(v8Object)) { return (Map<String, ? super Object>) cache.get(v8Object); } Map<String, ? super Object> result = new V8PropertyMap<Object>(); cache.put(v8Object, result); String[] keys = v8Object.getKeys(); for (String key : keys) { Object object = null; int type = V8Value.UNDEFINED; try { object = v8Object.get(key); type = v8Object.getType(key); Object value = getValue(object, type, cache, adapter); if (value != IGNORE) { result.put(key, value); } } finally { if (object instanceof Releasable) { ((Releasable) object).release(); } } } return result; }
@Test public void testGetMissing() { V8Map<String> map = new V8Map<String>(); v8.executeVoidScript("var x = {}"); V8Object v8Object = v8.getObject("x"); assertNull(map.get(v8Object)); v8Object.close(); map.close(); }
@Test public void testGet() { V8Map<String> map = new V8Map<String>(); v8.executeVoidScript("var x = {}"); V8Object v8Object = v8.getObject("x"); map.put(v8Object, "foo"); assertEquals("foo", map.get(v8Object)); v8Object.close(); map.close(); }
@Test public void testAddDuplicateKey() { V8Map<String> map = new V8Map<String>(); V8Object v1 = new V8Object(v8); map.put(v1, "foo"); map.put(v1, "bar"); assertEquals("bar", map.get(v1)); v1.close(); map.close(); }
@Test public void testPutUndefined() { V8Map<Object> map = new V8Map<Object>(); V8Object v1 = new V8Object(v8); map.put(v1, V8.getUndefined()); assertEquals(V8.getUndefined(), map.get(v1)); v1.close(); map.close(); }
/** * Returns the executor associated with the given key. * * @param key The key the executor was associated with. * @return The executor or null if it does not exist. */ public V8Executor getExecutor(final V8Object key) { checkThread(); if (executors == null) { return null; } return executors.get(key); }
/** * Returns the executor associated with the given key. * * @param key The key the executor was associated with. * @return The executor or null if it does not exist. */ public V8Executor getExecutor(final V8Object key) { checkThread(); if (executors == null) { return null; } return executors.get(key); }
@SuppressWarnings("unchecked") private static List<? super Object> toList(final V8Array array, final V8Map<Object> cache) { 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 value = getValue(array, i, cache); if (value != IGNORE) { result.add(getValue(array, i, cache)); } } return result; }
@SuppressWarnings("unchecked") private static List<? super Object> toList(final V8Array array, final V8Map<Object> cache) { 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 value = getValue(array, i, cache); if (value != IGNORE) { result.add(getValue(array, i, cache)); } } return result; }
@SuppressWarnings("unchecked") private static Map<String, ? super Object> toMap(final V8Object object, final V8Map<Object> cache) { if (object == null) { return Collections.emptyMap(); } if (cache.containsKey(object)) { return (Map<String, ? super Object>) cache.get(object); } Map<String, ? super Object> result = new V8PropertyMap<Object>(); cache.put(object, result); String[] keys = object.getKeys(); for (String key : keys) { Object value = getValue(object, key, cache); if (value != IGNORE) { result.put(key, value); } } return result; }
@SuppressWarnings("unchecked") private static Map<String, ? super Object> toMap(final V8Object object, final V8Map<Object> cache) { if (object == null) { return Collections.emptyMap(); } if (cache.containsKey(object)) { return (Map<String, ? super Object>) cache.get(object); } Map<String, ? super Object> result = new V8PropertyMap<Object>(); cache.put(object, result); String[] keys = object.getKeys(); for (String key : keys) { Object value = getValue(object, key, cache); if (value != IGNORE) { result.put(key, value); } } return result; }