From 783d22fa50a9a4486be8d976d58bc92d22673452 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sun, 5 Jan 2020 21:41:19 +0100 Subject: [PATCH] use valid JavaScript names for the JavaScriplt creator functions --- .../jwebassembly/module/WasmStructInstruction.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java index 9ad9c03..ade3a6c 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java @@ -108,17 +108,26 @@ class WasmStructInstruction extends WasmInstruction { break; case SET: AnyType fieldType = fieldName.getType(); - functionName = new JavaScriptSyntheticFunctionName( "NonGC", "set_" + fieldType, () -> "(a,v,i) => a[i]=v", ValueType.anyref, fieldType, ValueType.i32, null, null ); + functionName = new JavaScriptSyntheticFunctionName( "NonGC", "set_" + validJsName( fieldType ), () -> "(a,v,i) => a[i]=v", ValueType.anyref, fieldType, ValueType.i32, null, null ); break; case GET: fieldType = fieldName.getType(); - functionName = new JavaScriptSyntheticFunctionName( "NonGC", "get_" + fieldType, () -> "(a,i) => a[i]", ValueType.anyref, ValueType.i32, null, fieldType ); + functionName = new JavaScriptSyntheticFunctionName( "NonGC", "get_" + validJsName( fieldType ), () -> "(a,i) => a[i]", ValueType.anyref, ValueType.i32, null, fieldType ); break; default: } return functionName; } + /** + * Get a valid JavaScript name. + * @param type the type + * @return the identifier that is valid + */ + private static String validJsName( AnyType type ) { + return type instanceof StructType ? "anyref" : type.toString(); + } + /** * Get the StructOperator *