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