Skip to content

Commit

Permalink
Backport "Fix #19528: Actually remove Dynamic from interfaces of nati…
Browse files Browse the repository at this point in the history
…ve JS classes." to LTS (#20866)

Backports #19536 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 1, 2024
2 parents 49e307c + 1a0cf0a commit 56cb527
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class JSCodeGen()(using genCtx: Context) {
kind,
None,
superClass,
genClassInterfaces(sym, forJSClass = false),
genClassInterfaces(sym, forJSClass = true),
None,
jsNativeLoadSpec,
Nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.scalajs.testsuite.jsinterop

import scala.language.dynamics

import org.junit.Assert.*
import org.junit.Test

import scala.scalajs.js
import scala.scalajs.js.annotation.*

class CustomDynamicTestScala3 {
import CustomDynamicTestScala3.*

@Test
def testCustomDynamicClass_Issue19528(): Unit = {
val obj = new CustomDynamicClass()

assertEquals(false, obj.hasOwnProperty("foo"))
obj.foo = "bar"
assertEquals("bar", obj.foo)
assertEquals(true, obj.hasOwnProperty("foo"))
}

@Test
def testCustomDynamicTrait_Issue19528(): Unit = {
val obj = new js.Object().asInstanceOf[CustomDynamicTrait]

assertEquals(false, obj.hasOwnProperty("foo"))
obj.foo = "bar"
assertEquals("bar", obj.foo)
assertEquals(true, obj.hasOwnProperty("foo"))
}
}

object CustomDynamicTestScala3 {
@js.native
@JSGlobal("Object")
class CustomDynamicClass extends js.Any with Dynamic {
@JSBracketAccess
def selectDynamic(name: String): js.Any = js.native
@JSBracketAccess
def updateDynamic(name: String)(value: js.Any): Unit = js.native

@JSBracketCall
def applyDynamic(name: String)(args: js.Any*): js.Any = js.native
}

@js.native
trait CustomDynamicTrait extends js.Any with Dynamic {
@JSBracketAccess
def selectDynamic(name: String): js.Any = js.native
@JSBracketAccess
def updateDynamic(name: String)(value: js.Any): Unit = js.native

@JSBracketCall
def applyDynamic(name: String)(args: js.Any*): js.Any = js.native
}
}

0 comments on commit 56cb527

Please sign in to comment.