Chromium Code Reviews| 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 FilterKeyNames(array, symbolsOnly) { |
|
rossberg
2013/12/18 16:50:12
Why can't we fold this into the loop at line 1108,
arv (Not doing code reviews)
2013/12/18 18:07:12
Done.
That would make more sense. And now I under
rossberg
2013/12/19 10:28:04
Yes, sorry if that was too cryptic.
| |
| 1042 function ObjectGetOwnPropertyNames(obj) { | 1042 var result = new InternalArray(); |
| 1043 if (!IS_SPEC_OBJECT(obj)) { | 1043 var j = 0; |
| 1044 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); | 1044 for (var i = 0; i < array.length; i++) { |
| 1045 var key = array[i]; | |
| 1046 if (IS_SYMBOL(key)) { | |
| 1047 if (symbolsOnly && !IS_PRIVATE(key)) { | |
| 1048 result[j++] = key; | |
| 1049 } | |
| 1050 } else if (!symbolsOnly) { | |
| 1051 result[j++] = key; | |
| 1052 } | |
| 1045 } | 1053 } |
| 1046 // Special handling for proxies. | 1054 result.length = j; |
| 1047 if (%IsJSProxy(obj)) { | 1055 return result; |
| 1048 var handler = %GetHandler(obj); | 1056 } |
| 1049 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); | |
| 1050 return ToNameArray(names, "getOwnPropertyNames", false); | |
| 1051 } | |
| 1052 | 1057 |
| 1058 | |
| 1059 function ObjectGetOwnPropertyKeys(obj, symbolsOnly) { | |
| 1053 var nameArrays = new InternalArray(); | 1060 var nameArrays = new InternalArray(); |
| 1061 var filter = symbolsOnly ? | |
| 1062 PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL : | |
| 1063 PROPERTY_ATTRIBUTES_SYMBOLIC; | |
| 1054 | 1064 |
| 1055 // Find all the indexed properties. | 1065 // Find all the indexed properties. |
| 1056 | 1066 |
| 1057 // Get the local element names. | 1067 // Only get the local element names if we want to include string keys. |
| 1058 var localElementNames = %GetLocalElementNames(obj); | 1068 if (!symbolsOnly) { |
| 1059 for (var i = 0; i < localElementNames.length; ++i) { | 1069 var localElementNames = %GetLocalElementNames(obj); |
| 1060 localElementNames[i] = %_NumberToString(localElementNames[i]); | 1070 for (var i = 0; i < localElementNames.length; ++i) { |
| 1061 } | 1071 localElementNames[i] = %_NumberToString(localElementNames[i]); |
| 1062 nameArrays.push(localElementNames); | 1072 } |
| 1073 nameArrays.push(localElementNames); | |
| 1063 | 1074 |
| 1064 // Get names for indexed interceptor properties. | 1075 // Get names for indexed interceptor properties. |
| 1065 var interceptorInfo = %GetInterceptorInfo(obj); | 1076 var interceptorInfo = %GetInterceptorInfo(obj); |
| 1066 if ((interceptorInfo & 1) != 0) { | 1077 if ((interceptorInfo & 1) != 0) { |
| 1067 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); | 1078 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); |
| 1068 if (!IS_UNDEFINED(indexedInterceptorNames)) { | 1079 if (!IS_UNDEFINED(indexedInterceptorNames)) { |
| 1069 nameArrays.push(indexedInterceptorNames); | 1080 nameArrays.push(indexedInterceptorNames); |
| 1081 } | |
| 1070 } | 1082 } |
| 1071 } | 1083 } |
| 1072 | 1084 |
| 1073 // Find all the named properties. | 1085 // Find all the named properties. |
| 1074 | 1086 |
| 1075 // Get the local property names. | 1087 // Get the local property names. |
| 1076 nameArrays.push(%GetLocalPropertyNames(obj, false)); | 1088 nameArrays.push(%GetLocalPropertyNames(obj, filter)); |
| 1077 | 1089 |
| 1078 // Get names for named interceptor properties if any. | 1090 // Get names for named interceptor properties if any. |
| 1079 if ((interceptorInfo & 2) != 0) { | 1091 if ((interceptorInfo & 2) != 0) { |
| 1080 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj); | 1092 var namedInterceptorNames = |
| 1093 %GetNamedInterceptorPropertyNames(obj); | |
| 1081 if (!IS_UNDEFINED(namedInterceptorNames)) { | 1094 if (!IS_UNDEFINED(namedInterceptorNames)) { |
| 1082 nameArrays.push(namedInterceptorNames); | 1095 nameArrays.push(FilterKeyNames(namedInterceptorNames, symbolsOnly)); |
| 1083 } | 1096 } |
| 1084 } | 1097 } |
| 1085 | 1098 |
| 1086 var propertyNames = | 1099 var propertyNames = |
| 1087 %Apply(InternalArray.prototype.concat, | 1100 %Apply(InternalArray.prototype.concat, |
| 1088 nameArrays[0], nameArrays, 1, nameArrays.length - 1); | 1101 nameArrays[0], nameArrays, 1, nameArrays.length - 1); |
| 1089 | 1102 |
| 1090 // Property names are expected to be unique strings, | 1103 // Property names are expected to be unique strings, |
| 1091 // but interceptors can interfere with that assumption. | 1104 // but interceptors can interfere with that assumption. |
| 1092 if (interceptorInfo != 0) { | 1105 if (interceptorInfo != 0) { |
| 1093 var propertySet = { __proto__: null }; | 1106 var seenKeys = { __proto__: null }; |
| 1094 var j = 0; | 1107 var j = 0; |
| 1095 for (var i = 0; i < propertyNames.length; ++i) { | 1108 for (var i = 0; i < propertyNames.length; ++i) { |
| 1096 if (IS_SYMBOL(propertyNames[i])) continue; | 1109 var name = propertyNames[i]; |
| 1097 var name = ToString(propertyNames[i]); | 1110 if (!symbolsOnly) { |
| 1098 // We need to check for the exact property value since for intrinsic | 1111 name = ToString(name); |
| 1099 // properties like toString if(propertySet["toString"]) will always | |
| 1100 // succeed. | |
| 1101 if (propertySet[name] === true) { | |
| 1102 continue; | |
| 1103 } | 1112 } |
| 1104 propertySet[name] = true; | 1113 if (seenKeys[name]) continue; |
| 1114 seenKeys[name] = true; | |
| 1105 propertyNames[j++] = name; | 1115 propertyNames[j++] = name; |
| 1106 } | 1116 } |
| 1107 propertyNames.length = j; | 1117 propertyNames.length = j; |
| 1108 } | 1118 } |
| 1109 | 1119 |
| 1110 return propertyNames; | 1120 return propertyNames; |
| 1111 } | 1121 } |
| 1112 | 1122 |
| 1113 | 1123 |
| 1124 // ES6 19.1.2.8 | |
| 1125 function ObjectGetOwnPropertySymbols(obj) { | |
| 1126 if (!IS_SPEC_OBJECT(obj)) { | |
| 1127 throw MakeTypeError("called_on_non_object", | |
| 1128 ["Object.getOwnPropertySymbols"]); | |
| 1129 } | |
| 1130 | |
| 1131 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | |
| 1132 | |
| 1133 return ObjectGetOwnPropertyKeys(obj, true); | |
| 1134 } | |
| 1135 | |
| 1136 | |
| 1137 // ES5 section 15.2.3.4. | |
| 1138 function ObjectGetOwnPropertyNames(obj) { | |
| 1139 if (!IS_SPEC_OBJECT(obj)) { | |
| 1140 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); | |
| 1141 } | |
| 1142 // Special handling for proxies. | |
| 1143 if (%IsJSProxy(obj)) { | |
| 1144 var handler = %GetHandler(obj); | |
| 1145 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); | |
| 1146 return ToNameArray(names, "getOwnPropertyNames", false); | |
| 1147 } | |
| 1148 | |
| 1149 return ObjectGetOwnPropertyKeys(obj, false); | |
| 1150 } | |
| 1151 | |
| 1152 | |
| 1114 // ES5 section 15.2.3.5. | 1153 // ES5 section 15.2.3.5. |
| 1115 function ObjectCreate(proto, properties) { | 1154 function ObjectCreate(proto, properties) { |
| 1116 if (!IS_SPEC_OBJECT(proto) && proto !== null) { | 1155 if (!IS_SPEC_OBJECT(proto) && proto !== null) { |
| 1117 throw MakeTypeError("proto_object_or_null", [proto]); | 1156 throw MakeTypeError("proto_object_or_null", [proto]); |
| 1118 } | 1157 } |
| 1119 var obj = { __proto__: proto }; | 1158 var obj = { __proto__: proto }; |
| 1120 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 1159 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
| 1121 return obj; | 1160 return obj; |
| 1122 } | 1161 } |
| 1123 | 1162 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1413 // Set up non-enumerable functions in the Object object. | 1452 // Set up non-enumerable functions in the Object object. |
| 1414 InstallFunctions($Object, DONT_ENUM, $Array( | 1453 InstallFunctions($Object, DONT_ENUM, $Array( |
| 1415 "keys", ObjectKeys, | 1454 "keys", ObjectKeys, |
| 1416 "create", ObjectCreate, | 1455 "create", ObjectCreate, |
| 1417 "defineProperty", ObjectDefineProperty, | 1456 "defineProperty", ObjectDefineProperty, |
| 1418 "defineProperties", ObjectDefineProperties, | 1457 "defineProperties", ObjectDefineProperties, |
| 1419 "freeze", ObjectFreeze, | 1458 "freeze", ObjectFreeze, |
| 1420 "getPrototypeOf", ObjectGetPrototypeOf, | 1459 "getPrototypeOf", ObjectGetPrototypeOf, |
| 1421 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1460 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
| 1422 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1461 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1462 // getOwnPropertySymbols is added in symbol.js. | |
| 1423 "is", ObjectIs, | 1463 "is", ObjectIs, |
| 1424 "isExtensible", ObjectIsExtensible, | 1464 "isExtensible", ObjectIsExtensible, |
| 1425 "isFrozen", ObjectIsFrozen, | 1465 "isFrozen", ObjectIsFrozen, |
| 1426 "isSealed", ObjectIsSealed, | 1466 "isSealed", ObjectIsSealed, |
| 1427 "preventExtensions", ObjectPreventExtension, | 1467 "preventExtensions", ObjectPreventExtension, |
| 1428 "seal", ObjectSeal | 1468 "seal", ObjectSeal |
| 1469 // observe is added in object-observe.js. | |
| 1429 )); | 1470 )); |
| 1430 } | 1471 } |
| 1431 | 1472 |
| 1432 SetUpObject(); | 1473 SetUpObject(); |
| 1433 | 1474 |
| 1434 | 1475 |
| 1435 // ---------------------------------------------------------------------------- | 1476 // ---------------------------------------------------------------------------- |
| 1436 // Boolean | 1477 // Boolean |
| 1437 | 1478 |
| 1438 function BooleanConstructor(x) { | 1479 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 | 1886 // Eventually, we should move to a real event queue that allows to maintain |
| 1846 // relative ordering of different kinds of tasks. | 1887 // relative ordering of different kinds of tasks. |
| 1847 | 1888 |
| 1848 RunMicrotasks.runners = new InternalArray; | 1889 RunMicrotasks.runners = new InternalArray; |
| 1849 | 1890 |
| 1850 function RunMicrotasks() { | 1891 function RunMicrotasks() { |
| 1851 while (%SetMicrotaskPending(false)) { | 1892 while (%SetMicrotaskPending(false)) { |
| 1852 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); | 1893 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); |
| 1853 } | 1894 } |
| 1854 } | 1895 } |
| OLD | NEW |