diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/TraitTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/TraitTest.java index 6d130220da0..a317aa70042 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/TraitTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/TraitTest.java @@ -62,4 +62,8 @@ public final class TraitTest extends SingleFileTranslationTest { public void testDefinitionOrder() throws Exception { fooBoxTest(); } + + public void testCheckImplementationCharacteristics() throws Exception { + checkFooBoxIsOk(); + } } diff --git a/js/js.translator/testFiles/kotlin_lib_ecma3.js b/js/js.translator/testFiles/kotlin_lib_ecma3.js index 46ba6fd3b44..7891a74313b 100644 --- a/js/js.translator/testFiles/kotlin_lib_ecma3.js +++ b/js/js.translator/testFiles/kotlin_lib_ecma3.js @@ -80,15 +80,14 @@ var Kotlin = {}; return true; }; - Kotlin.createTrait = (function () { - return function () { - var result = arguments[0]; - for (var i = 1, n = arguments.length; i < n; i++) { - copyProperties(result, arguments[i]); - } - return result; + Kotlin.createTrait = function () { + var n = arguments.length - 1; + var result = arguments[n] || {}; + for (var i = 0; i < n; i++) { + copyProperties(result, arguments[i]); } - })(); + return result; + }; Kotlin.definePackage = function (members) { return members === null ? {} : members; diff --git a/js/js.translator/testFiles/trait/cases/checkImplementationCharacteristics.kt b/js/js.translator/testFiles/trait/cases/checkImplementationCharacteristics.kt new file mode 100644 index 00000000000..53e007dd011 --- /dev/null +++ b/js/js.translator/testFiles/trait/cases/checkImplementationCharacteristics.kt @@ -0,0 +1,30 @@ +package foo + +trait A { + fun foo() {} +} +trait B : A { + fun boo() {} +} + +native fun eval(code: String): Any = noImpl +native val undefined: Any = noImpl +native class Function(vararg args: String) + +val hasProp = Function("obj, prop", "return obj[prop] !== undefined") as ((Any, String)->Boolean) +val PREFIX = "Kotlin.modules.JS_TESTS.foo" + +fun box(): String { + val a = object: A {} + val b = object: B {} + + if (!hasProp(a, "foo")) return "A hasn't foo" + if (hasProp(a, "boo")) return "A has boo" + + if (!hasProp(b, "foo")) return "B hasn't foo" + if (!hasProp(b, "boo")) return "B hasn't boo" + + if (eval("$PREFIX.A === $PREFIX.B") as Boolean) return "A and B refer to the same object" + + return "OK" +} \ No newline at end of file