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

Side by Side Diff: src/v8natives.js

Issue 108083005: ES6: Add Object.getOwnPropertySymbols (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment and formatting based on code review Created 6 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « src/symbol.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
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 // 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 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 } 1030 }
1031 array[index] = s; 1031 array[index] = s;
1032 ++realLength; 1032 ++realLength;
1033 names[s] = 0; 1033 names[s] = 0;
1034 } 1034 }
1035 array.length = realLength; 1035 array.length = realLength;
1036 return array; 1036 return array;
1037 } 1037 }
1038 1038
1039 1039
1040 // ES5 section 15.2.3.4. 1040 function ObjectGetOwnPropertyKeys(obj, symbolsOnly) {
1041 function ObjectGetOwnPropertyNames(obj) {
1042 if (!IS_SPEC_OBJECT(obj)) {
1043 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1044 }
1045 // Special handling for proxies.
1046 if (%IsJSProxy(obj)) {
1047 var handler = %GetHandler(obj);
1048 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1049 return ToNameArray(names, "getOwnPropertyNames", false);
1050 }
1051
1052 var nameArrays = new InternalArray(); 1041 var nameArrays = new InternalArray();
1042 var filter = symbolsOnly ?
1043 PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL :
1044 PROPERTY_ATTRIBUTES_SYMBOLIC;
1053 1045
1054 // Find all the indexed properties. 1046 // Find all the indexed properties.
1055 1047
1056 // Get the local element names. 1048 // Only get the local element names if we want to include string keys.
1057 var localElementNames = %GetLocalElementNames(obj); 1049 if (!symbolsOnly) {
1058 for (var i = 0; i < localElementNames.length; ++i) { 1050 var localElementNames = %GetLocalElementNames(obj);
1059 localElementNames[i] = %_NumberToString(localElementNames[i]); 1051 for (var i = 0; i < localElementNames.length; ++i) {
1060 } 1052 localElementNames[i] = %_NumberToString(localElementNames[i]);
1061 nameArrays.push(localElementNames); 1053 }
1054 nameArrays.push(localElementNames);
1062 1055
1063 // Get names for indexed interceptor properties. 1056 // Get names for indexed interceptor properties.
1064 var interceptorInfo = %GetInterceptorInfo(obj); 1057 var interceptorInfo = %GetInterceptorInfo(obj);
1065 if ((interceptorInfo & 1) != 0) { 1058 if ((interceptorInfo & 1) != 0) {
1066 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); 1059 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
1067 if (!IS_UNDEFINED(indexedInterceptorNames)) { 1060 if (!IS_UNDEFINED(indexedInterceptorNames)) {
1068 nameArrays.push(indexedInterceptorNames); 1061 nameArrays.push(indexedInterceptorNames);
1062 }
1069 } 1063 }
1070 } 1064 }
1071 1065
1072 // Find all the named properties. 1066 // Find all the named properties.
1073 1067
1074 // Get the local property names. 1068 // Get the local property names.
1075 nameArrays.push(%GetLocalPropertyNames(obj, false)); 1069 nameArrays.push(%GetLocalPropertyNames(obj, filter));
1076 1070
1077 // Get names for named interceptor properties if any. 1071 // Get names for named interceptor properties if any.
1078 if ((interceptorInfo & 2) != 0) { 1072 if ((interceptorInfo & 2) != 0) {
1079 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj); 1073 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj);
1080 if (!IS_UNDEFINED(namedInterceptorNames)) { 1074 if (!IS_UNDEFINED(namedInterceptorNames)) {
1081 nameArrays.push(namedInterceptorNames); 1075 nameArrays.push(namedInterceptorNames);
1082 } 1076 }
1083 } 1077 }
1084 1078
1085 var propertyNames = 1079 var propertyNames =
1086 %Apply(InternalArray.prototype.concat, 1080 %Apply(InternalArray.prototype.concat,
1087 nameArrays[0], nameArrays, 1, nameArrays.length - 1); 1081 nameArrays[0], nameArrays, 1, nameArrays.length - 1);
1088 1082
1089 // Property names are expected to be unique strings, 1083 // Property names are expected to be unique strings,
1090 // but interceptors can interfere with that assumption. 1084 // but interceptors can interfere with that assumption.
1091 if (interceptorInfo != 0) { 1085 if (interceptorInfo != 0) {
1092 var propertySet = { __proto__: null }; 1086 var seenKeys = { __proto__: null };
1093 var j = 0; 1087 var j = 0;
1094 for (var i = 0; i < propertyNames.length; ++i) { 1088 for (var i = 0; i < propertyNames.length; ++i) {
1095 if (IS_SYMBOL(propertyNames[i])) continue; 1089 var name = propertyNames[i];
1096 var name = ToString(propertyNames[i]); 1090 if (symbolsOnly) {
1097 // We need to check for the exact property value since for intrinsic 1091 if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue;
1098 // properties like toString if(propertySet["toString"]) will always 1092 } else {
1099 // succeed. 1093 if (IS_SYMBOL(name)) continue;
1100 if (propertySet[name] === true) { 1094 name = ToString(name);
1101 continue;
1102 } 1095 }
1103 propertySet[name] = true; 1096 if (seenKeys[name]) continue;
1097 seenKeys[name] = true;
1104 propertyNames[j++] = name; 1098 propertyNames[j++] = name;
1105 } 1099 }
1106 propertyNames.length = j; 1100 propertyNames.length = j;
1107 } 1101 }
1108 1102
1109 return propertyNames; 1103 return propertyNames;
1110 } 1104 }
1111 1105
1112 1106
1107 // ES5 section 15.2.3.4.
1108 function ObjectGetOwnPropertyNames(obj) {
1109 if (!IS_SPEC_OBJECT(obj)) {
1110 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1111 }
1112 // Special handling for proxies.
1113 if (%IsJSProxy(obj)) {
1114 var handler = %GetHandler(obj);
1115 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1116 return ToNameArray(names, "getOwnPropertyNames", false);
1117 }
1118
1119 return ObjectGetOwnPropertyKeys(obj, false);
1120 }
1121
1122
1113 // ES5 section 15.2.3.5. 1123 // ES5 section 15.2.3.5.
1114 function ObjectCreate(proto, properties) { 1124 function ObjectCreate(proto, properties) {
1115 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 1125 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
1116 throw MakeTypeError("proto_object_or_null", [proto]); 1126 throw MakeTypeError("proto_object_or_null", [proto]);
1117 } 1127 }
1118 var obj = { __proto__: proto }; 1128 var obj = { __proto__: proto };
1119 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); 1129 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties);
1120 return obj; 1130 return obj;
1121 } 1131 }
1122 1132
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 // Set up non-enumerable functions in the Object object. 1422 // Set up non-enumerable functions in the Object object.
1413 InstallFunctions($Object, DONT_ENUM, $Array( 1423 InstallFunctions($Object, DONT_ENUM, $Array(
1414 "keys", ObjectKeys, 1424 "keys", ObjectKeys,
1415 "create", ObjectCreate, 1425 "create", ObjectCreate,
1416 "defineProperty", ObjectDefineProperty, 1426 "defineProperty", ObjectDefineProperty,
1417 "defineProperties", ObjectDefineProperties, 1427 "defineProperties", ObjectDefineProperties,
1418 "freeze", ObjectFreeze, 1428 "freeze", ObjectFreeze,
1419 "getPrototypeOf", ObjectGetPrototypeOf, 1429 "getPrototypeOf", ObjectGetPrototypeOf,
1420 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1430 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1421 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1431 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1432 // getOwnPropertySymbols is added in symbol.js.
1422 "is", ObjectIs, 1433 "is", ObjectIs,
1423 "isExtensible", ObjectIsExtensible, 1434 "isExtensible", ObjectIsExtensible,
1424 "isFrozen", ObjectIsFrozen, 1435 "isFrozen", ObjectIsFrozen,
1425 "isSealed", ObjectIsSealed, 1436 "isSealed", ObjectIsSealed,
1426 "preventExtensions", ObjectPreventExtension, 1437 "preventExtensions", ObjectPreventExtension,
1427 "seal", ObjectSeal 1438 "seal", ObjectSeal
1439 // deliverChangeRecords, getNotifier, observe and unobserve are added
1440 // in object-observe.js.
1428 )); 1441 ));
1429 } 1442 }
1430 1443
1431 SetUpObject(); 1444 SetUpObject();
1432 1445
1433 1446
1434 // ---------------------------------------------------------------------------- 1447 // ----------------------------------------------------------------------------
1435 // Boolean 1448 // Boolean
1436 1449
1437 function BooleanConstructor(x) { 1450 function BooleanConstructor(x) {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 // Eventually, we should move to a real event queue that allows to maintain 1857 // Eventually, we should move to a real event queue that allows to maintain
1845 // relative ordering of different kinds of tasks. 1858 // relative ordering of different kinds of tasks.
1846 1859
1847 RunMicrotasks.runners = new InternalArray; 1860 RunMicrotasks.runners = new InternalArray;
1848 1861
1849 function RunMicrotasks() { 1862 function RunMicrotasks() {
1850 while (%SetMicrotaskPending(false)) { 1863 while (%SetMicrotaskPending(false)) {
1851 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); 1864 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i]();
1852 } 1865 }
1853 } 1866 }
OLDNEW
« no previous file with comments | « src/symbol.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698