Debian Codegraph @

js/src/tests/test262/language/expressions/object/dstr/object-rest-proxy-gopd-not-called-on-excluded-keys.js

raw
1 // Copyright (C) 2021 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-destructuring-binding-patterns-runtime-semantics-restbindinginitialization
5 description: >
6 Proxy's "getOwnPropertyDescriptor" trap is not invoked for excluded keys.
7 info: |
8 BindingRestProperty : ... BindingIdentifier
9
10 [...]
11 3. Perform ? CopyDataProperties(restObj, value, excludedNames).
12
13 CopyDataProperties ( target, source, excludedItems )
14
15 [...]
16 5. Let keys be ? from.[[OwnPropertyKeys]]().
17 6. For each element nextKey of keys in List order, do
18 b. For each element e of excludedItems, do
19 i. If SameValue(e, nextKey) is true, then
20 1. Set excluded to true.
21 c. If excluded is false, then
22 i. Let desc be ? from.[[GetOwnProperty]](nextKey).
23
24 [[OwnPropertyKeys]] ( )
25
26 [...]
27 7. Let trapResultArray be ? Call(trap, handler, « target »).
28 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »).
29 [...]
30 23. Return trapResult.
31 features: [object-rest, destructuring-binding, Proxy, Symbol]
32 includes: [compareArray.js]
33 ---*/
34
35 var excludedSymbol = Symbol("excluded_symbol");
36 var includedSymbol = Symbol("included_symbol");
37
38 var excludedKeys = [excludedSymbol, "excludedString", "0"];
39 var includedKeys = [includedSymbol, "includedString", "1"];
40 var ownKeysResult = [...excludedKeys, ...includedKeys];
41
42 var getOwnKeys = [];
43 var proxy = new Proxy({}, {
44 getOwnPropertyDescriptor: function(_target, key) {
45 getOwnKeys.push(key);
46 },
47 ownKeys: function() {
48 return ownKeysResult;
49 },
50 });
51
52 var {[excludedSymbol]: _, excludedString, 0: excludedIndex, ...rest} = proxy;
53 assert.compareArray(getOwnKeys, includedKeys);
54
55 reportCompare(0, 0);