mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:08:11 +00:00
LibJS: Add a basic test for the "throw" keyword
This commit is contained in:
parent
9e8d3d6287
commit
30d24af54a
1 changed files with 26 additions and 0 deletions
26
Libraries/LibJS/Tests/throw-basic.js
Normal file
26
Libraries/LibJS/Tests/throw-basic.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
function assert(x) { if (!x) console.log("FAIL"); }
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (e) {
|
||||||
|
assert(e === 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw [99];
|
||||||
|
} catch (e) {
|
||||||
|
assert(typeof e === "object");
|
||||||
|
assert(e.length === 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo() {
|
||||||
|
throw "hello";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch (e) {
|
||||||
|
assert(e === "hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("PASS");
|
Loading…
Add table
Add a link
Reference in a new issue