Bump version to 24.04.3.4
[LibreOffice.git] / external / beanshell / beanshell-invoke.patch
blobb78f1db6164207e75372e3811fdfb5db08203744
1 --- old/beanshell/engine/src/bsh/engine/BshScriptEngine.java
2 +++ new/beanshell/engine/src/bsh/engine/BshScriptEngine.java
3 @@ -229,6 +229,12 @@
7 + public Object invoke( Object thiz, String name, Object... args )
8 + throws ScriptException, NoSuchMethodException
9 + {
10 + return invokeMethod( thiz, name, args );
11 + }
13 /**
14 * Same as invoke(Object, String, Object...) with <code>null</code> as the
15 * first argument. Used to call top-level procedures defined in scripts.
16 @@ -249,6 +255,12 @@
17 return invokeMethod( getGlobal(), name, args );
20 + public Object invoke( String name, Object... args )
21 + throws ScriptException, NoSuchMethodException
22 + {
23 + return invokeFunction( name, args );
24 + }
26 /**
27 * Returns an implementation of an interface using procedures compiled in the
28 * interpreter. The methods of the interface may be implemented using the
29 --- old/beanshell/engine/src/TestBshScriptEngine.java
30 +++ new/beanshell/engine/src/TestBshScriptEngine.java
31 @@ -2,11 +2,12 @@
32 import java.io.*;
33 import javax.script.*;
34 import static javax.script.ScriptContext.*;
35 +import java.lang.reflect.*;
37 public class TestBshScriptEngine
39 public static void main( String [] args )
40 - throws ScriptException, NoSuchMethodException, IOException
41 + throws ScriptException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException
43 ScriptEngineManager manager =
44 new ScriptEngineManager( bsh.Interpreter.class.getClassLoader() );
45 @@ -39,11 +40,23 @@
46 assertTrue( engine.get("bar").equals("gee") );
47 assertTrue( engine.eval("bar").equals("gee") );
49 + // use reflection to pick available method
50 + Method invokeMe = null;
51 + try {
52 + invokeMe = Invocable.class.getMethod( "invokeFunction", String.class, Object[].class );
53 + } catch ( Exception e ) { }
54 + if (invokeMe == null)
55 + {
56 + try {
57 + invokeMe = Invocable.class.getMethod( "invoke", String.class, Object[].class );
58 + } catch ( Exception e ) { }
59 + }
61 // install and invoke a method
62 engine.eval("foo() { return foo+1; }");
63 // invoke a method
64 Invocable invocable = (Invocable) engine;
65 - int foo = (Integer)invocable.invokeFunction( "foo" );
66 + int foo = (Integer)invokeMe.invoke( invocable, "foo", (Object) new Object[]{} );
67 assertTrue( foo == 43 );
69 // get interface
70 @@ -58,7 +71,7 @@
71 engine.eval(
72 "flag2=false; myObj() { run() { flag2=true; } return this; }");
73 assertTrue( (Boolean)engine.get("flag2") == false );
74 - Object scriptedObject = invocable.invokeFunction("myObj");
75 + Object scriptedObject = invokeMe.invoke( invocable, "myObj", (Object) new Object[]{} );
76 assertTrue( scriptedObject instanceof bsh.This );
77 runnable =
78 (Runnable)invocable.getInterface( scriptedObject, Runnable.class );