diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JS.java b/jso/impl/src/main/java/org/teavm/jso/impl/JS.java index 19c20b920..0b94c1b8c 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JS.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JS.java @@ -85,6 +85,9 @@ final class JS { public static native String unwrapString(JSObject value); public static JSArray wrap(T[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, array[i]); @@ -97,6 +100,9 @@ final class JS { } public static JSArray map(S[] array, Function f) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, f.apply(array[i])); @@ -109,6 +115,9 @@ final class JS { } public static JSArray wrap(boolean[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSBoolean.valueOf(array[i])); @@ -121,6 +130,9 @@ final class JS { } public static JSArray wrap(byte[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSNumber.valueOf(array[i])); @@ -133,6 +145,9 @@ final class JS { } public static JSArray wrap(short[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSNumber.valueOf(array[i])); @@ -145,6 +160,9 @@ final class JS { } public static JSArray wrap(char[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSNumber.valueOf(array[i])); @@ -157,6 +175,9 @@ final class JS { } public static JSArray wrap(int[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSNumber.valueOf(array[i])); @@ -169,6 +190,9 @@ final class JS { } public static JSArray wrap(String[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSString.valueOf(array[i])); @@ -181,6 +205,9 @@ final class JS { } public static JSArray wrap(float[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSNumber.valueOf(array[i])); @@ -193,6 +220,9 @@ final class JS { } public static JSArray wrap(double[] array) { + if (array == null) { + return null; + } JSArray result = JSArray.create(array.length); for (int i = 0; i < array.length; ++i) { result.set(i, JSNumber.valueOf(array[i])); @@ -205,6 +235,9 @@ final class JS { } public static T[] unwrapArray(Class type, JSArrayReader array) { + if (array == null) { + return null; + } @SuppressWarnings("unchecked") T[] result = (T[]) Array.newInstance(type, array.getLength()); for (int i = 0; i < result.length; ++i) { @@ -218,6 +251,9 @@ final class JS { } public static T[] unmapArray(Class type, JSArrayReader array, Function f) { + if (array == null) { + return null; + } @SuppressWarnings("unchecked") T[] result = (T[]) Array.newInstance(type, array.getLength()); for (int i = 0; i < result.length; ++i) { @@ -231,6 +267,9 @@ final class JS { } public static boolean[] unwrapBooleanArray(JSArrayReader array) { + if (array == null) { + return null; + } boolean[] result = new boolean[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).booleanValue(); @@ -243,6 +282,9 @@ final class JS { } public static byte[] unwrapByteArray(JSArrayReader array) { + if (array == null) { + return null; + } byte[] result = new byte[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).byteValue(); @@ -255,6 +297,9 @@ final class JS { } public static short[] unwrapShortArray(JSArrayReader array) { + if (array == null) { + return null; + } short[] result = new short[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).shortValue(); @@ -267,6 +312,9 @@ final class JS { } public static int[] unwrapIntArray(JSArrayReader array) { + if (array == null) { + return null; + } int[] result = new int[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).intValue(); @@ -279,6 +327,9 @@ final class JS { } public static char[] unwrapCharArray(JSArrayReader array) { + if (array == null) { + return null; + } char[] result = new char[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).charValue(); @@ -291,6 +342,9 @@ final class JS { } public static float[] unwrapFloatArray(JSArrayReader array) { + if (array == null) { + return null; + } float[] result = new float[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).floatValue(); @@ -303,6 +357,9 @@ final class JS { } public static double[] unwrapDoubleArray(JSArrayReader array) { + if (array == null) { + return null; + } double[] result = new double[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).doubleValue(); @@ -315,6 +372,9 @@ final class JS { } public static String[] unwrapStringArray(JSArrayReader array) { + if (array == null) { + return null; + } String[] result = new String[array.getLength()]; for (int i = 0; i < result.length; ++i) { result[i] = array.get(i).stringValue();