| 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-object-initializer-runtime-semantics-propertydefinitionevaluation |
| 5 |
description: > |
| 6 |
Proxy's "get" trap is not invoked for non-enumerable keys. |
| 7 |
info: | |
| 8 |
PropertyDefinition : ... AssignmentExpression |
| 9 |
|
| 10 |
[...] |
| 11 |
3. Let excludedNames be a new empty List. |
| 12 |
4. Return ? CopyDataProperties(object, fromValue, excludedNames). |
| 13 |
|
| 14 |
CopyDataProperties ( target, source, excludedItems ) |
| 15 |
|
| 16 |
[...] |
| 17 |
5. Let keys be ? from.[[OwnPropertyKeys]](). |
| 18 |
6. For each element nextKey of keys in List order, do |
| 19 |
[...] |
| 20 |
c. If excluded is false, then |
| 21 |
i. Let desc be ? from.[[GetOwnProperty]](nextKey). |
| 22 |
ii. If desc is not undefined and desc.[[Enumerable]] is true, then |
| 23 |
1. Let propValue be ? Get(from, nextKey). |
| 24 |
2. Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue). |
| 25 |
|
| 26 |
[[OwnPropertyKeys]] ( ) |
| 27 |
|
| 28 |
[...] |
| 29 |
7. Let trapResultArray be ? Call(trap, handler, « target »). |
| 30 |
8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »). |
| 31 |
[...] |
| 32 |
23. Return trapResult. |
| 33 |
features: [object-spread, Proxy, Symbol] |
| 34 |
includes: [compareArray.js, propertyHelper.js] |
| 35 |
---*/ |
| 36 |
|
| 37 |
var VALUE_LITERAL = "VALUE_LITERAL"; |
| 38 |
var VALUE_GOPD = "VALUE_GOPD"; |
| 39 |
var VALUE_GET = "VALUE_GET"; |
| 40 |
|
| 41 |
var dontEnumSymbol = Symbol("dont_enum_symbol"); |
| 42 |
var enumerableSymbol = Symbol("enumerable_symbol"); |
| 43 |
|
| 44 |
var dontEnumKeys = [dontEnumSymbol, "dontEnumString", "0"]; |
| 45 |
var enumerableKeys = [enumerableSymbol, "enumerableString", "1"]; |
| 46 |
var ownKeysResult = [...dontEnumKeys, ...enumerableKeys]; |
| 47 |
|
| 48 |
var getOwnKeys = []; |
| 49 |
var getKeys = []; |
| 50 |
var proxy = new Proxy({}, { |
| 51 |
getOwnPropertyDescriptor: function(_target, key) { |
| 52 |
getOwnKeys.push(key); |
| 53 |
var isEnumerable = enumerableKeys.indexOf(key) !== -1; |
| 54 |
return {value: VALUE_GOPD, writable: false, enumerable: isEnumerable, configurable: true}; |
| 55 |
}, |
| 56 |
get: function(_target, key) { |
| 57 |
getKeys.push(key); |
| 58 |
return VALUE_GET; |
| 59 |
}, |
| 60 |
ownKeys: function() { |
| 61 |
return ownKeysResult; |
| 62 |
}, |
| 63 |
}); |
| 64 |
|
| 65 |
var result = {[enumerableSymbol]: VALUE_LITERAL, enumerableString: VALUE_LITERAL, [1]: VALUE_LITERAL, ...proxy}; |
| 66 |
assert.compareArray(getOwnKeys, ownKeysResult); |
| 67 |
assert.compareArray(getKeys, enumerableKeys); |
| 68 |
|
| 69 |
verifyProperty(result, enumerableSymbol, {value: VALUE_GET, writable: true, enumerable: true, configurable: true}); |
| 70 |
verifyProperty(result, "enumerableString", {value: VALUE_GET, writable: true, enumerable: true, configurable: true}); |
| 71 |
verifyProperty(result, "1", {value: VALUE_GET, writable: true, enumerable: true, configurable: true}); |
| 72 |
|
| 73 |
reportCompare(0, 0); |