use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testIsHostAccessAllowed.
@Test
public void testIsHostAccessAllowed() {
Context context = Context.newBuilder().allowHostAccess(false).build();
assertTrue(!eval(context, env -> env.isHostLookupAllowed()).asBoolean());
context.close();
context = Context.newBuilder().allowHostAccess(true).build();
assertTrue(eval(context, env -> env.isHostLookupAllowed()).asBoolean());
context.close();
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testExportSymbolInCreate.
@SuppressWarnings("deprecation")
@Test
public void testExportSymbolInCreate() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected LanguageContext createContext(com.oracle.truffle.api.TruffleLanguage.Env env) {
env.exportSymbol("symbol", env.asGuestValue(env));
return super.createContext(env);
}
});
Context c = Context.create();
c.initialize(ProxyLanguage.ID);
assertTrue(c.importSymbol("symbol").isHostObject());
c.close();
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testEngineCloseInsideFromSameThreadCancelExecution.
@Test
public void testEngineCloseInsideFromSameThreadCancelExecution() {
Engine engine = Engine.create();
langContext = null;
Context context = Context.newBuilder(LanguageSPITestLanguage.ID).engine(engine).build();
eval(context, new Function<Env, Object>() {
public Object apply(Env t) {
engine.close(true);
return null;
}
});
assertEquals(1, langContext.disposeCalled);
engine.close();
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testCloseInnerContextWithParent.
@Test
public void testCloseInnerContextWithParent() {
Context context = Context.create();
LanguageContext returnedInnerContext = eval(context, new Function<Env, Object>() {
public Object apply(Env env) {
TruffleContext innerContext = env.newContextBuilder().build();
Object p = innerContext.enter();
LanguageContext innerLangContext = LanguageSPITestLanguage.getContext();
innerContext.leave(p);
return innerLangContext;
}
}).asHostObject();
context.close();
// inner context automatically closed
assertEquals(1, returnedInnerContext.disposeCalled);
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testCreateThreadDuringDispose.
@Test
public void testCreateThreadDuringDispose() {
AtomicBoolean contextOnFinalize = new AtomicBoolean(true);
AtomicBoolean contextOnDispose = new AtomicBoolean(false);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected LanguageContext createContext(Env env) {
return new LanguageContext(env);
}
@Override
protected void finalizeContext(LanguageContext context) {
if (contextOnFinalize.get()) {
context.env.createThread(() -> {
}).start();
}
}
@Override
protected void disposeContext(LanguageContext context) {
if (contextOnDispose.get()) {
context.env.createThread(() -> {
}).start();
}
}
});
Context c = Context.create();
c.initialize(ProxyLanguage.ID);
// Fails on finalize
testFails(() -> {
c.close();
});
contextOnFinalize.set(false);
contextOnDispose.set(true);
// Fails on dispose
testFails(() -> {
c.close();
});
// clean up the context
contextOnDispose.set(false);
c.close();
}
Aggregations