diff --git a/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java b/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java index c48478c..0136ccd 100644 --- a/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java +++ b/src/de/inetsoftware/jwebassembly/module/nativecode/ReplacementForClass.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Volker Berlin (i-net software) + Copyright 2020 - 2021 Volker Berlin (i-net software) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import de.inetsoftware.jwebassembly.module.TypeManager; /** * Replacement for java.lang.Class * + * @param the type of the class modeled by this {@code Class} * @author Volker Berlin */ @Replace( "java/lang/Class" ) @@ -59,15 +60,6 @@ class ReplacementForClass { this.vtable = vtable; } - /** - * Replacement for {@link Class#getName()} - * - * @return the name - */ - public String getName() { - return StringTable.stringConstant( getIntFromMemory( vtable + TYPE_DESCRIPTION_TYPE_NAME ) ); - } - /** * Replacement for {@link Object#getClass()}. The documentation of the memory of the type description is done in method: * {@link TypeManager.StructType#writeToStream(java.io.ByteArrayOutputStream, java.util.function.ToIntFunction)} @@ -179,6 +171,24 @@ class ReplacementForClass { "return" ) private static native int getIntFromMemory( int pos ); + /** + * Replacement of the Java methods isArray() + * @return {@code true} if this object represents an array class; + */ + public boolean isArray() { + int classIdx = getIntFromMemory( vtable + TYPE_DESCRIPTION_ARRAY_TYPE ); + return classIdx >= 0; + } + + /** + * Replacement for {@link Class#getName()} + * + * @return the name + */ + public String getName() { + return StringTable.stringConstant( getIntFromMemory( vtable + TYPE_DESCRIPTION_TYPE_NAME ) ); + } + /** * Replacement of the Java methods */ @@ -187,7 +197,7 @@ class ReplacementForClass { } /** - * Replacement of the Java methods + * Replacement of the Java methods getClassLoader0() */ ClassLoader getClassLoader0() { return null; diff --git a/test/de/inetsoftware/jwebassembly/runtime/ArrayOperations.java b/test/de/inetsoftware/jwebassembly/runtime/ArrayOperations.java index 3a0f652..c9f29b5 100644 --- a/test/de/inetsoftware/jwebassembly/runtime/ArrayOperations.java +++ b/test/de/inetsoftware/jwebassembly/runtime/ArrayOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2019 Volker Berlin (i-net software) + * Copyright 2018 - 2021 Volker Berlin (i-net software) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,6 +85,8 @@ public class ArrayOperations extends AbstractBaseTest { addParam( list, script, "booleanArrayComponentTypeClassName" ); addParam( list, script, "objectArrayComponentTypeClassName" ); addParam( list, script, "arrayNewInstance_getLength" ); + addParam( list, script, "isArrayOfArray" ); + addParam( list, script, "isArrayOfObject" ); } rule.setTestParameters( list ); return list; @@ -328,5 +330,19 @@ public class ArrayOperations extends AbstractBaseTest { Object obj = Array.newInstance( byte.class, 42 ); return Array.getLength( obj ); } + + @Export + static boolean isArrayOfArray() { + Object obj = new Object[42]; + Class clazz = obj.getClass(); + return clazz.isArray(); + } + + @Export + static boolean isArrayOfObject() { + Object obj = new Object(); + Class clazz = obj.getClass(); + return clazz.isArray(); + } } }