|
50 | 50 | import java.io.IOException;
|
51 | 51 | import java.io.UnsupportedEncodingException;
|
52 | 52 | import java.util.Arrays;
|
| 53 | +import java.util.HashMap; |
53 | 54 | import java.util.Map;
|
54 | 55 |
|
55 | 56 | import org.graalvm.polyglot.Context;
|
|
60 | 61 | import org.graalvm.polyglot.Value;
|
61 | 62 | import org.graalvm.polyglot.proxy.ProxyArray;
|
62 | 63 | import org.graalvm.polyglot.proxy.ProxyHashMap;
|
| 64 | +import org.graalvm.polyglot.proxy.ProxyExecutable; |
| 65 | +import org.graalvm.polyglot.proxy.ProxyObject; |
63 | 66 | import org.junit.After;
|
64 | 67 | import org.junit.Before;
|
65 | 68 | import org.junit.Test;
|
| 69 | +import org.junit.Ignore; |
66 | 70 | import org.junit.experimental.runners.Enclosed;
|
67 | 71 | import org.junit.runner.RunWith;
|
68 | 72 | import org.junit.runners.Parameterized;
|
@@ -324,6 +328,53 @@ public void accessSuitePy() throws IOException {
|
324 | 328 | assertEquals("'e39957904b7e79caf4fa54f30e8e4ee74d4e9e37'", dacapo.getHashValue("sha1").toString());
|
325 | 329 | }
|
326 | 330 |
|
| 331 | + public class AForeignExecutable implements ProxyExecutable { |
| 332 | + @Override |
| 333 | + public Object execute(Value... arguments) { |
| 334 | + throw new UnsupportedOperationException("wrong arity"); |
| 335 | + } |
| 336 | + } |
| 337 | + |
| 338 | + @Ignore // blocked by GR-46281 |
| 339 | + @Test |
| 340 | + public void runAForeignExecutable() throws IOException { |
| 341 | + Source suitePy = Source.newBuilder("python", |
| 342 | + """ |
| 343 | + def foo(obj): |
| 344 | + try: |
| 345 | + obj() |
| 346 | + except TypeError as e: |
| 347 | + pass |
| 348 | + else: |
| 349 | + assert False |
| 350 | + foo |
| 351 | + """, |
| 352 | + "suite.py").build(); |
| 353 | + Value foo = context.eval(suitePy); |
| 354 | + foo.execute(new AForeignExecutable()); |
| 355 | + } |
| 356 | + |
| 357 | + @Ignore // blocked by GR-46281 |
| 358 | + @Test |
| 359 | + public void invokeAForeignMember() throws IOException { |
| 360 | + Source suitePy = Source.newBuilder("python", |
| 361 | + """ |
| 362 | + def foo(obj): |
| 363 | + try: |
| 364 | + obj.fun() |
| 365 | + except TypeError as e: |
| 366 | + pass |
| 367 | + else: |
| 368 | + assert False |
| 369 | + foo |
| 370 | + """, |
| 371 | + "suite.py").build(); |
| 372 | + Map<String, Object> m = new HashMap<>(); |
| 373 | + m.put("fun", new AForeignExecutable()); |
| 374 | + Value foo = context.eval(suitePy); |
| 375 | + foo.execute(ProxyObject.fromMap(m)); |
| 376 | + } |
| 377 | + |
327 | 378 | @ExportLibrary(InteropLibrary.class)
|
328 | 379 | public static class ForeignObjectWithOOInvoke implements TruffleObject {
|
329 | 380 | public String getMyName() {
|
|
0 commit comments