/** * Add a new method to the class, representing a rest-of version of the function node * * @param functionNode the function node to generate a method for * @return method emitter to use for weaving this method */ MethodEmitter restOfMethod(final FunctionNode functionNode) { methodCount++; methodNames.add(functionNode.getName()); final MethodVisitor mv = cw.visitMethod( ACC_PUBLIC | ACC_STATIC, functionNode.getName(), Type.getMethodDescriptor(functionNode.getReturnType().getTypeClass(), RewriteException.class), null, null); return new MethodEmitter(this, mv, functionNode); }
/** * Add a new method to the class, representing a rest-of version of the * function node. * * @param functionNode the function node to generate a method for * * @return method emitter to use for weaving this method */ MethodEmitter restOfMethod(final FunctionNode functionNode) { methodCount++; methodNames.add(functionNode.getName()); final MethodVisitor mv = cw.visitMethod( ACC_PUBLIC | ACC_STATIC, functionNode.getName(), Type.getMethodDescriptor(functionNode.getReturnType().getTypeClass(), RewriteException.class), null, null); return new MethodEmitter(this, mv, functionNode); }
@Test public void rewriteExceptionNotSerializable() throws ScriptException { // NOTE: we must create a RewriteException in a context of a Nashorn engine, as it uses Global.newIntance() // internally. final ScriptEngine e = new NashornScriptEngineFactory().getScriptEngine(); e.put("f", new Runnable() { @Override public void run() { tryToSerialize(RewriteException.create(null, new Object[0], new String[0])); } }); e.eval("f()"); }
/** * Constructor * * @param level logging level * @param rewriteException rewriteException wrapped by this RuntimEvent * @param returnValue rewriteException return value - as we don't want to make * {@code RewriteException.getReturnValueNonDestructive()} public, we pass it as * an extra parameter, rather than querying the getter from another package. */ public RecompilationEvent(final Level level, final RewriteException rewriteException, final Object returnValue) { super(level, rewriteException); assert Context.getContext().getLogger(RecompilableScriptFunctionData.class).isEnabled() : "Unit test/instrumentation purpose only: RecompilationEvent instances should not be created without '--log=recompile', or we will leak memory in the general case"; this.returnValue = returnValue; }