mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Fix NULL values for INSTANCEOF and CAST.
This commit is contained in:
parent
91fafe3d24
commit
710127bb44
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 - 2021 Volker Berlin (i-net software)
|
* Copyright 2017 - 2022 Volker Berlin (i-net software)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -1328,6 +1328,10 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
codeStream.writeVaruint32( i );
|
codeStream.writeVaruint32( i );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case BR_ON_NULL:
|
||||||
|
codeStream.writeOpCode( BR_ON_NULL );
|
||||||
|
codeStream.writeVaruint32( (Integer)data );
|
||||||
|
break;
|
||||||
case LOOP:
|
case LOOP:
|
||||||
codeStream.writeOpCode( LOOP );
|
codeStream.writeOpCode( LOOP );
|
||||||
codeStream.writeValueType( ValueType.empty ); // void; the return type of the loop. currently we does not use it
|
codeStream.writeValueType( ValueType.empty ); // void; the return type of the loop. currently we does not use it
|
||||||
|
@ -514,6 +514,8 @@ public class TypeManager {
|
|||||||
WatCodeSyntheticFunctionName createInstanceOf() {
|
WatCodeSyntheticFunctionName createInstanceOf() {
|
||||||
return new WatCodeSyntheticFunctionName( //
|
return new WatCodeSyntheticFunctionName( //
|
||||||
"instanceof", "local.get 0 " // THIS
|
"instanceof", "local.get 0 " // THIS
|
||||||
|
+ "ref.is_null if i32.const 0 return end " // NULL check
|
||||||
|
+ "local.get 0 " // THIS
|
||||||
+ "struct.get java/lang/Object .vtable " // vtable is on index 0
|
+ "struct.get java/lang/Object .vtable " // vtable is on index 0
|
||||||
+ "local.tee 2 " // save the vtable location
|
+ "local.tee 2 " // save the vtable location
|
||||||
+ "i32.load offset=" + TYPE_DESCRIPTION_INSTANCEOF_OFFSET + " align=4 " // get offset of instanceof inside vtable (int position 1, byte position 4)
|
+ "i32.load offset=" + TYPE_DESCRIPTION_INSTANCEOF_OFFSET + " align=4 " // get offset of instanceof inside vtable (int position 1, byte position 4)
|
||||||
@ -557,11 +559,14 @@ public class TypeManager {
|
|||||||
WatCodeSyntheticFunctionName createCast() {
|
WatCodeSyntheticFunctionName createCast() {
|
||||||
return new WatCodeSyntheticFunctionName( //
|
return new WatCodeSyntheticFunctionName( //
|
||||||
"cast", "local.get 0 " // THIS
|
"cast", "local.get 0 " // THIS
|
||||||
|
+ "ref.is_null if local.get 0 return end " // NULL check
|
||||||
|
+ "local.get 0 " // THIS
|
||||||
+ "local.get 1 " // the class index that we search
|
+ "local.get 1 " // the class index that we search
|
||||||
+ "call $.instanceof()V " // the synthetic signature of ArraySyntheticFunctionName
|
+ "call $.instanceof()V " // the synthetic signature of ArraySyntheticFunctionName
|
||||||
+ "i32.eqz " //
|
+ "if " //
|
||||||
+ "local.get 0 " // THIS
|
+ " local.get 0 " // THIS
|
||||||
+ "return " //
|
+ " return " //
|
||||||
|
+ "end " //
|
||||||
+ "unreachable " // TODO throw a ClassCastException if exception handling is supported
|
+ "unreachable " // TODO throw a ClassCastException if exception handling is supported
|
||||||
, valueOf( "java/lang/Object" ), ValueType.i32, null, valueOf( "java/lang/Object" ) );
|
, valueOf( "java/lang/Object" ), ValueType.i32, null, valueOf( "java/lang/Object" ) );
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 - 2021 Volker Berlin (i-net software)
|
* Copyright 2017 - 2022 Volker Berlin (i-net software)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -834,6 +834,9 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
}
|
}
|
||||||
name = builder.toString();
|
name = builder.toString();
|
||||||
break;
|
break;
|
||||||
|
case BR_ON_NULL:
|
||||||
|
name = "br_on_null " + data;
|
||||||
|
break;
|
||||||
case LOOP:
|
case LOOP:
|
||||||
name = "loop";
|
name = "loop";
|
||||||
insetAfter++;
|
insetAfter++;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 - 2019 Volker Berlin (i-net software)
|
Copyright 2018 - 2022 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -32,6 +32,7 @@ public enum WasmBlockOperator {
|
|||||||
BR,
|
BR,
|
||||||
BR_IF,
|
BR_IF,
|
||||||
BR_TABLE,
|
BR_TABLE,
|
||||||
|
BR_ON_NULL,
|
||||||
LOOP,
|
LOOP,
|
||||||
UNREACHABLE,
|
UNREACHABLE,
|
||||||
TRY,
|
TRY,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 - 2021 Volker Berlin (i-net software)
|
Copyright 2018 - 2022 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -272,6 +272,9 @@ public class WatParser extends WasmCodeBuilder {
|
|||||||
case "br_if":
|
case "br_if":
|
||||||
addBlockInstruction( WasmBlockOperator.BR_IF, getInt( tokens, ++i ), javaCodePos, lineNumber );
|
addBlockInstruction( WasmBlockOperator.BR_IF, getInt( tokens, ++i ), javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
case "br_on_null":
|
||||||
|
addBlockInstruction( WasmBlockOperator.BR_ON_NULL, getInt( tokens, ++i ), javaCodePos, lineNumber );
|
||||||
|
break;
|
||||||
case "throw":
|
case "throw":
|
||||||
addBlockInstruction( WasmBlockOperator.THROW, null, javaCodePos, lineNumber );
|
addBlockInstruction( WasmBlockOperator.THROW, null, javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
|
@ -61,7 +61,9 @@ public class StructsNonGC extends AbstractBaseTest {
|
|||||||
addParam( list, script, "instanceof1" );
|
addParam( list, script, "instanceof1" );
|
||||||
addParam( list, script, "instanceof2" );
|
addParam( list, script, "instanceof2" );
|
||||||
addParam( list, script, "instanceof3" );
|
addParam( list, script, "instanceof3" );
|
||||||
addParam( list, script, "cast" );
|
addParam( list, script, "instanceof4" );
|
||||||
|
addParam( list, script, "cast1" );
|
||||||
|
addParam( list, script, "cast2" );
|
||||||
addParam( list, script, "objectClassName" );
|
addParam( list, script, "objectClassName" );
|
||||||
addParam( list, script, "integerClassName" );
|
addParam( list, script, "integerClassName" );
|
||||||
addParam( list, script, "classClassName" );
|
addParam( list, script, "classClassName" );
|
||||||
@ -197,12 +199,25 @@ public class StructsNonGC extends AbstractBaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Export
|
@Export
|
||||||
static int cast() {
|
static boolean instanceof4() {
|
||||||
|
Object obj = null;
|
||||||
|
return obj instanceof List;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static int cast1() {
|
||||||
Object obj = new Integer(42);
|
Object obj = new Integer(42);
|
||||||
Integer val = (Integer)obj;
|
Integer val = (Integer)obj;
|
||||||
return val.intValue();
|
return val.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static Integer cast2() {
|
||||||
|
Object obj = null;
|
||||||
|
Integer val = (Integer)obj;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
@Export
|
@Export
|
||||||
static DOMString objectClassName() {
|
static DOMString objectClassName() {
|
||||||
Object obj = new Object();
|
Object obj = new Object();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user