use of org.graalvm.polyglot.Context in project graal by oracle.
the class ContextAPITest method testEnteredExecute.
@Test
public void testEnteredExecute() {
Context context = Context.create(ContextAPITestLanguage.ID);
// test outside
testExecute(context);
// test inside
context.enter();
testExecute(context);
context.leave();
// test enter twice
context.enter();
context.enter();
testExecute(context);
context.leave();
testExecute(context);
context.leave();
testExecute(context);
// test entered with inner context
context.enter();
Context context2 = Context.create(ContextAPITestLanguage.ID);
testExecute(context2);
context2.enter();
testExecute(context2);
context2.leave();
context2.enter();
context2.enter();
testExecute(context2);
context2.leave();
testExecute(context2);
context2.leave();
context2.close();
context.leave();
// finally close the context
context.close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class ContextAPITest method testImportExport.
@Test
public void testImportExport() {
Context context = Context.create();
Value polyglotBindings = context.getPolyglotBindings();
polyglotBindings.putMember("string", "bar");
polyglotBindings.putMember("null", null);
polyglotBindings.putMember("int", 42);
Object object = new Object();
polyglotBindings.putMember("object", object);
assertEquals("bar", polyglotBindings.getMember("string").asString());
assertTrue(polyglotBindings.getMember("null").isNull());
assertEquals(42, polyglotBindings.getMember("int").asInt());
assertSame(object, polyglotBindings.getMember("object").asHostObject());
assertNull(polyglotBindings.getMember("notexisting"));
context.close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class ContextAPITest method testEnterLeave.
public void testEnterLeave() {
Context context = Context.create();
testEnterLeave(context, 0);
context.close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class ContextAPITest method testContextCreateAllLanguages.
@Test
public void testContextCreateAllLanguages() {
Context context = Context.create();
context.eval(ContextAPITestLanguage.ID, "");
context.eval(LanguageSPITestLanguage.ID, "");
assertInternalNotAccessible(context);
context.close();
}
use of org.graalvm.polyglot.Context in project graal by oracle.
the class ContextPreInitializationTest method testSystemPropertiesOptionsFailedPatch.
@Test
public void testSystemPropertiesOptionsFailedPatch() throws Exception {
System.setProperty(SYS_OPTION1_KEY, "true");
setPatchable();
doContextPreinitialize(FIRST);
List<CountingContext> contexts = new ArrayList<>(emittedContexts);
final CountingContext firstLangCtx = findContext(FIRST, contexts);
assertNotNull(firstLangCtx);
assertFalse(firstLangCtx.optionValues.get(ContextPreInitializationTestFirstLanguage.Option1));
assertFalse(firstLangCtx.optionValues.get(ContextPreInitializationTestFirstLanguage.Option2));
firstLangCtx.optionValues.clear();
System.getProperties().remove(SYS_OPTION1_KEY);
System.setProperty(SYS_OPTION2_KEY, "true");
final Context ctx = Context.create();
Value res = ctx.eval(Source.create(FIRST, "test"));
assertEquals("test", res.asString());
contexts = new ArrayList<>(emittedContexts);
contexts.remove(firstLangCtx);
final CountingContext firstLangCtx2 = findContext(FIRST, contexts);
assertNotNull(firstLangCtx2);
assertFalse(firstLangCtx2.optionValues.get(ContextPreInitializationTestFirstLanguage.Option1));
assertTrue(firstLangCtx2.optionValues.get(ContextPreInitializationTestFirstLanguage.Option2));
ctx.close();
}
Aggregations