Debian Codegraph @

js/src/tests/test262/language/statements/with/binding-blocked-by-unscopables.js

raw
1 // Copyright 2015 Mike Pennisi. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 es6id: 8.1.1.2.1
6 description: >
7 True-coercing `Symbol.unscopables` properties block access to object environment record
8 info: |
9 [...]
10 6. If the withEnvironment flag of envRec is false, return true.
11 7. Let unscopables be Get(bindings, @@unscopables).
12 8. ReturnIfAbrupt(unscopables).
13 9. If Type(unscopables) is Object, then
14 a. Let blocked be ToBoolean(Get(unscopables, N)).
15 b. ReturnIfAbrupt(blocked).
16 c. If blocked is true, return false.
17
18 ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation
19 [...]
20 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true.
21 [...]
22 flags: [noStrict]
23 features: [Symbol.unscopables]
24 ---*/
25
26 var x = 0;
27 var env = { x: 1 };
28 env[Symbol.unscopables] = { x: true };
29
30 with (env) {
31 assert.sameValue(x, 0, 'literal `true` value');
32 }
33
34 env[Symbol.unscopables].x = 'string';
35 with (env) {
36 assert.sameValue(x, 0, 'non-empty string values');
37 }
38
39 env[Symbol.unscopables].x = 86;
40 with (env) {
41 assert.sameValue(x, 0, 'non-zero number values');
42 }
43
44 env[Symbol.unscopables].x = {};
45 with (env) {
46 assert.sameValue(x, 0, 'object values');
47 }
48
49 env[Symbol.unscopables].x = Symbol.unscopables;
50 with (env) {
51 assert.sameValue(x, 0, 'Symbol values');
52 }
53
54 reportCompare(0, 0);