use valid JavaScript names for the JavaScriplt creator functions

This commit is contained in:
Volker Berlin 2020-01-05 21:41:19 +01:00
parent 6fa864b9fc
commit 783d22fa50

View File

@ -108,17 +108,26 @@ class WasmStructInstruction extends WasmInstruction {
break; break;
case SET: case SET:
AnyType fieldType = fieldName.getType(); 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; break;
case GET: case GET:
fieldType = fieldName.getType(); 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; break;
default: default:
} }
return functionName; 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 * Get the StructOperator
* *