use of org.graalvm.polyglot.Value in project graal by oracle.
the class ContextPreInitializationTest method testContextOptionsNoLanguagePreInitialization.
@Test
public void testContextOptionsNoLanguagePreInitialization() throws Exception {
setPatchable();
doContextPreinitialize();
List<CountingContext> contexts = new ArrayList<>(emittedContexts);
assertEquals(0, contexts.size());
final Context ctx = Context.newBuilder().option(FIRST + ".Option1", "true").build();
final Value res = ctx.eval(Source.create(FIRST, "test"));
assertEquals("test", res.asString());
contexts = new ArrayList<>(emittedContexts);
assertEquals(1, contexts.size());
CountingContext context = findContext(FIRST, contexts);
assertNotNull(context);
assertTrue(context.optionValues.get(ContextPreInitializationTestFirstLanguage.Option1));
assertFalse(context.optionValues.get(ContextPreInitializationTestFirstLanguage.Option2));
ctx.close();
}
use of org.graalvm.polyglot.Value in project graal by oracle.
the class ContextPreInitializationTest method testMoreLanguagesPreInitialization.
@Test
public void testMoreLanguagesPreInitialization() throws Exception {
setPatchable(FIRST, SECOND);
doContextPreinitialize(FIRST, SECOND);
List<CountingContext> contexts = new ArrayList<>(emittedContexts);
assertEquals(2, contexts.size());
final CountingContext firstLangCtx = findContext(FIRST, contexts);
assertNotNull(firstLangCtx);
final CountingContext secondLangCtx = findContext(SECOND, contexts);
assertNotNull(secondLangCtx);
assertEquals(1, firstLangCtx.createContextCount);
assertEquals(1, firstLangCtx.initializeContextCount);
assertEquals(0, firstLangCtx.patchContextCount);
assertEquals(0, firstLangCtx.disposeContextCount);
assertEquals(0, firstLangCtx.initializeThreadCount);
assertEquals(0, firstLangCtx.disposeThreadCount);
assertEquals(1, secondLangCtx.createContextCount);
assertEquals(1, secondLangCtx.initializeContextCount);
assertEquals(0, secondLangCtx.patchContextCount);
assertEquals(0, secondLangCtx.disposeContextCount);
assertEquals(0, secondLangCtx.initializeThreadCount);
assertEquals(0, secondLangCtx.disposeThreadCount);
final Context ctx = Context.create();
Value res = ctx.eval(Source.create(FIRST, "test"));
assertEquals("test", res.asString());
contexts = new ArrayList<>(emittedContexts);
assertEquals(2, contexts.size());
assertEquals(1, firstLangCtx.createContextCount);
assertEquals(1, firstLangCtx.initializeContextCount);
assertEquals(1, firstLangCtx.patchContextCount);
assertEquals(0, firstLangCtx.disposeContextCount);
assertEquals(1, firstLangCtx.initializeThreadCount);
assertEquals(0, firstLangCtx.disposeThreadCount);
assertEquals(1, secondLangCtx.createContextCount);
assertEquals(1, secondLangCtx.initializeContextCount);
assertEquals(1, secondLangCtx.patchContextCount);
assertEquals(0, secondLangCtx.disposeContextCount);
assertEquals(1, secondLangCtx.initializeThreadCount);
assertEquals(0, secondLangCtx.disposeThreadCount);
res = ctx.eval(Source.create(SECOND, "test"));
assertEquals("test", res.asString());
contexts = new ArrayList<>(emittedContexts);
assertEquals(2, contexts.size());
assertEquals(1, firstLangCtx.createContextCount);
assertEquals(1, firstLangCtx.initializeContextCount);
assertEquals(1, firstLangCtx.patchContextCount);
assertEquals(0, firstLangCtx.disposeContextCount);
assertEquals(1, firstLangCtx.initializeThreadCount);
assertEquals(0, firstLangCtx.disposeThreadCount);
assertEquals(1, secondLangCtx.createContextCount);
assertEquals(1, secondLangCtx.initializeContextCount);
assertEquals(1, secondLangCtx.patchContextCount);
assertEquals(0, secondLangCtx.disposeContextCount);
assertEquals(1, secondLangCtx.initializeThreadCount);
assertEquals(0, secondLangCtx.disposeThreadCount);
ctx.close();
contexts = new ArrayList<>(emittedContexts);
assertEquals(2, contexts.size());
assertEquals(1, firstLangCtx.createContextCount);
assertEquals(1, firstLangCtx.initializeContextCount);
assertEquals(1, firstLangCtx.patchContextCount);
assertEquals(1, firstLangCtx.disposeContextCount);
assertEquals(1, firstLangCtx.initializeThreadCount);
assertEquals(1, firstLangCtx.disposeThreadCount);
assertEquals(1, secondLangCtx.createContextCount);
assertEquals(1, secondLangCtx.initializeContextCount);
assertEquals(1, secondLangCtx.patchContextCount);
assertEquals(1, secondLangCtx.disposeContextCount);
assertEquals(1, secondLangCtx.initializeThreadCount);
assertEquals(1, secondLangCtx.disposeThreadCount);
}
use of org.graalvm.polyglot.Value in project graal by oracle.
the class ConstraintInteropTypesTest method allowStringReturn.
public void allowStringReturn() {
BrokenTruffleObject obj = new BrokenTruffleObject("30");
polyglot.putMember("value", obj);
Value result = polyglot.getMember("value").execute();
Assert.assertEquals("30", result);
}
use of org.graalvm.polyglot.Value in project graal by oracle.
the class ConstraintInteropTypesTest method forbidNullReturn.
@Test(expected = PolyglotException.class)
public void forbidNullReturn() {
BrokenTruffleObject obj = new BrokenTruffleObject(null);
polyglot.putMember("value", obj);
Value result = polyglot.getMember("value").execute();
fail("No result, an exception should be thrown: " + result);
}
use of org.graalvm.polyglot.Value in project graal by oracle.
the class ConstraintInteropTypesTest method forbidBigIntegerReturn.
@Test(expected = PolyglotException.class)
public void forbidBigIntegerReturn() {
BrokenTruffleObject obj = new BrokenTruffleObject(new BigInteger("30"));
polyglot.putMember("value", obj);
Value result = polyglot.getMember("value").execute();
fail("No result, an exception should be thrown: " + result);
}
Aggregations