diff --git a/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/WasmLanguage.java b/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/WasmLanguage.java
index 2269caf5ed25..0b7e846df38c 100644
--- a/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/WasmLanguage.java
+++ b/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/WasmLanguage.java
@@ -48,7 +48,6 @@
import org.graalvm.options.OptionDescriptors;
import org.graalvm.options.OptionValues;
import org.graalvm.wasm.api.JsConstants;
-import org.graalvm.wasm.api.WasmModuleWithSource;
import org.graalvm.wasm.api.WebAssembly;
import org.graalvm.wasm.exception.WasmJsApiException;
import org.graalvm.wasm.memory.WasmMemory;
@@ -56,7 +55,6 @@
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ContextThreadLocal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.TruffleLanguage;
@@ -141,6 +139,16 @@ private ParsedWasmModuleRootNode(WasmLanguage language, WasmModule module, Sourc
this.source = source;
}
+ /**
+ * The CallTarget returned by {@code parse} supports two calling conventions:
+ *
+ *
+ * - (default) zero arguments provided: on the first call, instantiates the decoded module
+ * and puts it in the context's module instance map; then returns the {@link WasmInstance}.
+ *
- first argument is {@code "module_decode"}: returns the decoded {@link WasmModule}
+ * (i.e. behaves like {@link WebAssembly#moduleDecode module_decode}). Used by the JS API.
+ *
+ */
@Override
public Object execute(VirtualFrame frame) {
if (frame.getArguments().length == 0) {
@@ -153,7 +161,7 @@ public Object execute(VirtualFrame frame) {
} else {
if (frame.getArguments()[0] instanceof String mode) {
if (mode.equals(MODULE_DECODE)) {
- return moduleDecode();
+ return module;
} else {
throw WasmJsApiException.format(WasmJsApiException.Kind.TypeError, "Unsupported first argument: '%s'", mode);
}
@@ -163,21 +171,6 @@ public Object execute(VirtualFrame frame) {
}
}
- @TruffleBoundary
- private Object moduleDecode() {
- /*
- * Get the source used for parsing on the JS side and associate it with the returned
- * WasmModule, so that it will be kept alive with the JS WebAssembly.Module object.
- */
- Source sourceHandle = getParsingSource();
- return new WasmModuleWithSource(module, sourceHandle);
- }
-
- @TruffleBoundary
- private Source getParsingSource() {
- return Source.newBuilder(source).build();
- }
-
@Override
public SourceSection getSourceSection() {
return source.createUnavailableSection();
diff --git a/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/WebAssembly.java b/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/WebAssembly.java
index 73245ad7586c..2c36798d2216 100644
--- a/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/WebAssembly.java
+++ b/wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/WebAssembly.java
@@ -332,6 +332,11 @@ private static WasmJsApiException cannotConvertToBytesError(Throwable cause) {
return (cause == null) ? new WasmJsApiException(kind, message) : new WasmJsApiException(kind, message, cause);
}
+ /**
+ * Extract a {@link WasmModule} from argument 0. The argument may be a {@link WasmModule} or a
+ * {@link WasmModuleWithSource} as produced by the CallTarget returned from Env.parse or
+ * {@link #moduleDecode}, respectively.
+ */
private static WasmModule toModule(Object[] args) {
checkArgumentCount(args, 1);
Object arg0 = args[0];