Serenity Operating System
at master 65 lines 1.9 kB view raw
1describe("CallExpression", () => { 2 test("callee is evaluated before arguments", () => { 3 function foo() {} 4 const values = []; 5 6 [foo][(values.push("callee"), 0)](values.push("args")); 7 8 expect(values).toEqual(["callee", "args"]); 9 }); 10 11 test("arguments are evaluated in order", () => { 12 function foo() {} 13 const values = []; 14 15 foo(values.push("arg1"), values.push("arg2"), values.push("arg3")); 16 17 expect(values).toEqual(["arg1", "arg2", "arg3"]); 18 }); 19 20 test("arguments are evaluated before callee is checked for its type", () => { 21 const values = []; 22 23 expect(() => { 24 "foo"(values.push("args")); 25 }).toThrowWithMessage(TypeError, "foo is not a function"); 26 expect(values).toEqual(["args"]); 27 28 expect(() => { 29 "foo"(bar); 30 }).toThrowWithMessage(ReferenceError, "'bar' is not defined"); 31 }); 32}); 33 34describe("NewExpression", () => { 35 test("callee is evaluated before arguments", () => { 36 function Foo() {} 37 const values = []; 38 39 new [Foo][(values.push("callee"), 0)](values.push("args")); 40 41 expect(values).toEqual(["callee", "args"]); 42 }); 43 44 test("arguments are evaluated in order", () => { 45 function Foo() {} 46 const values = []; 47 48 new Foo(values.push("arg1"), values.push("arg2"), values.push("arg3")); 49 50 expect(values).toEqual(["arg1", "arg2", "arg3"]); 51 }); 52 53 test("arguments are evaluated before callee is checked for its type", () => { 54 const values = []; 55 56 expect(() => { 57 new "Foo"(values.push("args")); 58 }).toThrowWithMessage(TypeError, "Foo is not a constructor"); 59 expect(values).toEqual(["args"]); 60 61 expect(() => { 62 new "Foo"(bar); 63 }).toThrowWithMessage(ReferenceError, "'bar' is not defined"); 64 }); 65});