summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-28 11:48:52 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-28 11:51:44 +0100
commit14de45296eb93a42282782769b03e2e42739a2aa (patch)
tree5a1aa57d443ceacdf267bb87bf75639486abe995 /Libraries/LibJS/Tests
parentf1a074a262a9815a1063b17d20df1d1a15308cef (diff)
downloadserenity-14de45296eb93a42282782769b03e2e42739a2aa.zip
LibJS: Fix broken parsing of `!o.a`
Unary expressions parsing now respects precedence and associativity of operators. This patch also makes `typeof` left-associative which was an oversight. Thanks to Conrad for helping me work this out. :^)
Diffstat (limited to 'Libraries/LibJS/Tests')
-rw-r--r--Libraries/LibJS/Tests/parser-unary-associativity.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/parser-unary-associativity.js b/Libraries/LibJS/Tests/parser-unary-associativity.js
new file mode 100644
index 0000000000..240b20f61c
--- /dev/null
+++ b/Libraries/LibJS/Tests/parser-unary-associativity.js
@@ -0,0 +1,18 @@
+function assert(x) { if (!x) throw 1; }
+
+try {
+ var o = {};
+ o.a = 1;
+
+ assert(o.a === 1);
+ assert(!o.a === false);
+ assert(!o.a === !(o.a));
+ assert(~o.a === ~(o.a));
+
+ assert((typeof "x" === "string") === true);
+ assert(!(typeof "x" === "string") === false);
+
+ console.log("PASS");
+} catch (e) {
+ console.log("FAIL: " + e);
+}