[JS IR BE] Implement kotlin.js.jsTypeOf as intrinsics
This commit is contained in:
@@ -96,7 +96,7 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
|||||||
// Type checks:
|
// Type checks:
|
||||||
|
|
||||||
val jsInstanceOf = binOpBool("jsInstanceOf")
|
val jsInstanceOf = binOpBool("jsInstanceOf")
|
||||||
val jsTypeOf = unOp("jsTypeOf", irBuiltIns.stringType)
|
val jsTypeOf = getInternalFunction("jsTypeOf")
|
||||||
|
|
||||||
// Number conversions:
|
// Number conversions:
|
||||||
|
|
||||||
|
|||||||
+18
@@ -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")
|
@TestMetadata("js/js.translator/testData/box/java")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+18
@@ -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")
|
@TestMetadata("js/js.translator/testData/box/java")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
var definedVariableX = 10;
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user