private void setupDebugObject(final V8 runtime) { V8Object outerDebug = runtime.getObject(DEBUG_OBJECT_NAME); try { debugObject = outerDebug.getObject(V8_DEBUG_OBJECT); } finally { outerDebug.close(); } }
this.waitForConnection = waitForConnection; V8Object debugScope = runtime.getObject(DEBUG_OBJECT_NAME); if (debugScope == null) { System.err.println("Cannot initialize debugger server - global debug object not found.");
/** * Returns the version of Node.js that is runtime is built against. * This uses process.versions.node to get the version. * * @return The version of Node.js. */ public String getNodeVersion() { if (nodeVersion != null) { return nodeVersion; } V8Object process = null; V8Object versions = null; try { process = v8.getObject(PROCESS); versions = process.getObject(VERSIONS); nodeVersion = versions.getString(NODE); } finally { safeRelease(process); safeRelease(versions); } return nodeVersion; }
/** * Execute a NodeJS script. This will load the script and execute it on the * next tick. This is the same as how NodeJS executes scripts at startup. Since * the script won't actually run until the next tick, this method does not return * a result. * * @param file The script to execute. */ public void exec(final File file) { V8Function scriptExecution = createScriptExecutionCallback(file); V8Object process = null; V8Array parameters = null; try { process = v8.getObject(PROCESS); parameters = new V8Array(v8); parameters.push(scriptExecution); process.executeObjectFunction(NEXT_TICK, parameters); } finally { safeRelease(process); safeRelease(parameters); safeRelease(scriptExecution); } }
@Test(expected = UnsupportedOperationException.class) public void testAddBooleanUndefined() { V8Object undefined = v8.getObject("object"); undefined.add("foo", false); }
@Test(expected = UnsupportedOperationException.class) public void testAddUndefinedUndefined() { V8Object undefined = v8.getObject("object"); undefined.addUndefined("foo"); }
@Test(expected = UnsupportedOperationException.class) public void testExecuteIntFunctionUndefined() { V8Object undefined = v8.getObject("object"); undefined.executeIntegerFunction("foo", null); }
@Test(expected = UnsupportedOperationException.class) public void testExecuteBooleanFunctionUndefined() { V8Object undefined = v8.getObject("object"); undefined.executeBooleanFunction("foo", null); }
@Test(expected = UnsupportedOperationException.class) public void testExecuteObjectFunctionUndefined() { V8Object undefined = v8.getObject("object"); undefined.executeObjectFunction("foo", null); }
@Test(expected = UnsupportedOperationException.class) public void testExecuteVoidFunctionUndefined() { V8Object undefined = v8.getObject("object"); undefined.executeVoidFunction("foo", null); }
@Test(expected = UnsupportedOperationException.class) public void testGetObjectUndefined() { V8Object undefined = v8.getObject("object"); undefined.getObject("foo"); }
@Test public void testUndefinedToString() { V8Object undefined = v8.getObject("object"); assertEquals("undefined", undefined.toString()); }
@Test(expected = UnsupportedOperationException.class) public void testAddObjectUndefined() { V8Object undefined = v8.getObject("object"); V8Object object = new V8Object(v8); try { undefined.add("foo", object); } finally { object.close(); } }
@Test(expected = UnsupportedOperationException.class) public void testSetPrototype() { V8Object undefined = v8.getObject("object"); V8Object prototype = new V8Object(v8); try { undefined.setPrototype(prototype); } finally { prototype.close(); } }
@Test public void testGetFunction() { v8.executeVoidScript("function add(x, y) {return x+y;}"); V8Object result = v8.getObject("add"); assertTrue(result instanceof V8Function); result.close(); }
@Test(expected = UnsupportedOperationException.class) public void testAddArrayUndefined() { V8Object undefined = v8.getObject("object"); V8Array array = new V8Array(v8); try { undefined.add("foo", array); } finally { array.close(); } }
@Test public void testCallFunctionNullParameters() { v8.executeVoidScript("function call() {return true;}"); V8Function function = (V8Function) v8.getObject("call"); boolean result = (Boolean) function.call(v8, null); assertTrue(result); function.close(); }
@Test public void testTwinIsFunction() { v8.executeVoidScript("function add(x, y) {return x+y;}"); V8Function v8Object = (V8Function) v8.getObject("add"); V8Function twin = v8Object.twin(); assertTrue(twin instanceof V8Function); v8Object.close(); twin.close(); }
@Test public void testNestedInteger() { v8.executeVoidScript("foo = {bar: {key:6}}"); V8Object foo = v8.getObject("foo"); V8Object bar = foo.getObject("bar"); assertEquals(6, bar.getInteger("key")); foo.close(); bar.close(); }
@Test public void testDoesNotContainKey() { V8Map<String> map = new V8Map<String>(); v8.executeVoidScript("var x = {}"); V8Object v8Object = v8.getObject("x"); assertFalse(map.containsKey(v8Object)); v8Object.close(); map.close(); }