Skip to content

Commit a5258c3

Browse files
author
Jaroslav Tulach
committed
PolyglotEngine.Language.getGlobalObject may initialize the language and as such it needs to be treated as an execution
1 parent 29ebc01 commit a5258c3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,11 +795,15 @@ public Value eval(Source source) throws IOException {
795795
* @return the global object or <code>null</code> if the language does not support such
796796
* concept
797797
*/
798+
@SuppressWarnings("try")
798799
public Value getGlobalObject() {
799800
checkThread();
800-
801-
Object res = SPI.languageGlobal(getEnv(true));
802-
return res == null ? null : new Value(new TruffleLanguage[]{info.getImpl(true)}, res);
801+
try (Closeable d = SPI.executionStart(PolyglotEngine.this, -1, debugger, null)) {
802+
Object res = SPI.languageGlobal(getEnv(true));
803+
return res == null ? null : new Value(new TruffleLanguage[]{info.getImpl(true)}, res);
804+
} catch (IOException ex) {
805+
throw new IllegalStateException(ex);
806+
}
803807
}
804808

805809
TruffleLanguage<?> getImpl(boolean create) {

truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLPolyglotTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@
4444

4545
import com.oracle.truffle.api.vm.PolyglotEngine;
4646
import com.oracle.truffle.api.vm.PolyglotEngine.Language;
47+
import java.io.IOException;
48+
import static org.junit.Assert.assertNotNull;
4749

4850
public class SLPolyglotTest {
4951
@Test
50-
public void accessGlobalObject() {
52+
public void accessGlobalObject() throws IOException {
5153
PolyglotEngine vm = PolyglotEngine.newBuilder().build();
5254
Language lang = vm.getLanguages().get("application/x-sl");
53-
lang.getGlobalObject();
55+
PolyglotEngine.Value global = lang.getGlobalObject();
56+
Object globalValue = global.get();
57+
assertNotNull("There is global context in SL", globalValue);
5458
}
5559
}

0 commit comments

Comments
 (0)