JS backend: fix KT-6112 jsonFromTuples is broken
#KT-6112 Fixed
This commit is contained in:
@@ -5,11 +5,13 @@ native public class Json() {
|
|||||||
public fun set(propertyName: String, value: Any?): Unit = noImpl
|
public fun set(propertyName: String, value: Any?): Unit = noImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
library("jsonFromTuples")
|
public fun json(vararg pairs: Pair<String, Any?>): Json {
|
||||||
public fun json(vararg pairs: Pair<String, Any?>): Json = noImpl
|
var res: dynamic = js("({})")
|
||||||
|
for((name, value) in pairs) {
|
||||||
library("jsonFromTuples")
|
res[name] = value
|
||||||
public fun json2(pairs: Array<Pair<String, Any?>>): Json = noImpl
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
library("jsonAddProperties")
|
library("jsonAddProperties")
|
||||||
public fun Json.add(other: Json): Json = noImpl
|
public fun Json.add(other: Json): Json = noImpl
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -955,16 +955,6 @@
|
|||||||
return new Kotlin.ArrayIterator(array);
|
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) {
|
Kotlin.jsonAddProperties = function (obj1, obj2) {
|
||||||
for (var p in obj2) {
|
for (var p in obj2) {
|
||||||
if (obj2.hasOwnProperty(p)) {
|
if (obj2.hasOwnProperty(p)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user