diff --git a/js/js.libraries/src/generated/org.w3c.dom.kt b/js/js.libraries/src/generated/org.w3c.dom.kt index a019d857067..e6d87338e55 100644 --- a/js/js.libraries/src/generated/org.w3c.dom.kt +++ b/js/js.libraries/src/generated/org.w3c.dom.kt @@ -4578,7 +4578,7 @@ native public open class DOMPointReadOnly(x: Double, y: Double, z: Double, w: Do } native public open class DOMPoint : DOMPointReadOnly { - constructor(point: DOMPointInit = noImpl) : super(noImpl, noImpl, noImpl, noImpl) + constructor(point: DOMPointInit) : super(noImpl, noImpl, noImpl, noImpl) constructor(x: Double = 0.0, y: Double = 0.0, z: Double = 0.0, w: Double = 1.0) : super(x, y, z, w) override var x: Double get() = noImpl @@ -4644,7 +4644,7 @@ native public open class DOMRectInit { native public open class DOMQuad { constructor(p1: DOMPointInit = noImpl, p2: DOMPointInit = noImpl, p3: DOMPointInit = noImpl, p4: DOMPointInit = noImpl) - constructor(rect: DOMRectInit = noImpl) + constructor(rect: DOMRectInit) open val p1: DOMPoint get() = noImpl open val p2: DOMPoint diff --git a/libraries/tools/idl2k/src/main/kotlin/config.kt b/libraries/tools/idl2k/src/main/kotlin/config.kt index f32dc1cacd9..121303801a2 100644 --- a/libraries/tools/idl2k/src/main/kotlin/config.kt +++ b/libraries/tools/idl2k/src/main/kotlin/config.kt @@ -52,7 +52,7 @@ val relocations = mapOf( "EventListener" to "org.w3c.dom.events" ) -val commentOutDeclarations = listOf( +val commentOutDeclarations = setOf( "MouseEvent.screenX: Double", "MouseEvent.screenY: Double", "MouseEvent.clientX: Double", "MouseEvent.clientY: Double", "MouseEvent.x: Double", "MouseEvent.y: Double", @@ -67,4 +67,9 @@ val commentOutDeclarations = listOf( "HTMLPropertiesCollection.get", "SVGElement.id" -).toSet() +) + +val requiredArguments = setOf( + "DOMPoint.constructor.point", + "DOMQuad.constructor.rect" +) diff --git a/libraries/tools/idl2k/src/main/kotlin/gen.kt b/libraries/tools/idl2k/src/main/kotlin/gen.kt index 83836c8af86..dfd61b5ce79 100644 --- a/libraries/tools/idl2k/src/main/kotlin/gen.kt +++ b/libraries/tools/idl2k/src/main/kotlin/gen.kt @@ -138,8 +138,8 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT fun generateConstructorAsFunction(repository: Repository, constructor: ExtendedAttribute) = generateFunction( repository, - Operation("", UnitType, constructor.arguments, emptyList(), false), - functionName = "", + Operation("constructor", UnitType, constructor.arguments, emptyList(), false), + functionName = "constructor", nativeGetterOrSetter = NativeGetterOrSetter.NONE) fun superOrPrimaryConstructorCall(constructorAsFunction: GenerateFunction, superClassName: String, superOrPrimaryConstructor: ExtendedAttribute): GenerateFunctionCall { diff --git a/libraries/tools/idl2k/src/main/kotlin/render.kt b/libraries/tools/idl2k/src/main/kotlin/render.kt index 1535c439a6f..3a4e352a8c2 100644 --- a/libraries/tools/idl2k/src/main/kotlin/render.kt +++ b/libraries/tools/idl2k/src/main/kotlin/render.kt @@ -98,6 +98,8 @@ private val GenerateAttribute.isVar: Boolean private fun GenerateAttribute.isCommented(parent: String) = "$parent.$name" in commentOutDeclarations || "$parent.$name: ${type.render()}" in commentOutDeclarations private fun GenerateFunction.isCommented(parent: String) = "$parent.$name" in commentOutDeclarations || "$parent.$name(${arguments.size()})" in commentOutDeclarations +private fun GenerateAttribute.isRequiredFunctionArgument(owner: String, functionName: String) = "$owner.$functionName.$name" in requiredArguments +private fun GenerateFunction.fixRequiredArguments(parent: String) = copy(arguments = arguments.map { arg -> arg.copy(initializer = if (arg.isRequiredFunctionArgument(parent, name)) null else arg.initializer) }) fun Appendable.render(allTypes: Map, typeNamesToUnions: Map>, iface: GenerateTraitOrClass, markerAnnotation: Boolean = false) { append("native public ") @@ -115,7 +117,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn append(iface.name) val primary = iface.primaryConstructor if (primary != null && (primary.constructor.arguments.isNotEmpty() || iface.secondaryConstructors.isNotEmpty())) { - renderArgumentsDeclaration(primary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false) + renderArgumentsDeclaration(primary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keySet()), false) } val superCallName = primary?.initTypeCall?.name @@ -133,7 +135,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn iface.secondaryConstructors.forEach { secondary -> indent(false, 1) append("constructor") - renderArgumentsDeclaration(secondary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false) + renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keySet()), false) if (secondary.initTypeCall != null) { append(" : ") @@ -155,7 +157,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn renderAttributeDeclaration(arg, override = arg.signature in superSignatures, open = iface.kind == GenerateDefinitionKind.CLASS && arg.readOnly, commented = arg.isCommented(iface.name)) } iface.memberFunctions.filter { it !in superFunctions && !it.static }.map { it.dynamicIfUnknownType(allTypes.keySet()) }.groupBy { it.signature }.reduceValues(::betterFunction).values().forEach { - renderFunctionDeclaration(it, it.signature in superSignatures, commented = it.isCommented(iface.name)) + renderFunctionDeclaration(it.fixRequiredArguments(iface.name), it.signature in superSignatures, commented = it.isCommented(iface.name)) } val staticAttributes = iface.memberAttributes.filter { it.static } @@ -172,7 +174,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn renderAttributeDeclaration(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name)) } staticFunctions.forEach { - renderFunctionDeclaration(it, override = false, level = 2, commented = it.isCommented(iface.name)) + renderFunctionDeclaration(it.fixRequiredArguments(iface.name), override = false, level = 2, commented = it.isCommented(iface.name)) } indent(false, 1) appendln("}")