From 52dd9a1665dff11d76787a40f004785cf19497b6 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sun, 8 May 2022 18:53:45 +0200 Subject: [PATCH] use "java/lang/Object" as fallback type for NULL values --- .../module/JavaMethodWasmCodeBuilder.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java index ec28cbf..5eb89d8 100644 --- a/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java @@ -967,23 +967,30 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder { int size = instructions.size(); for( int i = 0; i < size; i++ ) { WasmInstruction instr = instructions.get( i ); - if( instr.getType() == Type.Struct ) { - WasmStructInstruction structInst = (WasmStructInstruction)instr; - if( structInst.getOperator() == StructOperator.NULL ) { - int count = 0; - for( int s = i + 1; s < size; s++ ) { - WasmInstruction nextInstr = instructions.get( s ); - count -= nextInstr.getPopCount(); - if( count < 0 ) { - AnyType[] popValueTypes = nextInstr.getPopValueTypes(); - structInst.setStructType( (StructType)popValueTypes[-1 - count] ); - break; - } - if( nextInstr.getPushValueType() != null ) { - count++; + try { + if( instr.getType() == Type.Struct ) { + WasmStructInstruction structInst = (WasmStructInstruction)instr; + if( structInst.getOperator() == StructOperator.NULL ) { + int count = 0; + for( int s = i + 1; s < size; s++ ) { + WasmInstruction nextInstr = instructions.get( s ); + count -= nextInstr.getPopCount(); + if( count < 0 ) { + AnyType[] popValueTypes = nextInstr.getPopValueTypes(); + AnyType type = popValueTypes[-1 - count]; + // is the fallback to java/lang/Object right? There can also be a NULL value for external. + StructType structType = type instanceof StructType ? (StructType)type : getTypeManager().valueOf( "java/lang/Object" ); + structInst.setStructType( structType ); + break; + } + if( nextInstr.getPushValueType() != null ) { + count++; + } } } } + } catch( Exception ex ) { + throw WasmException.create( ex, instr.getLineNumber() ); } } }