From 30d24af54a42b232204c3e5fcb4d52f48e562832 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 25 Mar 2020 16:09:23 +0100 Subject: [PATCH] LibJS: Add a basic test for the "throw" keyword --- Libraries/LibJS/Tests/throw-basic.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Libraries/LibJS/Tests/throw-basic.js diff --git a/Libraries/LibJS/Tests/throw-basic.js b/Libraries/LibJS/Tests/throw-basic.js new file mode 100644 index 0000000000..6cf2c0fe58 --- /dev/null +++ b/Libraries/LibJS/Tests/throw-basic.js @@ -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");