Skip to content

Commit

Permalink
JS. Remove redundant asDynamic() usages (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
turansky committed Dec 2, 2024
1 parent 7989ad3 commit 85d31ce
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
25 changes: 17 additions & 8 deletions kotlin-js/src/jsMain/kotlin/js/function/JsFunction.invoke.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
package js.function

import js.array.*
import js.reflect.unsafeCast

inline operator fun <R> JsFunction<JsTuple, R>.invoke(): R =
asDynamic()()
unsafeCast<UnsafeInvoker<R>>(this)
.invoke()

inline operator fun <P1, R> JsFunction<JsTuple1<P1>, R>.invoke(
p1: P1,
): R =
asDynamic()(p1)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1)

inline operator fun <P1, P2, R> JsFunction<JsTuple2<P1, P2>, R>.invoke(
p1: P1,
p2: P2,
): R =
asDynamic()(p1, p2)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1, p2)

inline operator fun <P1, P2, P3, R> JsFunction<JsTuple3<P1, P2, P3>, R>.invoke(
p1: P1,
p2: P2,
p3: P3,
): R =
asDynamic()(p1, p2, p3)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1, p2, p3)

inline operator fun <P1, P2, P3, P4, R> JsFunction<JsTuple4<P1, P2, P3, P4>, R>.invoke(
p1: P1,
p2: P2,
p3: P3,
p4: P4,
): R =
asDynamic()(p1, p2, p3, p4)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1, p2, p3, p4)

inline operator fun <P1, P2, P3, P4, P5, R> JsFunction<JsTuple5<P1, P2, P3, P4, P5>, R>.invoke(
p1: P1,
Expand All @@ -38,7 +44,8 @@ inline operator fun <P1, P2, P3, P4, P5, R> JsFunction<JsTuple5<P1, P2, P3, P4,
p4: P4,
p5: P5,
): R =
asDynamic()(p1, p2, p3, p4, p5)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1, p2, p3, p4, p5)

inline operator fun <P1, P2, P3, P4, P5, P6, R> JsFunction<JsTuple6<P1, P2, P3, P4, P5, P6>, R>.invoke(
p1: P1,
Expand All @@ -48,7 +55,8 @@ inline operator fun <P1, P2, P3, P4, P5, P6, R> JsFunction<JsTuple6<P1, P2, P3,
p5: P5,
p6: P6,
): R =
asDynamic()(p1, p2, p3, p4, p5, p6)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1, p2, p3, p4, p5, p6)

inline operator fun <P1, P2, P3, P4, P5, P6, P7, R> JsFunction<JsTuple7<P1, P2, P3, P4, P5, P6, P7>, R>.invoke(
p1: P1,
Expand All @@ -59,4 +67,5 @@ inline operator fun <P1, P2, P3, P4, P5, P6, P7, R> JsFunction<JsTuple7<P1, P2,
p6: P6,
p7: P7,
): R =
asDynamic()(p1, p2, p3, p4, p5, p6, p7)
unsafeCast<UnsafeInvoker<R>>(this)
.invoke(p1, p2, p3, p4, p5, p6, p7)
65 changes: 65 additions & 0 deletions kotlin-js/src/jsMain/kotlin/js/function/UnsafeInvoker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package js.function

import seskar.js.JsNative

@PublishedApi
internal interface UnsafeInvoker<out R> {
@JsNative
fun invoke(): R

@JsNative
fun invoke(
p1: Any?,
): R

@JsNative
fun invoke(
p1: Any?,
p2: Any?,
): R

@JsNative
fun invoke(
p1: Any?,
p2: Any?,
p3: Any?,
): R

@JsNative
fun invoke(
p1: Any?,
p2: Any?,
p3: Any?,
p4: Any?,
): R

@JsNative
fun invoke(
p1: Any?,
p2: Any?,
p3: Any?,
p4: Any?,
p5: Any?,
): R

@JsNative
fun invoke(
p1: Any?,
p2: Any?,
p3: Any?,
p4: Any?,
p5: Any?,
p6: Any?,
): R

@JsNative
fun invoke(
p1: Any?,
p2: Any?,
p3: Any?,
p4: Any?,
p5: Any?,
p6: Any?,
p7: Any?,
): R
}

0 comments on commit 85d31ce

Please sign in to comment.