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, type) { |
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(); |
1054 | 1043 |
1055 // Find all the indexed properties. | 1044 // Find all the indexed properties. |
1056 | 1045 |
1057 // Get the local element names. | 1046 // Only get the local element names if we want to include string keys. |
1058 var localElementNames = %GetLocalElementNames(obj); | 1047 if (type == PROPERTY_KEY_STRING) { |
1059 for (var i = 0; i < localElementNames.length; ++i) { | 1048 var localElementNames = %GetLocalElementNames(obj); |
1060 localElementNames[i] = %_NumberToString(localElementNames[i]); | 1049 for (var i = 0; i < localElementNames.length; ++i) { |
1061 } | 1050 localElementNames[i] = %_NumberToString(localElementNames[i]); |
1062 nameArrays.push(localElementNames); | 1051 } |
| 1052 nameArrays.push(localElementNames); |
1063 | 1053 |
1064 // Get names for indexed interceptor properties. | 1054 // Get names for indexed interceptor properties. |
1065 var interceptorInfo = %GetInterceptorInfo(obj); | 1055 var interceptorInfo = %GetInterceptorInfo(obj); |
1066 if ((interceptorInfo & 1) != 0) { | 1056 if ((interceptorInfo & 1) != 0) { |
1067 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); | 1057 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); |
1068 if (!IS_UNDEFINED(indexedInterceptorNames)) { | 1058 if (!IS_UNDEFINED(indexedInterceptorNames)) { |
1069 nameArrays.push(indexedInterceptorNames); | 1059 nameArrays.push(indexedInterceptorNames); |
| 1060 } |
1070 } | 1061 } |
1071 } | 1062 } |
1072 | 1063 |
1073 // Find all the named properties. | 1064 // Find all the named properties. |
1074 | 1065 |
1075 // Get the local property names. | 1066 // Get the local property names. |
1076 nameArrays.push(%GetLocalPropertyNames(obj, false)); | 1067 nameArrays.push(%GetLocalPropertyNames(obj, type)); |
1077 | 1068 |
1078 // Get names for named interceptor properties if any. | 1069 // Get names for named interceptor properties if any. |
1079 if ((interceptorInfo & 2) != 0) { | 1070 if ((interceptorInfo & 2) != 0) { |
1080 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj); | 1071 var namedInterceptorNames = |
| 1072 %GetNamedInterceptorPropertyNames(obj, type); |
1081 if (!IS_UNDEFINED(namedInterceptorNames)) { | 1073 if (!IS_UNDEFINED(namedInterceptorNames)) { |
1082 nameArrays.push(namedInterceptorNames); | 1074 nameArrays.push(namedInterceptorNames); |
1083 } | 1075 } |
1084 } | 1076 } |
1085 | 1077 |
1086 var propertyNames = | 1078 var propertyNames = |
1087 %Apply(InternalArray.prototype.concat, | 1079 %Apply(InternalArray.prototype.concat, |
1088 nameArrays[0], nameArrays, 1, nameArrays.length - 1); | 1080 nameArrays[0], nameArrays, 1, nameArrays.length - 1); |
1089 | 1081 |
1090 // Property names are expected to be unique strings, | 1082 // Property names are expected to be unique strings, |
1091 // but interceptors can interfere with that assumption. | 1083 // but interceptors can interfere with that assumption. |
1092 if (interceptorInfo != 0) { | 1084 if (interceptorInfo != 0) { |
1093 var propertySet = { __proto__: null }; | 1085 var seenNames = { __proto__: null }; |
1094 var j = 0; | 1086 var j = 0; |
1095 for (var i = 0; i < propertyNames.length; ++i) { | 1087 for (var i = 0; i < propertyNames.length; ++i) { |
1096 if (IS_SYMBOL(propertyNames[i])) continue; | 1088 var name = propertyNames[i]; |
1097 var name = ToString(propertyNames[i]); | 1089 if (type == PROPERTY_KEY_STRING) { |
1098 // We need to check for the exact property value since for intrinsic | 1090 name = ToString(name); |
1099 // properties like toString if(propertySet["toString"]) will always | |
1100 // succeed. | |
1101 if (propertySet[name] === true) { | |
1102 continue; | |
1103 } | 1091 } |
1104 propertySet[name] = true; | 1092 if (seenNames[name]) continue; |
| 1093 seenNames[name] = true; |
1105 propertyNames[j++] = name; | 1094 propertyNames[j++] = name; |
1106 } | 1095 } |
1107 propertyNames.length = j; | 1096 propertyNames.length = j; |
1108 } | 1097 } |
1109 | 1098 |
1110 return propertyNames; | 1099 return propertyNames; |
1111 } | 1100 } |
1112 | 1101 |
1113 | 1102 |
| 1103 // ES6 19.1.2.8 |
| 1104 function ObjectGetOwnPropertySymbols(obj) { |
| 1105 if (!IS_SPEC_OBJECT(obj)) { |
| 1106 throw MakeTypeError("called_on_non_object", |
| 1107 ["Object.getOwnPropertySymbols"]); |
| 1108 } |
| 1109 |
| 1110 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
| 1111 |
| 1112 return ObjectGetOwnPropertyKeys(obj, PROPERTY_KEY_SYMBOL); |
| 1113 } |
| 1114 |
| 1115 // ES5 section 15.2.3.4. |
| 1116 function ObjectGetOwnPropertyNames(obj) { |
| 1117 if (!IS_SPEC_OBJECT(obj)) { |
| 1118 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); |
| 1119 } |
| 1120 // Special handling for proxies. |
| 1121 if (%IsJSProxy(obj)) { |
| 1122 var handler = %GetHandler(obj); |
| 1123 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); |
| 1124 return ToNameArray(names, "getOwnPropertyNames", false); |
| 1125 } |
| 1126 |
| 1127 return ObjectGetOwnPropertyKeys(obj, PROPERTY_KEY_STRING); |
| 1128 } |
| 1129 |
| 1130 |
1114 // ES5 section 15.2.3.5. | 1131 // ES5 section 15.2.3.5. |
1115 function ObjectCreate(proto, properties) { | 1132 function ObjectCreate(proto, properties) { |
1116 if (!IS_SPEC_OBJECT(proto) && proto !== null) { | 1133 if (!IS_SPEC_OBJECT(proto) && proto !== null) { |
1117 throw MakeTypeError("proto_object_or_null", [proto]); | 1134 throw MakeTypeError("proto_object_or_null", [proto]); |
1118 } | 1135 } |
1119 var obj = { __proto__: proto }; | 1136 var obj = { __proto__: proto }; |
1120 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 1137 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
1121 return obj; | 1138 return obj; |
1122 } | 1139 } |
1123 | 1140 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 // Set up non-enumerable functions in the Object object. | 1430 // Set up non-enumerable functions in the Object object. |
1414 InstallFunctions($Object, DONT_ENUM, $Array( | 1431 InstallFunctions($Object, DONT_ENUM, $Array( |
1415 "keys", ObjectKeys, | 1432 "keys", ObjectKeys, |
1416 "create", ObjectCreate, | 1433 "create", ObjectCreate, |
1417 "defineProperty", ObjectDefineProperty, | 1434 "defineProperty", ObjectDefineProperty, |
1418 "defineProperties", ObjectDefineProperties, | 1435 "defineProperties", ObjectDefineProperties, |
1419 "freeze", ObjectFreeze, | 1436 "freeze", ObjectFreeze, |
1420 "getPrototypeOf", ObjectGetPrototypeOf, | 1437 "getPrototypeOf", ObjectGetPrototypeOf, |
1421 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1438 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
1422 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1439 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1440 // getOwnPropertySymbols is added in symbol.js. |
1423 "is", ObjectIs, | 1441 "is", ObjectIs, |
1424 "isExtensible", ObjectIsExtensible, | 1442 "isExtensible", ObjectIsExtensible, |
1425 "isFrozen", ObjectIsFrozen, | 1443 "isFrozen", ObjectIsFrozen, |
1426 "isSealed", ObjectIsSealed, | 1444 "isSealed", ObjectIsSealed, |
1427 "preventExtensions", ObjectPreventExtension, | 1445 "preventExtensions", ObjectPreventExtension, |
1428 "seal", ObjectSeal | 1446 "seal", ObjectSeal |
| 1447 // observe is added in object-observe.js. |
1429 )); | 1448 )); |
1430 } | 1449 } |
1431 | 1450 |
1432 SetUpObject(); | 1451 SetUpObject(); |
1433 | 1452 |
1434 | 1453 |
1435 // ---------------------------------------------------------------------------- | 1454 // ---------------------------------------------------------------------------- |
1436 // Boolean | 1455 // Boolean |
1437 | 1456 |
1438 function BooleanConstructor(x) { | 1457 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 | 1864 // Eventually, we should move to a real event queue that allows to maintain |
1846 // relative ordering of different kinds of tasks. | 1865 // relative ordering of different kinds of tasks. |
1847 | 1866 |
1848 RunMicrotasks.runners = new InternalArray; | 1867 RunMicrotasks.runners = new InternalArray; |
1849 | 1868 |
1850 function RunMicrotasks() { | 1869 function RunMicrotasks() { |
1851 while (%SetMicrotaskPending(false)) { | 1870 while (%SetMicrotaskPending(false)) { |
1852 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); | 1871 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); |
1853 } | 1872 } |
1854 } | 1873 } |
OLD | NEW |