use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class VirtualizedFileSystemTest method testToUri.
@Test
public void testToUri() {
final Context ctx = cfg.getContext();
final Path userDir = cfg.getUserDir();
final boolean allowsUserDir = cfg.allowsUserDir();
if (cfg.needsURI()) {
// Nothing to test for URI path
return;
}
languageAction = (Env env) -> {
final TruffleFile file = env.getTruffleFile(FOLDER_EXISTING).resolve(FILE_EXISTING);
try {
final URI uri = file.toUri();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), allowsUserDir);
Assert.assertEquals(cfg.formatErrorMessage("URI"), userDir.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING).toUri(), uri);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), allowsUserDir);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class VirtualizedFileSystemTest method testList.
@Test
public void testList() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final Path folderExisting = path.resolve(FOLDER_EXISTING);
final TruffleFile file = cfg.needsURI() ? env.getTruffleFile(folderExisting.toUri()) : env.getTruffleFile(folderExisting.toString());
try {
final String expected = path.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING).toString();
final Collection<? extends TruffleFile> children = file.list();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
final Optional<String> expectedFile = children.stream().map(TruffleFile::getAbsoluteFile).map(TruffleFile::getPath).filter(expected::equals).findAny();
Assert.assertTrue(cfg.formatErrorMessage("Expected child"), expectedFile.isPresent());
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class VirtualizedFileSystemTest method isReadable.
@Test
public void isReadable() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean readable = file.isReadable();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertTrue(cfg.formatErrorMessage("Is readable"), readable);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class PolyglotLanguageContext method patch.
boolean patch(Map<String, String> newOptions, String[] newApplicationArguments) {
final boolean preInitialized = isInitialized();
if (preInitialized) {
// Reset options from image generation time
optionValues = null;
}
if (newOptions != null) {
getOptionValues().putAll(newOptions);
}
setApplicationArguments(newApplicationArguments);
if (preInitialized) {
try {
final Env newEnv = LANGUAGE.patchEnvContext(env, context.out, context.err, context.in, config, getOptionValues(), newApplicationArguments, context.fileSystem);
if (newEnv != null) {
env = newEnv;
return true;
}
return false;
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
throw t;
}
throw PolyglotImpl.wrapGuestException(this, t);
}
} else {
return true;
}
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class PolyglotLanguageContext method ensureCreated.
void ensureCreated(PolyglotLanguage accessingLanguage) {
language.ensureInitialized();
if (creating) {
throw new PolyglotIllegalStateException(String.format("Cyclic access to language context for language %s. " + "The context is currently being created.", language.getId()));
}
boolean created = false;
if (env == null) {
synchronized (context) {
if (env == null) {
checkAccess(accessingLanguage);
boolean singleThreaded = context.isSingleThreaded();
Thread firstFailingThread = null;
for (PolyglotThreadInfo threadInfo : context.getSeenThreads().values()) {
if (!LANGUAGE.isThreadAccessAllowed(language.info, threadInfo.thread, singleThreaded)) {
firstFailingThread = threadInfo.thread;
break;
}
}
if (firstFailingThread != null) {
throw PolyglotContextImpl.throwDeniedThreadAccess(firstFailingThread, singleThreaded, Arrays.asList(language));
}
creating = true;
try {
initializeCaches();
try {
Env createdEnv = env = LANGUAGE.createEnv(this, language.info, context.out, context.err, context.in, config, getOptionValues(), applicationArguments, context.fileSystem);
LANGUAGE.createEnvContext(createdEnv);
language.requireProfile().notifyContextCreate(createdEnv);
} finally {
creating = false;
}
created = true;
} catch (Throwable e) {
// language not successfully created, reset to avoid inconsistent
// language contexts
env = null;
throw e;
}
}
}
}
if (created && eventsEnabled) {
VMAccessor.INSTRUMENT.notifyLanguageContextCreated(context.engine, context.truffleContext, language.info);
}
}
Aggregations