/** * Returns the value of this property. * * @return The value of this property. */ public Mirror getValue() { V8Object mirror = v8Object.executeObjectFunction("value", null); try { return createMirror(mirror); } finally { mirror.close(); } }
/** * Returns the name of the Script associated with * this FunctionMirror. * * @return The name of the script. */ public String getScriptName() { V8Object script = v8Object.executeObjectFunction(SCRIPT, null); try { return script.executeStringFunction(NAME, null); } finally { script.close(); } }
/** * Returns the underlying V8Object that represents this scope. * * @return The underlying V8Object that represents this scope. */ public ObjectMirror getScopeObject() { V8Object mirror = null; try { mirror = v8Object.executeObjectFunction(SCOPE_OBJECT, null); return (ObjectMirror) createMirror(mirror); } finally { if ( mirror != null ) { mirror.close(); } } }
/** * Returns the Function associated with this particular debug frame. * * @return The Function for this debug frame. */ public FunctionMirror getFunction() { V8Object function = null; try { function = v8Object.executeObjectFunction(FUNC, null); return new FunctionMirror(function); } finally { if (function != null) { function.close(); } } }
private void sendCompileEvent(final V8Object eventData) throws IOException { if (!isConnected()) { return; } //send event to debugger int type = eventData.getInteger("type_"); V8Object script = eventData.getObject("script_"); V8Object event = null; V8Array params = new V8Array(runtime); try { params.push(script); params.push(type); event = debugObject.executeObjectFunction(MAKE_COMPILE_EVENT, params); String json = event.executeStringFunction("toJSONProtocol", null); if (traceCommunication) { System.out.println("Sending event (CompileEvent):\n" + json.substring(0, Math.min(json.length(), 1000))); } if (json.length() > 0) { sendJson(json); } } finally { params.close(); script.close(); if (event != null) { event.close(); } } }
/** * Returns the value of the local variable at the given index. * * @param index The index of the local to return. * @return The value of local at the given index. */ public ValueMirror getLocalValue(final int index) { V8Array parameters = new V8Array(v8Object.getRuntime()); parameters.push(index); V8Object result = null; try { result = v8Object.executeObjectFunction(LOCAL_VALUE, parameters); if (!isValue(result)) { throw new IllegalStateException("Local value is not a ValueMirror"); } return createMirror(result); } finally { parameters.close(); if (result != null) { result.close(); } } }
/** * Returns the value of the argument at the given index. * * @param index The index of the argument value to return. * @return The value of argument at the given index. */ public ValueMirror getArgumentValue(final int index) { V8Array parameters = new V8Array(v8Object.getRuntime()); parameters.push(index); V8Object result = null; try { result = v8Object.executeObjectFunction(ARGUMENT_VALUE, parameters); if (!isValue(result)) { throw new IllegalStateException("Argument value is not a ValueMirror"); } return new ValueMirror(result); } finally { parameters.close(); if (result != null) { result.close(); } } }
/** * Get the BreakPoint as referenced by the given ID. * * @param breakPointID The BreakPoint ID. * @return The BreakPoint as referenced by the given ID. */ public ScriptBreakPoint getScriptBreakPoint(final int breakPointID) { V8Array parameters = new V8Array(runtime); parameters.push(breakPointID); parameters.push(false); V8Object scriptBreakPoint = null; try { scriptBreakPoint = debugObject.executeObjectFunction(FIND_SCRIPT_BREAK_POINT, parameters); return new ScriptBreakPoint(scriptBreakPoint); } finally { parameters.close(); if (scriptBreakPoint != null) { scriptBreakPoint.close(); } } }
/** * Returns the Frame at a given index * * @param index The stack index * @return The stack frame at a given index */ public Frame getFrame(final int index) { V8Array parameters = new V8Array(v8Object.getRuntime()); parameters.push(index); V8Object frame = null; try { frame = v8Object.executeObjectFunction(FRAME, parameters); return new Frame(frame); } finally { parameters.close(); if (frame != null) { frame.close(); } } }
/** * Returns the scope at a given index. * * @param index The index * @return The scope */ public Scope getScope(final int index) { V8Array parameters = new V8Array(v8Object.getRuntime()); parameters.push(index); V8Object scope = null; try { scope = v8Object.executeObjectFunction(SCOPE, parameters); return new Scope(scope); } finally { parameters.close(); if (scope != null) { scope.close(); } } }
/** * 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); } }
try { params.push(false); stoppedStateDcp = execState.executeObjectFunction("debugCommandProcessor", params); } finally { params.close(); params.push(breakId); params.push(breakpointsHit); event = debugObject.executeObjectFunction(MAKE_BREAK_EVENT, params); String json = event.executeStringFunction("toJSONProtocol", null); if (traceCommunication) {
V8Object sourceLocation = v8Object.executeObjectFunction(SOURCE_LOCATION, null); FunctionMirror function = getFunction(); String functionScriptName = function.getScriptName();
/** * Returns the value of this property. * * @return The value of this property. */ public Mirror getValue() { V8Object mirror = v8Object.executeObjectFunction("value", null); try { return createMirror(mirror); } finally { mirror.close(); } }
/** * Returns the name of the Script associated with * this FunctionMirror. * * @return The name of the script. */ public String getScriptName() { V8Object script = v8Object.executeObjectFunction(SCRIPT, null); try { return script.executeStringFunction(NAME, null); } finally { script.close(); } }
/** * Returns the Function associated with this particular debug frame. * * @return The Function for this debug frame. */ public FunctionMirror getFunction() { V8Object function = null; try { function = v8Object.executeObjectFunction(FUNC, null); return new FunctionMirror(function); } finally { if (function != null) { function.close(); } } }
/** * Returns the underlying V8Object that represents this scope. * * @return The underlying V8Object that represents this scope. */ public ObjectMirror getScopeObject() { V8Object mirror = null; try { mirror = v8Object.executeObjectFunction(SCOPE_OBJECT, null); return (ObjectMirror) createMirror(mirror); } finally { if ( mirror != null ) { mirror.close(); } } }
@Test(expected = UnsupportedOperationException.class) public void testExecuteObjectFunctionUndefined() { V8Object undefined = v8.getObject("object"); undefined.executeObjectFunction("foo", null); }
@Test public void testV8ObjectFunctionCallOnJSObject() { ICallback callback = mock(ICallback.class); doReturn(v8.executeObjectScript("x = {first:'bob'}; x")).when(callback).v8ObjectMethodNoParameters(); V8Object v8Object = new V8Object(v8); v8Object.registerJavaMethod(callback, "v8ObjectMethodNoParameters", "foo", new Class<?>[0]); V8Object result = v8Object.executeObjectFunction("foo", null); verify(callback).v8ObjectMethodNoParameters(); assertEquals("bob", result.getString("first")); v8Object.close(); result.close(); }
@Test public void testObjectFunctionCallOnObject() { v8.executeVoidScript("function getPoint(x, y) {return {'x':x, 'y':y};}"); v8.executeVoidScript("pointer = {};"); v8.executeVoidScript("pointer.pointGetter = getPoint;"); V8Object object = v8.getObject("pointer"); V8Array parameters = new V8Array(v8); parameters.push(8); parameters.push(9); V8Object result = object.executeObjectFunction("pointGetter", parameters); parameters.close(); assertEquals(8, result.getInteger("x")); assertEquals(9, result.getInteger("y")); result.close(); object.close(); }