JS backend: fix KT-6112 jsonFromTuples is broken

#KT-6112 Fixed
This commit is contained in:
Michael Nedzelsky
2014-12-18 15:52:13 +03:00
parent 0abf56c9ac
commit 8074ab27ea
4 changed files with 47 additions and 15 deletions
+7 -5
View File
@@ -5,11 +5,13 @@ native public class Json() {
public fun set(propertyName: String, value: Any?): Unit = noImpl
}
library("jsonFromTuples")
public fun json(vararg pairs: Pair<String, Any?>): Json = noImpl
library("jsonFromTuples")
public fun json2(pairs: Array<Pair<String, Any?>>): Json = noImpl
public fun json(vararg pairs: Pair<String, Any?>): Json {
var res: dynamic = js("({})")
for((name, value) in pairs) {
res[name] = value
}
return res
}
library("jsonAddProperties")
public fun Json.add(other: Json): Json = noImpl
+14
View File
@@ -0,0 +1,14 @@
package test.js
import kotlin.test.*
import org.junit.Test as test
class JsonTest {
test fun createJsonFromPairs() {
var obj = json(Pair("firstName", "John"), Pair("lastName", "Doe"), Pair("age", 30))
assertEquals("John", obj["firstName"], "firstName")
assertEquals("Doe", obj["lastName"], "lastName")
assertEquals(30, obj["age"], "age")
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* 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.jetbrains.k2js.test.semantics;
import junit.framework.Test;
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class JsonTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("js/js.libraries/test/core/JsonTest.kt");
}
}
-10
View File
@@ -955,16 +955,6 @@
return new Kotlin.ArrayIterator(array);
};
Kotlin.jsonFromTuples = function (pairArr) {
var i = pairArr.length;
var res = {};
while (i > 0) {
--i;
res[pairArr[i][0]] = pairArr[i][1];
}
return res;
};
Kotlin.jsonAddProperties = function (obj1, obj2) {
for (var p in obj2) {
if (obj2.hasOwnProperty(p)) {