diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt index ef92f393435..5447fba6df6 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt @@ -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: diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java index 1cdc1d47b22..f521ed0a533 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java @@ -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) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 0863dfbeec2..45f66e76caf 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -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) diff --git a/js/js.translator/testData/box/intrinsics/typeof.js b/js/js.translator/testData/box/intrinsics/typeof.js new file mode 100644 index 00000000000..6802269e2d8 --- /dev/null +++ b/js/js.translator/testData/box/intrinsics/typeof.js @@ -0,0 +1 @@ +var definedVariableX = 10; \ No newline at end of file diff --git a/js/js.translator/testData/box/intrinsics/typeof.kt b/js/js.translator/testData/box/intrinsics/typeof.kt new file mode 100644 index 00000000000..5af873d6db2 --- /dev/null +++ b/js/js.translator/testData/box/intrinsics/typeof.kt @@ -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" +} \ No newline at end of file