From be53236d2323abafa5d83174a01f8dbc59e7fde8 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 20 Nov 2023 20:33:47 +0100 Subject: [PATCH] JS: fix wrapping keys for native indexers --- .../org/teavm/jso/impl/JSClassProcessor.java | 2 +- .../org/teavm/jso/test/ImportClassTest.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/src/test/java/org/teavm/jso/test/ImportClassTest.java diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index dfe30361f..b7787ad97 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -631,7 +631,7 @@ class JSClassProcessor { } if (isProperSetIndexer(method.getDescriptor())) { var index = invoke.getArguments().get(0); - marshaller.wrapArgument(callLocation, index, method.parameterType(0), types.typeOf(index), false); + index = marshaller.wrapArgument(callLocation, index, method.parameterType(0), types.typeOf(index), false); var value = invoke.getArguments().get(1); value = marshaller.wrapArgument(callLocation, value, method.parameterType(1), types.typeOf(value), false); diff --git a/tests/src/test/java/org/teavm/jso/test/ImportClassTest.java b/tests/src/test/java/org/teavm/jso/test/ImportClassTest.java new file mode 100644 index 000000000..73ee8efc7 --- /dev/null +++ b/tests/src/test/java/org/teavm/jso/test/ImportClassTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2023 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.test; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.teavm.jso.JSBody; +import org.teavm.jso.JSIndexer; +import org.teavm.jso.JSObject; +import org.teavm.junit.EachTestCompiledSeparately; +import org.teavm.junit.OnlyPlatform; +import org.teavm.junit.SkipJVM; +import org.teavm.junit.TeaVMTestRunner; +import org.teavm.junit.TestPlatform; + +@RunWith(TeaVMTestRunner.class) +@SkipJVM +@OnlyPlatform(TestPlatform.JAVASCRIPT) +@EachTestCompiledSeparately +public class ImportClassTest { + @Test + public void indexer() { + var o = create(); + o.set("foo", 23); + set(o, "bar", 42); + assertEquals(23, o.get("foo")); + assertEquals(42, o.get("bar")); + } + + @JSBody(script = "return {};") + private static native O create(); + + @JSBody(params = { "o", "key", "value" }, script = "o[key] = value;") + private static native void set(O o, String key, int value); + + interface O extends JSObject { + @JSIndexer + int get(String key); + + @JSIndexer + void set(String key, int value); + } +}