use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class LanguageSPITest method testPolyglotBindingsPreserveLanguage.
@Test
public void testPolyglotBindingsPreserveLanguage() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {
@Override
public Object execute(VirtualFrame frame) {
Object bindings = getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
try {
ForeignAccess.sendWrite(Message.WRITE.createNode(), (TruffleObject) bindings, "exportedValue", "convertOnToString");
} catch (UnknownIdentifierException | UnsupportedTypeException | UnsupportedMessageException e) {
throw new AssertionError(e);
}
return bindings;
}
});
}
@Override
protected String toString(LanguageContext context, Object value) {
if (value.equals("convertOnToString")) {
return "myStringToString";
}
return super.toString(context, value);
}
});
Context c = Context.create();
c.eval(ProxyLanguage.ID, "");
assertEquals("Make sure language specific toString was invoked.", "myStringToString", c.getPolyglotBindings().getMember("exportedValue").toString());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class ProxySPITest method assertEmpty.
private static void assertEmpty(Message message, TruffleObject proxyInner) {
try {
TruffleObject values = (TruffleObject) ForeignAccess.send(message.createNode(), proxyInner);
Assert.assertEquals(true, ForeignAccess.sendHasSize(Message.HAS_SIZE.createNode(), values));
Assert.assertEquals(0, ((Number) ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), values)).intValue());
} catch (InteropException e) {
Assert.fail();
}
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class ValueHostInteropTest method executableAsFunctionalInterface1.
@Test
public void executableAsFunctionalInterface1() throws Exception {
TruffleObject executable = new FunctionObject();
FunctionalWithDefaults f = context.asValue(executable).as(FunctionalWithDefaults.class);
assertEquals(50, f.call((Object) 13, (Object) 37));
f.hashCode();
f.equals(null);
f.toString();
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class ValueHostInteropTest method executableAsFunctionalInterface3.
@Ignore("Interface not accessible")
@Test
public void executableAsFunctionalInterface3() throws Exception {
assumeTrue("JDK 9 or later", System.getProperty("java.specification.version").compareTo("1.9") >= 0);
TruffleObject executable = new FunctionObject();
FunctionalWithDefaults f = context.asValue(executable).as(FunctionalWithDefaults.class);
assertEquals(42, f.call((Object) 13, (Object) 29));
assertEquals(50, f.call(13, 37));
f.hashCode();
f.equals(null);
f.toString();
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class ConvertAndClassCastTest method convertObjToIntThrowsClassCastException.
@Test(expected = ClassCastException.class)
public void convertObjToIntThrowsClassCastException() {
Object obj = new Object();
TruffleObject truffleObj = JavaInterop.asTruffleObject(obj);
PolyglotEngine eng = PolyglotEngine.newBuilder().globalSymbol("value", truffleObj).build();
Integer v = eng.findGlobalSymbol("value").as(Integer.class);
fail("No value, but exception: " + v);
}
Aggregations