OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 } | 1031 } |
1032 array[index] = s; | 1032 array[index] = s; |
1033 ++realLength; | 1033 ++realLength; |
1034 names[s] = 0; | 1034 names[s] = 0; |
1035 } | 1035 } |
1036 array.length = realLength; | 1036 array.length = realLength; |
1037 return array; | 1037 return array; |
1038 } | 1038 } |
1039 | 1039 |
1040 | 1040 |
1041 // ES5 section 15.2.3.4. | 1041 function ObjectGetOwnPropertyKeys(obj, symbolsOnly) { |
1042 function ObjectGetOwnPropertyNames(obj) { | |
1043 if (!IS_SPEC_OBJECT(obj)) { | |
1044 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); | |
1045 } | |
1046 // Special handling for proxies. | |
1047 if (%IsJSProxy(obj)) { | |
1048 var handler = %GetHandler(obj); | |
1049 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); | |
1050 return ToNameArray(names, "getOwnPropertyNames", false); | |
1051 } | |
1052 | |
1053 var nameArrays = new InternalArray(); | 1042 var nameArrays = new InternalArray(); |
| 1043 var filter = symbolsOnly ? |
| 1044 PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL : |
| 1045 PROPERTY_ATTRIBUTES_SYMBOLIC; |
1054 | 1046 |
1055 // Find all the indexed properties. | 1047 // Find all the indexed properties. |
1056 | 1048 |
1057 // Get the local element names. | 1049 // Only get the local element names if we want to include string keys. |
1058 var localElementNames = %GetLocalElementNames(obj); | 1050 if (!symbolsOnly) { |
1059 for (var i = 0; i < localElementNames.length; ++i) { | 1051 var localElementNames = %GetLocalElementNames(obj); |
1060 localElementNames[i] = %_NumberToString(localElementNames[i]); | 1052 for (var i = 0; i < localElementNames.length; ++i) { |
1061 } | 1053 localElementNames[i] = %_NumberToString(localElementNames[i]); |
1062 nameArrays.push(localElementNames); | 1054 } |
| 1055 nameArrays.push(localElementNames); |
1063 | 1056 |
1064 // Get names for indexed interceptor properties. | 1057 // Get names for indexed interceptor properties. |
1065 var interceptorInfo = %GetInterceptorInfo(obj); | 1058 var interceptorInfo = %GetInterceptorInfo(obj); |
1066 if ((interceptorInfo & 1) != 0) { | 1059 if ((interceptorInfo & 1) != 0) { |
1067 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); | 1060 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); |
1068 if (!IS_UNDEFINED(indexedInterceptorNames)) { | 1061 if (!IS_UNDEFINED(indexedInterceptorNames)) { |
1069 nameArrays.push(indexedInterceptorNames); | 1062 nameArrays.push(indexedInterceptorNames); |
| 1063 } |
1070 } | 1064 } |
1071 } | 1065 } |
1072 | 1066 |
1073 // Find all the named properties. | 1067 // Find all the named properties. |
1074 | 1068 |
1075 // Get the local property names. | 1069 // Get the local property names. |
1076 nameArrays.push(%GetLocalPropertyNames(obj, false)); | 1070 nameArrays.push(%GetLocalPropertyNames(obj, filter)); |
1077 | 1071 |
1078 // Get names for named interceptor properties if any. | 1072 // Get names for named interceptor properties if any. |
1079 if ((interceptorInfo & 2) != 0) { | 1073 if ((interceptorInfo & 2) != 0) { |
1080 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj); | 1074 var namedInterceptorNames = |
| 1075 %GetNamedInterceptorPropertyNames(obj); |
1081 if (!IS_UNDEFINED(namedInterceptorNames)) { | 1076 if (!IS_UNDEFINED(namedInterceptorNames)) { |
1082 nameArrays.push(namedInterceptorNames); | 1077 nameArrays.push(namedInterceptorNames); |
1083 } | 1078 } |
1084 } | 1079 } |
1085 | 1080 |
1086 var propertyNames = | 1081 var propertyNames = |
1087 %Apply(InternalArray.prototype.concat, | 1082 %Apply(InternalArray.prototype.concat, |
1088 nameArrays[0], nameArrays, 1, nameArrays.length - 1); | 1083 nameArrays[0], nameArrays, 1, nameArrays.length - 1); |
1089 | 1084 |
1090 // Property names are expected to be unique strings, | 1085 // Property names are expected to be unique strings, |
1091 // but interceptors can interfere with that assumption. | 1086 // but interceptors can interfere with that assumption. |
1092 if (interceptorInfo != 0) { | 1087 if (interceptorInfo != 0) { |
1093 var propertySet = { __proto__: null }; | 1088 var seenKeys = { __proto__: null }; |
1094 var j = 0; | 1089 var j = 0; |
1095 for (var i = 0; i < propertyNames.length; ++i) { | 1090 for (var i = 0; i < propertyNames.length; ++i) { |
1096 if (IS_SYMBOL(propertyNames[i])) continue; | 1091 var name = propertyNames[i]; |
1097 var name = ToString(propertyNames[i]); | 1092 if (symbolsOnly) { |
1098 // We need to check for the exact property value since for intrinsic | 1093 if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue; |
1099 // properties like toString if(propertySet["toString"]) will always | 1094 } else { |
1100 // succeed. | 1095 if (IS_SYMBOL(name)) continue; |
1101 if (propertySet[name] === true) { | 1096 name = ToString(name); |
1102 continue; | |
1103 } | 1097 } |
1104 propertySet[name] = true; | 1098 if (seenKeys[name]) continue; |
| 1099 seenKeys[name] = true; |
1105 propertyNames[j++] = name; | 1100 propertyNames[j++] = name; |
1106 } | 1101 } |
1107 propertyNames.length = j; | 1102 propertyNames.length = j; |
1108 } | 1103 } |
1109 | 1104 |
1110 return propertyNames; | 1105 return propertyNames; |
1111 } | 1106 } |
1112 | 1107 |
1113 | 1108 |
| 1109 // ES6 19.1.2.8 |
| 1110 function ObjectGetOwnPropertySymbols(obj) { |
| 1111 if (!IS_SPEC_OBJECT(obj)) { |
| 1112 throw MakeTypeError("called_on_non_object", |
| 1113 ["Object.getOwnPropertySymbols"]); |
| 1114 } |
| 1115 |
| 1116 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
| 1117 |
| 1118 return ObjectGetOwnPropertyKeys(obj, true); |
| 1119 } |
| 1120 |
| 1121 |
| 1122 // ES5 section 15.2.3.4. |
| 1123 function ObjectGetOwnPropertyNames(obj) { |
| 1124 if (!IS_SPEC_OBJECT(obj)) { |
| 1125 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); |
| 1126 } |
| 1127 // Special handling for proxies. |
| 1128 if (%IsJSProxy(obj)) { |
| 1129 var handler = %GetHandler(obj); |
| 1130 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); |
| 1131 return ToNameArray(names, "getOwnPropertyNames", false); |
| 1132 } |
| 1133 |
| 1134 return ObjectGetOwnPropertyKeys(obj, false); |
| 1135 } |
| 1136 |
| 1137 |
1114 // ES5 section 15.2.3.5. | 1138 // ES5 section 15.2.3.5. |
1115 function ObjectCreate(proto, properties) { | 1139 function ObjectCreate(proto, properties) { |
1116 if (!IS_SPEC_OBJECT(proto) && proto !== null) { | 1140 if (!IS_SPEC_OBJECT(proto) && proto !== null) { |
1117 throw MakeTypeError("proto_object_or_null", [proto]); | 1141 throw MakeTypeError("proto_object_or_null", [proto]); |
1118 } | 1142 } |
1119 var obj = { __proto__: proto }; | 1143 var obj = { __proto__: proto }; |
1120 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 1144 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
1121 return obj; | 1145 return obj; |
1122 } | 1146 } |
1123 | 1147 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 // Set up non-enumerable functions in the Object object. | 1437 // Set up non-enumerable functions in the Object object. |
1414 InstallFunctions($Object, DONT_ENUM, $Array( | 1438 InstallFunctions($Object, DONT_ENUM, $Array( |
1415 "keys", ObjectKeys, | 1439 "keys", ObjectKeys, |
1416 "create", ObjectCreate, | 1440 "create", ObjectCreate, |
1417 "defineProperty", ObjectDefineProperty, | 1441 "defineProperty", ObjectDefineProperty, |
1418 "defineProperties", ObjectDefineProperties, | 1442 "defineProperties", ObjectDefineProperties, |
1419 "freeze", ObjectFreeze, | 1443 "freeze", ObjectFreeze, |
1420 "getPrototypeOf", ObjectGetPrototypeOf, | 1444 "getPrototypeOf", ObjectGetPrototypeOf, |
1421 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1445 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
1422 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1446 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1447 // getOwnPropertySymbols is added in symbol.js. |
1423 "is", ObjectIs, | 1448 "is", ObjectIs, |
1424 "isExtensible", ObjectIsExtensible, | 1449 "isExtensible", ObjectIsExtensible, |
1425 "isFrozen", ObjectIsFrozen, | 1450 "isFrozen", ObjectIsFrozen, |
1426 "isSealed", ObjectIsSealed, | 1451 "isSealed", ObjectIsSealed, |
1427 "preventExtensions", ObjectPreventExtension, | 1452 "preventExtensions", ObjectPreventExtension, |
1428 "seal", ObjectSeal | 1453 "seal", ObjectSeal |
| 1454 // observe is added in object-observe.js. |
1429 )); | 1455 )); |
1430 } | 1456 } |
1431 | 1457 |
1432 SetUpObject(); | 1458 SetUpObject(); |
1433 | 1459 |
1434 | 1460 |
1435 // ---------------------------------------------------------------------------- | 1461 // ---------------------------------------------------------------------------- |
1436 // Boolean | 1462 // Boolean |
1437 | 1463 |
1438 function BooleanConstructor(x) { | 1464 function BooleanConstructor(x) { |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1845 // Eventually, we should move to a real event queue that allows to maintain | 1871 // Eventually, we should move to a real event queue that allows to maintain |
1846 // relative ordering of different kinds of tasks. | 1872 // relative ordering of different kinds of tasks. |
1847 | 1873 |
1848 RunMicrotasks.runners = new InternalArray; | 1874 RunMicrotasks.runners = new InternalArray; |
1849 | 1875 |
1850 function RunMicrotasks() { | 1876 function RunMicrotasks() { |
1851 while (%SetMicrotaskPending(false)) { | 1877 while (%SetMicrotaskPending(false)) { |
1852 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); | 1878 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); |
1853 } | 1879 } |
1854 } | 1880 } |
OLD | NEW |