Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/js/v8natives.js

Issue 1498593006: [proxies] Use JSReceiver::GetKeys() for more purposes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/js/symbol.js ('k') | src/objects.h » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ---------------------------------------------------------------------------- 9 // ----------------------------------------------------------------------------
10 // Imports 10 // Imports
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 var receiver = this; 250 var receiver = this;
251 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) { 251 if (IS_NULL(receiver) || IS_UNDEFINED(receiver)) {
252 receiver = %GlobalProxy(ObjectLookupSetter); 252 receiver = %GlobalProxy(ObjectLookupSetter);
253 } 253 }
254 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), SETTER); 254 return %LookupAccessor(TO_OBJECT(receiver), TO_NAME(name), SETTER);
255 } 255 }
256 256
257 257
258 function ObjectKeys(obj) { 258 function ObjectKeys(obj) {
259 obj = TO_OBJECT(obj); 259 obj = TO_OBJECT(obj);
260 return %OwnKeys(obj); 260 var filter = PROPERTY_FILTER_ONLY_ENUMERABLE | PROPERTY_FILTER_SKIP_SYMBOLS;
261 return %GetOwnPropertyKeys(obj, filter);
261 } 262 }
262 263
263 264
264 // ES5 8.10.1. 265 // ES5 8.10.1.
265 function IsAccessorDescriptor(desc) { 266 function IsAccessorDescriptor(desc) {
266 if (IS_UNDEFINED(desc)) return false; 267 if (IS_UNDEFINED(desc)) return false;
267 return desc.hasGetter() || desc.hasSetter(); 268 return desc.hasGetter() || desc.hasSetter();
268 } 269 }
269 270
270 271
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 return obj; 849 return obj;
849 } 850 }
850 851
851 852
852 // ES6 section 19.1.2.6 853 // ES6 section 19.1.2.6
853 function ObjectGetOwnPropertyDescriptor(obj, p) { 854 function ObjectGetOwnPropertyDescriptor(obj, p) {
854 return %GetOwnProperty(obj, p); 855 return %GetOwnProperty(obj, p);
855 } 856 }
856 857
857 858
858 // For Harmony proxies
859 function ToNameArray(obj, trap, includeSymbols) {
860 if (!IS_SPEC_OBJECT(obj)) {
861 throw MakeTypeError(kProxyNonObjectPropNames, trap, obj);
862 }
863 var n = TO_UINT32(obj.length);
864 var array = new GlobalArray(n);
865 var realLength = 0;
866 var names = { __proto__: null }; // TODO(rossberg): use sets once ready.
867 for (var index = 0; index < n; index++) {
868 var s = TO_NAME(obj[index]);
869 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
870 if (IS_SYMBOL(s) && !includeSymbols) continue;
871 if (%HasOwnProperty(names, s)) {
872 throw MakeTypeError(kProxyRepeatedPropName, trap, s);
873 }
874 array[realLength] = s;
875 ++realLength;
876 names[s] = 0;
877 }
878 array.length = realLength;
879 return array;
880 }
881
882
883 function ObjectGetOwnPropertyKeys(obj, filter) {
884 var nameArrays = new InternalArray();
885 filter |= PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
886 var interceptorInfo = %GetInterceptorInfo(obj);
887
888 // Find all the indexed properties.
889
890 // Only get own element names if we want to include string keys.
891 if ((filter & PROPERTY_ATTRIBUTES_STRING) === 0) {
892 var ownElementNames = %GetOwnElementNames(obj);
893 for (var i = 0; i < ownElementNames.length; ++i) {
894 ownElementNames[i] = %_NumberToString(ownElementNames[i]);
895 }
896 nameArrays.push(ownElementNames);
897 // Get names for indexed interceptor properties.
898 if ((interceptorInfo & 1) != 0) {
899 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
900 if (!IS_UNDEFINED(indexedInterceptorNames)) {
901 nameArrays.push(indexedInterceptorNames);
902 }
903 }
904 }
905
906 // Find all the named properties.
907
908 // Get own property names.
909 nameArrays.push(%GetOwnPropertyNames(obj, filter));
910
911 // Get names for named interceptor properties if any.
912 if ((interceptorInfo & 2) != 0) {
913 var namedInterceptorNames =
914 %GetNamedInterceptorPropertyNames(obj);
915 if (!IS_UNDEFINED(namedInterceptorNames)) {
916 nameArrays.push(namedInterceptorNames);
917 }
918 }
919
920 var propertyNames =
921 %Apply(InternalArray.prototype.concat,
922 nameArrays[0], nameArrays, 1, nameArrays.length - 1);
923
924 // Property names are expected to be unique strings,
925 // but interceptors can interfere with that assumption.
926 if (interceptorInfo != 0) {
927 var seenKeys = { __proto__: null };
928 var j = 0;
929 for (var i = 0; i < propertyNames.length; ++i) {
930 var name = propertyNames[i];
931 if (IS_SYMBOL(name)) {
932 if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) {
933 continue;
934 }
935 } else {
936 if (filter & PROPERTY_ATTRIBUTES_STRING) continue;
937 name = TO_STRING(name);
938 }
939 if (seenKeys[name]) continue;
940 seenKeys[name] = true;
941 propertyNames[j++] = name;
942 }
943 propertyNames.length = j;
944 }
945
946 return propertyNames;
947 }
948
949
950 // ES6 section 9.1.12 / 9.5.12 859 // ES6 section 9.1.12 / 9.5.12
951 function OwnPropertyKeys(obj) { 860 function OwnPropertyKeys(obj) {
952 if (%_IsJSProxy(obj)) { 861 return %GetOwnPropertyKeys(obj, PROPERTY_FILTER_NONE);
953 var handler = %GetHandler(obj);
954 // TODO(caitp): Proxy.[[OwnPropertyKeys]] can not be implemented to spec
955 // without an implementation of Direct Proxies.
956 var names = CallTrap0(handler, "ownKeys", UNDEFINED);
957 return ToNameArray(names, "getOwnPropertyNames", false);
958 }
959 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL);
960 } 862 }
961 863
962 864
963 // ES5 section 15.2.3.4. 865 // ES5 section 15.2.3.4.
964 function ObjectGetOwnPropertyNames(obj) { 866 function ObjectGetOwnPropertyNames(obj) {
965 obj = TO_OBJECT(obj); 867 obj = TO_OBJECT(obj);
966 // Special handling for proxies. 868 return %GetOwnPropertyKeys(obj, PROPERTY_FILTER_SKIP_SYMBOLS);
967 if (%_IsJSProxy(obj)) {
968 var handler = %GetHandler(obj);
969 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
970 return ToNameArray(names, "getOwnPropertyNames", false);
971 }
972
973 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC);
974 } 869 }
975 870
976 871
977 // ES5 section 15.2.3.5. 872 // ES5 section 15.2.3.5.
978 function ObjectCreate(proto, properties) { 873 function ObjectCreate(proto, properties) {
979 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 874 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
980 throw MakeTypeError(kProtoObjectOrNull, proto); 875 throw MakeTypeError(kProtoObjectOrNull, proto);
981 } 876 }
982 var obj = {}; 877 var obj = {};
983 %InternalSetPrototype(obj, proto); 878 %InternalSetPrototype(obj, proto);
(...skipping 13 matching lines...) Expand all
997 var name = TO_NAME(p); 892 var name = TO_NAME(p);
998 var desc = ToPropertyDescriptor(attributes); 893 var desc = ToPropertyDescriptor(attributes);
999 DefineOwnProperty(obj, name, desc, true); 894 DefineOwnProperty(obj, name, desc, true);
1000 return obj; 895 return obj;
1001 } 896 }
1002 return %ObjectDefineProperty(obj, p, attributes); 897 return %ObjectDefineProperty(obj, p, attributes);
1003 } 898 }
1004 899
1005 900
1006 function GetOwnEnumerablePropertyNames(object) { 901 function GetOwnEnumerablePropertyNames(object) {
1007 var names = new InternalArray(); 902 return %GetOwnPropertyKeys(object, PROPERTY_FILTER_ONLY_ENUMERABLE);
1008 for (var key in object) {
1009 if (%HasOwnProperty(object, key)) {
1010 names.push(key);
1011 }
1012 }
1013
1014 var filter = PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
1015 var symbols = %GetOwnPropertyNames(object, filter);
1016 for (var i = 0; i < symbols.length; ++i) {
1017 var symbol = symbols[i];
1018 if (IS_SYMBOL(symbol)) {
1019 var desc = ObjectGetOwnPropertyDescriptor(object, symbol);
1020 if (desc.enumerable) names.push(symbol);
1021 }
1022 }
1023
1024 return names;
1025 } 903 }
1026 904
1027 905
1028 // ES5 section 15.2.3.7. 906 // ES5 section 15.2.3.7.
1029 function ObjectDefineProperties(obj, properties) { 907 function ObjectDefineProperties(obj, properties) {
1030 // The new pure-C++ implementation doesn't support O.o. 908 // The new pure-C++ implementation doesn't support O.o.
1031 // TODO(jkummerow): Implement missing features and remove fallback path. 909 // TODO(jkummerow): Implement missing features and remove fallback path.
1032 if (%IsObserved(obj)) { 910 if (%IsObserved(obj)) {
1033 if (!IS_SPEC_OBJECT(obj)) { 911 if (!IS_SPEC_OBJECT(obj)) {
1034 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties"); 912 throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 to.FunctionSourceString = FunctionSourceString; 1601 to.FunctionSourceString = FunctionSourceString;
1724 to.GetIterator = GetIterator; 1602 to.GetIterator = GetIterator;
1725 to.GetMethod = GetMethod; 1603 to.GetMethod = GetMethod;
1726 to.IsFinite = GlobalIsFinite; 1604 to.IsFinite = GlobalIsFinite;
1727 to.IsNaN = GlobalIsNaN; 1605 to.IsNaN = GlobalIsNaN;
1728 to.NewFunctionString = NewFunctionString; 1606 to.NewFunctionString = NewFunctionString;
1729 to.NumberIsNaN = NumberIsNaN; 1607 to.NumberIsNaN = NumberIsNaN;
1730 to.ObjectDefineProperties = ObjectDefineProperties; 1608 to.ObjectDefineProperties = ObjectDefineProperties;
1731 to.ObjectDefineProperty = ObjectDefineProperty; 1609 to.ObjectDefineProperty = ObjectDefineProperty;
1732 to.ObjectFreeze = ObjectFreezeJS; 1610 to.ObjectFreeze = ObjectFreezeJS;
1733 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys;
1734 to.ObjectHasOwnProperty = ObjectHasOwnProperty; 1611 to.ObjectHasOwnProperty = ObjectHasOwnProperty;
1735 to.ObjectIsFrozen = ObjectIsFrozen; 1612 to.ObjectIsFrozen = ObjectIsFrozen;
1736 to.ObjectIsSealed = ObjectIsSealed; 1613 to.ObjectIsSealed = ObjectIsSealed;
1737 to.ObjectToString = ObjectToString; 1614 to.ObjectToString = ObjectToString;
1738 to.ToNameArray = ToNameArray;
1739 }); 1615 });
1740 1616
1741 %InstallToContext([ 1617 %InstallToContext([
1742 "global_eval_fun", GlobalEval, 1618 "global_eval_fun", GlobalEval,
1743 "object_value_of", ObjectValueOf, 1619 "object_value_of", ObjectValueOf,
1744 "object_to_string", ObjectToString, 1620 "object_to_string", ObjectToString,
1745 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor, 1621 "object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
1746 "to_complete_property_descriptor", ToCompletePropertyDescriptor, 1622 "to_complete_property_descriptor", ToCompletePropertyDescriptor,
1747 ]); 1623 ]);
1748 1624
1749 }) 1625 })
OLDNEW
« no previous file with comments | « src/js/symbol.js ('k') | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698