From a7234c68e11e9672d0a17c24e5fc3cd36e569a0d Mon Sep 17 00:00:00 2001 From: Tomas Zezula Date: Thu, 21 Jul 2022 18:10:57 +0200 Subject: [PATCH] [GR-40012] Source#path is not transferred to the Truffle isolate. --- .../src/org/graalvm/polyglot/Engine.java | 2 +- .../src/org/graalvm/polyglot/Source.java | 2 +- .../src/org/graalvm/polyglot/impl/AbstractPolyglotImpl.java | 4 ++-- .../src/com/oracle/truffle/api/impl/Accessor.java | 2 ++ .../src/com/oracle/truffle/api/source/Source.java | 4 ++++ .../src/com/oracle/truffle/api/source/SourceAccessor.java | 5 +++++ .../src/com/oracle/truffle/polyglot/PolyglotImpl.java | 5 ++++- 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Engine.java b/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Engine.java index 05a524dcc88..3959184602a 100644 --- a/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Engine.java +++ b/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Engine.java @@ -1055,7 +1055,7 @@ public Object newTargetTypeMapping(Class sourceType, Class targetTy } @Override - public Source build(String language, Object origin, URI uri, String name, String mimeType, Object content, boolean interactive, boolean internal, boolean cached, Charset encoding) + public Source build(String language, Object origin, URI uri, String name, String mimeType, Object content, boolean interactive, boolean internal, boolean cached, Charset encoding, String path) throws IOException { throw noPolyglotImplementationFound(); } diff --git a/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Source.java b/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Source.java index a6605abf3e2..0c8ebf16bca 100644 --- a/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Source.java +++ b/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/Source.java @@ -917,7 +917,7 @@ public Builder encoding(Charset encoding) { * @since 19.0 */ public Source build() throws IOException { - Source source = getImpl().build(language, origin, uri, name, mimeType, content, interactive, internal, cached, fileEncoding); + Source source = getImpl().build(language, origin, uri, name, mimeType, content, interactive, internal, cached, fileEncoding, null); // make sure origin is not consumed again if builder is used twice if (source.hasBytes()) { diff --git a/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/impl/AbstractPolyglotImpl.java b/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/impl/AbstractPolyglotImpl.java index 9642967a606..575d51c45a4 100644 --- a/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/impl/AbstractPolyglotImpl.java +++ b/sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/impl/AbstractPolyglotImpl.java @@ -338,9 +338,9 @@ public void resetPreInitializedEngine() { getNext().resetPreInitializedEngine(); } - public Source build(String language, Object origin, URI uri, String name, String mimeType, Object content, boolean interactive, boolean internal, boolean cached, Charset encoding) + public Source build(String language, Object origin, URI uri, String name, String mimeType, Object content, boolean interactive, boolean internal, boolean cached, Charset encoding, String path) throws IOException { - return getNext().build(language, origin, uri, name, mimeType, content, interactive, internal, cached, encoding); + return getNext().build(language, origin, uri, name, mimeType, content, interactive, internal, cached, encoding, path); } public String findLanguage(File file) throws IOException { diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java index cabafaed5e3..d5bbf1a6ecd 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java @@ -228,6 +228,8 @@ public abstract org.graalvm.polyglot.Source getOrCreatePolyglotSource(Source sou public abstract void mergeLoadedSources(Source[] sources); public abstract void setEmbedderSource(SourceBuilder builder, boolean b); + + public abstract void setPath(SourceBuilder builder, String path); } public abstract static class InteropSupport extends Support { diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java index 75247b3601c..0a9babd3922 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java @@ -1531,6 +1531,10 @@ void embedderSource(boolean b) { this.embedderSource = b; } + void path(String path) { + this.path = path; + } + /** * Uses configuration of this builder to create new {@link Source} object. The method throws * an {@link IOException} if an error loading the source occurred. diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceAccessor.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceAccessor.java index 702fdd811c1..7927e260354 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceAccessor.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceAccessor.java @@ -149,6 +149,11 @@ public void setEmbedderSource(SourceBuilder builder, boolean enabled) { builder.embedderSource(enabled); } + @Override + public void setPath(SourceBuilder builder, String path) { + builder.path(path); + } + @Override public void invalidateAfterPreinitialiation(Source source) { ((SourceImpl) source).key.invalidateAfterPreinitialiation(); diff --git a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotImpl.java b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotImpl.java index 83230dea7f1..1d9f450c94d 100644 --- a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotImpl.java +++ b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotImpl.java @@ -542,7 +542,7 @@ public String findLanguage(String mimeType) { @Override public org.graalvm.polyglot.Source build(String language, Object origin, URI uri, String name, String mimeType, Object content, boolean interactive, boolean internal, boolean cached, - Charset encoding) + Charset encoding, String path) throws IOException { assert language != null; com.oracle.truffle.api.source.Source.SourceBuilder builder; @@ -567,6 +567,9 @@ public org.graalvm.polyglot.Source build(String language, Object origin, URI uri } EngineAccessor.SOURCE.setEmbedderSource(builder, true); + if (path != null) { + EngineAccessor.SOURCE.setPath(builder, path); + } if (content instanceof CharSequence) { builder.content((CharSequence) content);