This repository was 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
Fix #32: Implement exception handling. #38
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fdf8964
Add support for Tags in our Wasm structures and writers.
sjrd 57819db
Force usage of the leaner JavaScriptException for now.
sjrd dcfb071
Implement WrapAsThrowable and UnwrapFromThrowable.
sjrd d115b9f
Implement Throw.
sjrd c62ac8c
Make it possible to run the sample from the browser.
sjrd 21881fd
Remove old exception-related instructions from an outdated spec.
sjrd e5f1639
Make the logic for indenting instructions more generic.
sjrd 2557861
Implement TryCatch.
sjrd 452ffec
Implement rudimentary support for TryFinally.
sjrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
package testsuite | ||
|
||
/** Temporary assertion method on Scala for Wasm. `ok` method generates `unreachable` if the given | ||
* condition is false, trapping at runtime. | ||
* | ||
* While it's desirable to eventually utilize Scala's assertion, it's currently unavailable because | ||
* we cannot compile Throwable to wasm yet, thus throw new (Throwable) is unusable. and making | ||
* assert unavailable as well. | ||
* | ||
* Using JS's assert isn't feasible either; `console.assert` merely displays a message when | ||
* assertion failure, and Node's assert module is unsupported for Wasm due to current | ||
* unavailability of `JSImport` and module. | ||
*/ | ||
/** Assertion helpers. */ | ||
object Assert { | ||
def ok(cond: Boolean): Unit = | ||
if (!cond) null.toString() // Apply to Null should compile to unreachable | ||
if (!cond) fail() | ||
|
||
def assertSame(expected: Any, actual: Any): Unit = | ||
ok(expected.asInstanceOf[AnyRef] eq actual.asInstanceOf[AnyRef]) | ||
|
||
def fail(): Unit = | ||
throw new AssertionError("assertion failed") | ||
} |
46 changes: 46 additions & 0 deletions
46
test-suite/src/main/scala/testsuite/core/WrapUnwrapThrowableTest.scala
This file contains hidden or 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,46 @@ | ||
package testsuite.core | ||
|
||
import scala.scalajs.js | ||
|
||
import testsuite.Assert.{assertSame, fail} | ||
|
||
object WrapUnwrapThrowableTest { | ||
def main(): Unit = { | ||
testWrapAsThrowable() | ||
testUnwrapFromThrowable() | ||
} | ||
|
||
def testWrapAsThrowable(): Unit = { | ||
// Wraps a js.Object | ||
val obj = new js.Object | ||
val e1 = js.special.wrapAsThrowable(obj) | ||
e1 match { | ||
case e1: js.JavaScriptException => assertSame(obj, e1.exception) | ||
case _ => fail() | ||
} | ||
|
||
// Wraps null | ||
val e2 = js.special.wrapAsThrowable(null) | ||
e2 match { | ||
case e2: js.JavaScriptException => assertSame(null, e2.exception) | ||
case _ => fail() | ||
} | ||
|
||
// Does not wrap a Throwable | ||
val th = new IllegalArgumentException | ||
assertSame(th, js.special.wrapAsThrowable(th)) | ||
|
||
// Does not double-wrap | ||
assertSame(e1, js.special.wrapAsThrowable(e1)) | ||
} | ||
|
||
def testUnwrapFromThrowable(): Unit = { | ||
// Unwraps a JavaScriptException | ||
val obj = new js.Object | ||
assertSame(obj, js.special.unwrapFromThrowable(new js.JavaScriptException(obj))) | ||
|
||
// Does not unwrap a Throwable | ||
val th = new IllegalArgumentException | ||
assertSame(th, js.special.unwrapFromThrowable(th)) | ||
} | ||
} |
This file contains hidden or 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,9 @@ | ||
<html> | ||
<head> | ||
<title>Test run</title> | ||
</head> | ||
<body> | ||
<p>Look at the console</p> | ||
<script type="module" src="./run.mjs"></script> | ||
</body> | ||
</html> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.