Skip to content

Commit

Permalink
Drop exception handler in for tag to reduce bytecode size (#224)
Browse files Browse the repository at this point in the history
* Drop deprecated targets

* Test dropping exception handling
  • Loading branch information
e5l committed Jun 14, 2023
1 parent 003ca00 commit f1ca2c6
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 224 deletions.
14 changes: 0 additions & 14 deletions api/kotlinx-html.api
Expand Up @@ -3003,15 +3003,10 @@ public abstract interface class kotlinx/html/TagConsumer {
public abstract fun onTagContentEntity (Lkotlinx/html/Entities;)V
public abstract fun onTagContentUnsafe (Lkotlin/jvm/functions/Function1;)V
public abstract fun onTagEnd (Lkotlinx/html/Tag;)V
public abstract fun onTagError (Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
public abstract fun onTagEvent (Lkotlinx/html/Tag;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public abstract fun onTagStart (Lkotlinx/html/Tag;)V
}

public final class kotlinx/html/TagConsumer$DefaultImpls {
public static fun onTagError (Lkotlinx/html/TagConsumer;Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
}

public final class kotlinx/html/TextAreaWrap : java/lang/Enum, kotlinx/html/AttributeEnum {
public static final field hard Lkotlinx/html/TextAreaWrap;
public static final field soft Lkotlinx/html/TextAreaWrap;
Expand Down Expand Up @@ -3205,7 +3200,6 @@ public final class kotlinx/html/consumers/DelayedConsumer : kotlinx/html/TagCons
public fun onTagContentEntity (Lkotlinx/html/Entities;)V
public fun onTagContentUnsafe (Lkotlin/jvm/functions/Function1;)V
public fun onTagEnd (Lkotlinx/html/Tag;)V
public fun onTagError (Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
public fun onTagEvent (Lkotlinx/html/Tag;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public fun onTagStart (Lkotlinx/html/Tag;)V
}
Expand All @@ -3214,10 +3208,6 @@ public final class kotlinx/html/consumers/Delayed_consumerKt {
public static final fun delayed (Lkotlinx/html/TagConsumer;)Lkotlinx/html/TagConsumer;
}

public final class kotlinx/html/consumers/Exception_consumerKt {
public static final fun catch (Lkotlinx/html/TagConsumer;Lkotlin/jvm/functions/Function2;)Lkotlinx/html/TagConsumer;
}

public final class kotlinx/html/consumers/Filter_consumerKt {
public static final fun filter (Lkotlinx/html/TagConsumer;Lkotlin/jvm/functions/Function2;)Lkotlinx/html/TagConsumer;
}
Expand All @@ -3233,7 +3223,6 @@ public final class kotlinx/html/consumers/FinalizeConsumer : kotlinx/html/TagCon
public fun onTagContentEntity (Lkotlinx/html/Entities;)V
public fun onTagContentUnsafe (Lkotlin/jvm/functions/Function1;)V
public fun onTagEnd (Lkotlinx/html/Tag;)V
public fun onTagError (Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
public fun onTagEvent (Lkotlinx/html/Tag;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public fun onTagStart (Lkotlinx/html/Tag;)V
}
Expand Down Expand Up @@ -3287,7 +3276,6 @@ public final class kotlinx/html/consumers/TraceConsumer : kotlinx/html/TagConsum
public fun onTagContentEntity (Lkotlinx/html/Entities;)V
public fun onTagContentUnsafe (Lkotlin/jvm/functions/Function1;)V
public fun onTagEnd (Lkotlinx/html/Tag;)V
public fun onTagError (Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
public fun onTagEvent (Lkotlinx/html/Tag;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public fun onTagStart (Lkotlinx/html/Tag;)V
}
Expand Down Expand Up @@ -3330,7 +3318,6 @@ public final class kotlinx/html/dom/HTMLDOMBuilder : kotlinx/html/TagConsumer {
public fun onTagContentEntity (Lkotlinx/html/Entities;)V
public fun onTagContentUnsafe (Lkotlin/jvm/functions/Function1;)V
public fun onTagEnd (Lkotlinx/html/Tag;)V
public fun onTagError (Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
public fun onTagEvent (Lkotlinx/html/Tag;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public fun onTagStart (Lkotlinx/html/Tag;)V
}
Expand Down Expand Up @@ -3383,7 +3370,6 @@ public final class kotlinx/html/stream/HTMLStreamBuilder : kotlinx/html/TagConsu
public fun onTagContentEntity (Lkotlinx/html/Entities;)V
public fun onTagContentUnsafe (Lkotlin/jvm/functions/Function1;)V
public fun onTagEnd (Lkotlinx/html/Tag;)V
public fun onTagError (Lkotlinx/html/Tag;Ljava/lang/Throwable;)V
public fun onTagEvent (Lkotlinx/html/Tag;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public fun onTagStart (Lkotlinx/html/Tag;)V
}
Expand Down
63 changes: 4 additions & 59 deletions build.gradle.kts
Expand Up @@ -68,70 +68,29 @@ publishing {
}
}
}

create<MavenPublication>("kotlinx-html-assembly") {
artifactId = "kotlinx-html-assembly"
jar("jsWebJar") {
archiveBaseName by "${project.name}-assembly"
archiveClassifier by "webjar"
from("$buildDir/js/packages/${project.name}/kotlin/kotlinx-html-js.js")
into("META-INF/resources/webjars/${project.name}/${project.version}/")
}
}
}
}

repositories {
mavenCentral()
}



kotlin {
jvm {
mavenPublication {
groupId = group as String
pom { name by "${project.name}-jvm" }

javadocJar("jvmJavadocJar")
jar("jvmTestSourcesJar") {
archiveClassifier by "test-sources"
with(sourceSets["jvmTest"]) {
from(kotlin, resources)
}
}
}
}
js(BOTH) {
js(IR) {
moduleName = project.name

compilations["main"].packageJson {
main = "kotlin/kotlinx-html-js.js"
name = "kotlinx-html-js"
}

compilations["main"].kotlinOptions.apply {
outputFile = "$buildDir/js/packages/${project.name}/kotlin/${project.name}-js.js"
moduleKind = "umd"
sourceMap = true
sourceMapEmbedSources = "always"
}

compilations["test"].kotlinOptions.apply {
moduleKind = "umd"
metaInfo = true
sourceMap = true
}
browser()

mavenPublication {
groupId = group as String
pom { name by "${project.name}-js" }

javadocJar("jsJavadocJar")
jar("jsTestSourcesJar") {
archiveClassifier by "test-sources"
with(sourceSets["jsTest"]) {
from(kotlin, resources)
}
}
}
}

Expand All @@ -140,9 +99,7 @@ kotlin {
linuxArm64()
iosX64()
iosArm64()
iosArm32()
iosSimulatorArm64()
watchosX86()
watchosX64()
watchosArm32()
watchosArm64()
Expand All @@ -160,11 +117,6 @@ kotlin {
pom {
name by "${project.name}-common"
}

javadocJar("commonJavadocJar")
jar("commonTestSourcesJar") {
archiveClassifier by "test-sources"
}
}
}
}
Expand Down Expand Up @@ -342,13 +294,6 @@ tasks.withType<GenerateModuleMetadata> {
enabled = true
}

fun MavenPublication.jar(taskName: String, config: Action<Jar>) = artifact(tasks.create(taskName, Jar::class, config))

fun MavenPublication.javadocJar(taskName: String, config: Jar.() -> Unit = {}) = jar(taskName) {
archiveClassifier by "javadoc"
config()
}

infix fun <T> Property<T>.by(value: T) {
set(value)
}
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
@@ -1,7 +1,6 @@
# The following property is required to mitigate issue https://github.com/gradle/gradle/issues/11412.
systemProp.org.gradle.internal.publish.checksums.insecure=true
kotlin.code.style=official
kotlin.js.compiler=both

kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.mpp.enableCInteropCommonization=true
Expand Down
1 change: 0 additions & 1 deletion src/commonMain/kotlin/api.kt
Expand Up @@ -11,7 +11,6 @@ interface TagConsumer<out R> {
fun onTagContentEntity(entity: Entities)
fun onTagContentUnsafe(block: Unsafe.() -> Unit)
fun onTagComment(content: CharSequence)
fun onTagError(tag: Tag, exception: Throwable): Unit = throw exception
fun finalize(): R
}

Expand Down
7 changes: 1 addition & 6 deletions src/commonMain/kotlin/delayed-consumer.kt
Expand Up @@ -38,12 +38,7 @@ class DelayedConsumer<T>(val downstream: TagConsumer<T>) : TagConsumer<T> {
downstream.onTagContentEntity(entity)
}

override fun onTagError(tag: Tag, exception: Throwable) {
processDelayedTag()
downstream.onTagError(tag, exception)
}

override fun onTagComment(content: CharSequence) {
override fun onTagComment(content: CharSequence) {
processDelayedTag()
downstream.onTagComment(content)
}
Expand Down
18 changes: 0 additions & 18 deletions src/commonMain/kotlin/exception-consumer.kt

This file was deleted.

6 changes: 0 additions & 6 deletions src/commonMain/kotlin/filter-consumer.kt
Expand Up @@ -74,12 +74,6 @@ private class FilterTagConsumer<T>(val downstream: TagConsumer<T>, val predicate

private fun canPassCurrentLevel() = dropLevel == null && currentLevel !in skippedLevels

override fun onTagError(tag: Tag, exception: Throwable) {
if (canPassCurrentLevel()) {
downstream.onTagError(tag, exception)
}
}

override fun onTagComment(content: CharSequence) {
if (canPassCurrentLevel()) {
downstream.onTagComment(content)
Expand Down
1 change: 0 additions & 1 deletion src/commonMain/kotlin/finalize-consumer.kt
Expand Up @@ -23,7 +23,6 @@ class FinalizeConsumer<F, T>(val downstream: TagConsumer<F>, val block: (F, Bool
override fun onTagContent(content: CharSequence) = downstream.onTagContent(content)
override fun onTagContentEntity(entity: Entities) = downstream.onTagContentEntity(entity)
override fun onTagContentUnsafe(block: Unsafe.() -> Unit) = downstream.onTagContentUnsafe(block)
override fun onTagError(tag: Tag, exception: Throwable) = downstream.onTagError(tag, exception)
override fun onTagComment(content: CharSequence) = downstream.onTagComment(content)

override fun finalize() = block(downstream.finalize(), level > 0)
Expand Down
4 changes: 0 additions & 4 deletions src/commonMain/kotlin/measure-consumer.kt
Expand Up @@ -39,10 +39,6 @@ private class TimeMeasureConsumer<R>(val downstream: TagConsumer<R>) : TagConsum
downstream.onTagContentUnsafe(block)
}

override fun onTagError(tag: Tag, exception: Throwable) {
downstream.onTagError(tag, exception)
}

override fun onTagComment(content: CharSequence) {
downstream.onTagComment(content)
}
Expand Down
6 changes: 0 additions & 6 deletions src/commonMain/kotlin/trace-consumer.kt
Expand Up @@ -26,12 +26,6 @@ class TraceConsumer<R>(val downstream: TagConsumer<R>, val println: (String) ->
println("[$id] ${tag.tagName}.$attribute changed to $value")
}

override fun onTagError(tag: Tag, exception: Throwable) {
println("[$id] exception in ${tag.tagName}: ${exception.message}")

downstream.onTagError(tag, exception)
}

override fun finalize(): R {
val v = downstream.finalize()

Expand Down
9 changes: 2 additions & 7 deletions src/commonMain/kotlin/visit.kt
Expand Up @@ -2,13 +2,8 @@ package kotlinx.html

inline fun <T : Tag> T.visitTag(block: T.() -> Unit) {
consumer.onTagStart(this)
try {
this.block()
} catch (err: Throwable) {
consumer.onTagError(this, err)
} finally {
consumer.onTagEnd(this)
}
this.block()
consumer.onTagEnd(this)
}

inline fun <T : Tag, R> T.visitTagAndFinalize(consumer: TagConsumer<R>, block: T.() -> Unit): R {
Expand Down
36 changes: 0 additions & 36 deletions src/jsTest/kotlin/exceptions.kt

This file was deleted.

65 changes: 0 additions & 65 deletions src/jvmTest/kotlin/exceptions.kt

This file was deleted.

0 comments on commit f1ca2c6

Please sign in to comment.