trap-is-null-target-is-proxy.js (1357B)
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys 6 description: > 7 If "ownKeys" trap is null or undefined, [[OwnPropertyKeys]] call is 8 properly forwarded to [[ProxyTarget]] (which is also a Proxy object). 9 info: | 10 [[OwnPropertyKeys]] ( ) 11 12 [...] 13 4. Let target be O.[[ProxyTarget]]. 14 5. Let trap be ? GetMethod(handler, "ownKeys"). 15 6. If trap is undefined, then 16 a. Return ? target.[[OwnPropertyKeys]](). 17 18 OrdinaryOwnPropertyKeys ( O ) 19 20 1. Let keys be a new empty List. 21 2. For each own property key P of O that is an array index, 22 in ascending numeric index order, do 23 a. Add P as the last element of keys. 24 3. For each own property key P of O that is a String but is not an 25 array index, in ascending chronological order of property creation, do 26 a. Add P as the last element of keys. 27 [...] 28 5. Return keys. 29 includes: [compareArray.js] 30 features: [Proxy] 31 ---*/ 32 33 var plainObject = { 34 foo: 1, 35 "0": 2, 36 get bar() {}, 37 "1": 4, 38 }; 39 40 var plainObjectTarget = new Proxy(plainObject, {}); 41 var plainObjectProxy = new Proxy(plainObjectTarget, { 42 ownKeys: null, 43 }); 44 45 assert.compareArray( 46 Object.keys(plainObjectProxy), 47 ["0", "1", "foo", "bar"] 48 ); 49 50 reportCompare(0, 0);