use of org.graalvm.polyglot.Context in project graal by oracle.
the class LanguageSPITest method testImplicitEngineClose.
@Test
public void testImplicitEngineClose() {
Context context = Context.create();
context.close();
try {
context.getEngine().getOptions();
fail();
} catch (IllegalStateException e) {
// expect closed
}
try {
context.getEngine().getLanguages();
fail();
} catch (IllegalStateException e) {
// expect closed
}
try {
context.getEngine().getInstruments();
fail();
} catch (IllegalStateException e) {
// expect closed
}
// does not fail
context.getEngine().close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class LanguageSPITest method testLookupHostDisabled.
@Test
public void testLookupHostDisabled() {
Context context = Context.newBuilder().allowHostAccess(false).build();
try {
eval(context, new Function<Env, Object>() {
public Object apply(Env t) {
return t.lookupHostSymbol("java.util.HashMap");
}
});
fail();
} catch (PolyglotException e) {
assertTrue(!e.isInternalError());
}
context.close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class LanguageSPITest method testCreateContextDuringDispose.
@Test
public void testCreateContextDuringDispose() {
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.newContextBuilder().build();
}
}
@Override
protected void disposeContext(LanguageContext context) {
if (contextOnDispose.get()) {
context.env.newContextBuilder().build();
}
}
});
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();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class LanguageSPITest method testLazyInit.
@Test
public void testLazyInit() {
LanguageSPITestLanguage.instanceCount.set(0);
Context context = Context.create();
assertEquals(0, LanguageSPITestLanguage.instanceCount.get());
context.initialize(LanguageSPITestLanguage.ID);
assertEquals(1, LanguageSPITestLanguage.instanceCount.get());
context.close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class LanguageSPITest method testErrorInDisposeLanguage.
@Test
public void testErrorInDisposeLanguage() {
AtomicBoolean fail = new AtomicBoolean(true);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected void disposeContext(LanguageContext context) {
if (fail.get()) {
throw new RuntimeException();
}
}
});
Context c = Context.create();
c.initialize(ProxyLanguage.ID);
testFails(() -> {
c.close();
});
testFails(() -> {
c.close();
});
// clean up the context
fail.set(false);
c.close();
}
Aggregations