/** * Returns the integer value associated with this key. If the value * associated with this key does not exist, or if it's not an integer, then * V8ResultUndefined exception is thrown. * * @param key The key whose value to return. * * @return The integer value associated with this key, or V8ResultUndefined * if the key does not exist or the value is not an integer. */ public int getInteger(final String key) { v8.checkThread(); checkReleased(); checkKey(key); return v8.getInteger(v8.getV8RuntimePtr(), objectHandle, key); }
/** * Returns the integer value associated with this key. If the value * associated with this key does not exist, or if it's not an integer, then * V8ResultUndefined exception is thrown. * * @param key The key whose value to return. * * @return The integer value associated with this key, or V8ResultUndefined * if the key does not exist or the value is not an integer. */ public int getInteger(final String key) { v8.checkThread(); checkReleased(); checkKey(key); return v8.getInteger(v8.getV8RuntimePtr(), objectHandle, key); }
@Test(expected = V8ResultUndefined.class) public void testGetIntWrongType() { v8.executeVoidScript("x = 'foo'"); v8.getInteger("x"); }
@Test(expected = V8ResultUndefined.class) public void testGetIntDoesNotExist() { v8.executeVoidScript(""); v8.getInteger("x"); }
@Test public void testGetIntFromDouble() { v8.executeVoidScript("x = 7.7"); int result = v8.getInteger("x"); assertEquals(7, result); }
/*** Get Int ***/ @Test public void testGetInt() { v8.executeVoidScript("x = 7"); int result = v8.getInteger("x"); assertEquals(7, result); }
@Test public void testGetIntReplaceValue() { v8.executeVoidScript("x = 7; x = 8"); int result = v8.getInteger("x"); assertEquals(8, result); }
@Test public void testVoidFunctionCallNullParameters() { v8.executeVoidScript("function foo() {x=7;}"); v8.executeVoidFunction("foo", null); assertEquals(7, v8.getInteger("x")); }
/*** Void Function ***/ @Test public void testSimpleVoidFunction() { v8.executeVoidScript("function foo() {x=1}"); v8.executeVoidFunction("foo", null); assertEquals(1, v8.getInteger("x")); }
@Test public void testVoidFunctionCallNoParameters() { v8.executeVoidScript("function foo() {x=7;}"); V8Array parameters = new V8Array(v8); v8.executeVoidFunction("foo", parameters); assertEquals(7, v8.getInteger("x")); parameters.close(); }
@Test public void testAddGet() { v8.add("string", "string"); v8.add("int", 7); v8.add("double", 3.1); v8.add("boolean", true); assertEquals("string", v8.getString("string")); assertEquals(7, v8.getInteger("int")); assertEquals(3.1, v8.getDouble("double"), 0.00001); assertTrue(v8.getBoolean("boolean")); }
/** * Returns the integer value associated with this key. If the value * associated with this key does not exist, or if it's not an integer, then * V8ResultUndefined exception is thrown. * * @param key The key whose value to return. * * @return The integer value associated with this key, or V8ResultUndefined * if the key does not exist or the value is not an integer. */ public int getInteger(final String key) { v8.checkThread(); checkReleased(); return v8.getInteger(v8.getV8RuntimePtr(), objectHandle, key); }
/** * Returns the integer value associated with this key. If the value * associated with this key does not exist, or if it's not an integer, then * V8ResultUndefined exception is thrown. * * @param key The key whose value to return. * * @return The integer value associated with this key, or V8ResultUndefined * if the key does not exist or the value is not an integer. */ public int getInteger(final String key) { v8.checkThread(); checkReleased(); return v8.getInteger(v8.getV8RuntimePtr(), objectHandle, key); }
@Test public void testCreateMatrix() { V8Array a1 = new V8Array(v8); V8Array a2 = new V8Array(v8); V8Array a3 = new V8Array(v8); a1.push(1); a1.push(2); a1.push(3); a2.push(4); a2.push(5); a2.push(6); a3.push(7); a3.push(8); a3.push(9); V8Array array = new V8Array(v8); array.push(a1); array.push(a2); array.push(a3); V8Array parameters = new V8Array(v8); parameters.push(array); v8.executeVoidScript("var total = 0; function add(matrix) { for(var i = 0; i < 3; i++) { for (var j = 0; j < 3; j++) { total = total + matrix[i][j]; }}};"); v8.executeVoidFunction("add", parameters); int result = v8.getInteger("total"); assertEquals(45, result); a1.close(); a2.close(); a3.close(); array.close(); parameters.close(); }