[JS IR BE] Implement kotlin.js.jsTypeOf as intrinsics

This commit is contained in:
Svyatoslav Kuzmich
2020-02-26 21:39:33 +03:00
parent dff7d7b7b9
commit 3ecee5c7cd
5 changed files with 50 additions and 1 deletions
@@ -96,7 +96,7 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
// Type checks:
val jsInstanceOf = binOpBool("jsInstanceOf")
val jsTypeOf = unOp("jsTypeOf", irBuiltIns.stringType)
val jsTypeOf = getInternalFunction("jsTypeOf")
// Number conversions:
@@ -4649,6 +4649,24 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
}
}
@TestMetadata("js/js.translator/testData/box/intrinsics")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Intrinsics extends AbstractIrBoxJsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInIntrinsics() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/intrinsics"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("typeof.kt")
public void testTypeof() throws Exception {
runTest("js/js.translator/testData/box/intrinsics/typeof.kt");
}
}
@TestMetadata("js/js.translator/testData/box/java")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -4664,6 +4664,24 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
}
}
@TestMetadata("js/js.translator/testData/box/intrinsics")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Intrinsics extends AbstractBoxJsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInIntrinsics() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/intrinsics"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("typeof.kt")
public void testTypeof() throws Exception {
runTest("js/js.translator/testData/box/intrinsics/typeof.kt");
}
}
@TestMetadata("js/js.translator/testData/box/java")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
+1
View File
@@ -0,0 +1 @@
var definedVariableX = 10;
+12
View File
@@ -0,0 +1,12 @@
// EXPECTED_REACHABLE_NODES: 1303
external val definedVariableX: Int
external val undefinedVariableX: Int
fun box(): String {
if (jsTypeOf(definedVariableX) != "number") return "Fail 1"
if (jsTypeOf(js("definedVariableX")) != "number") return "Fail 2"
if (jsTypeOf(undefinedVariableX) != "undefined") return "Fail 3"
if (jsTypeOf(js("undefinedVariableX")) != "undefined") return "Fail 4"
return "OK"
}