This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from sjrd/enable-hijacked-classes
Support transformation of hijacked classes.
- Loading branch information
Showing
9 changed files
with
155 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test-suite/src/main/scala/testsuite/core/AsInstanceOfTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package testsuite.core.asinstanceof | ||
|
||
import scala.scalajs.js.annotation._ | ||
|
||
object AsInstanceOfTest { | ||
def main(): Unit = { val _ = test() } | ||
|
||
@JSExportTopLevel("asInstanceOf") | ||
def test(): Boolean = { | ||
testInt(5) && | ||
testClasses(new Child()) && | ||
testString("foo", true) | ||
} | ||
|
||
def testClasses(c: Child): Boolean = { | ||
val c1 = c.asInstanceOf[Child] | ||
val c2 = c.asInstanceOf[Parent] | ||
c1.foo() == 5 && c2.foo() == 5 | ||
} | ||
|
||
def testInt(x: Int): Boolean = { | ||
val x1 = x.asInstanceOf[Int] | ||
x1 == 5 | ||
} | ||
|
||
def testString(s: String, b: Boolean): Boolean = { | ||
val s1 = s.asInstanceOf[String] | ||
val s2 = ("" + b).asInstanceOf[String] | ||
s1.length() == 3 && s2.length() == 4 | ||
} | ||
|
||
class Parent { | ||
def foo(): Int = 5 | ||
} | ||
class Child extends Parent | ||
} |
22 changes: 22 additions & 0 deletions
22
test-suite/src/main/scala/testsuite/core/HijackedClassesMonoTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package testsuite.core.hijackedclassesmono | ||
|
||
import scala.scalajs.js.annotation._ | ||
|
||
object HijackedClassesMonoTest { | ||
def main(): Unit = { val _ = test() } | ||
|
||
@JSExportTopLevel("hijackedClassesMono") | ||
def test(): Boolean = { | ||
testInteger(5) && | ||
testString("foo") | ||
} | ||
|
||
def testInteger(x: Int): Boolean = { | ||
x.hashCode() == 5 | ||
} | ||
|
||
def testString(foo: String): Boolean = { | ||
foo.length() == 3 && | ||
foo.hashCode() == 101574 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters