summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/object-basic.js
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2021-11-26 23:36:43 +0100
committerLinus Groh <mail@linusgroh.de>2021-11-30 17:05:32 +0000
commit51e23cd04303e6cd18987d90dec4cc032341b371 (patch)
tree3f5ca576f3b3b9c32195adb8a4edec096f3cb3da /Userland/Libraries/LibJS/Tests/object-basic.js
parente491fc0e816bc15d0b7d18bfb8659bab93cd0157 (diff)
downloadserenity-51e23cd04303e6cd18987d90dec4cc032341b371.zip
LibJS: Disallow shorthand properties with reserved names
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/object-basic.js')
-rw-r--r--Userland/Libraries/LibJS/Tests/object-basic.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/object-basic.js b/Userland/Libraries/LibJS/Tests/object-basic.js
index 5b3b78fb19..15b1906fbb 100644
--- a/Userland/Libraries/LibJS/Tests/object-basic.js
+++ b/Userland/Libraries/LibJS/Tests/object-basic.js
@@ -151,6 +151,54 @@ describe("side effects", () => {
});
});
+describe("shorthanded properties with special names", () => {
+ test("keywords cannot be used", () => {
+ expect("({ function, })").not.toEval();
+ expect("({ var, })").not.toEval();
+ expect("({ const, })").not.toEval();
+ expect("({ class, })").not.toEval();
+ });
+
+ test("reserved words are allowed in non-strict mode", () => {
+ {
+ var implements = 3;
+ expect({ implements }).toEqual({ implements: 3 });
+ }
+ {
+ var public = "a";
+ expect({ public }).toEqual({ public: "a" });
+ }
+ {
+ var let = 9;
+ expect({ let }).toEqual({ let: 9 });
+ }
+ {
+ var await = 8;
+ expect({ await }).toEqual({ await: 8 });
+ }
+ {
+ var async = 7;
+ expect({ async }).toEqual({ async: 7 });
+ }
+ {
+ var yield = 6;
+ expect({ yield }).toEqual({ yield: 6 });
+ }
+ });
+
+ test("reserved words are not allowed in strict mode", () => {
+ expect('"use strict"; var implements = 3; ({ implements })').not.toEval();
+ expect("\"use strict\"; var public = 'a'; ({ public })").not.toEval();
+ expect('"use strict"; var let = 9; ({ let, })').not.toEval();
+ expect('"use strict"; var yield = 6; ({ yield, })').not.toEval();
+ });
+
+ test("special non reserved words are allowed even in strict mode", () => {
+ expect('"use strict"; var await = 8; ({ await, })').toEval();
+ expect('"use strict"; var async = 7; ({ async, })').toEval();
+ });
+});
+
describe("errors", () => {
test("syntax errors", () => {
expect("({ foo: function() { super.bar; } })").not.toEval();