Serenity Operating System
1test("basic with statement functionality", () => {
2 var object = { foo: 5, bar: 6, baz: 7 };
3 var qux = 1;
4
5 var bar = 99;
6
7 with (object) {
8 expect(foo).toBe(5);
9 expect(bar).toBe(6);
10 expect(baz).toBe(7);
11 expect(qux).toBe(1);
12 expect(typeof quz).toBe("undefined");
13
14 bar = 2;
15 }
16
17 expect(object.bar).toBe(2);
18 expect(() => foo).toThrowWithMessage(ReferenceError, "'foo' is not defined");
19
20 expect(bar).toBe(99);
21});
22
23test("syntax error in strict mode", () => {
24 expect("'use strict'; with (foo) {}").not.toEval();
25});
26
27test("restores lexical environment even when exception is thrown", () => {
28 var object = {
29 foo: 1,
30 get bar() {
31 throw Error();
32 },
33 };
34
35 try {
36 with (object) {
37 expect(foo).toBe(1);
38 bar;
39 }
40 expect().fail();
41 } catch (e) {
42 expect(() => foo).toThrowWithMessage(ReferenceError, "'foo' is not defined");
43 }
44 expect(() => foo).toThrowWithMessage(ReferenceError, "'foo' is not defined");
45});