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

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: Put back use strict 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
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 =
rossberg 2014/01/09 12:01:28 Nit: obsolete line wrap
1074 %GetNamedInterceptorPropertyNames(obj);
1080 if (!IS_UNDEFINED(namedInterceptorNames)) { 1075 if (!IS_UNDEFINED(namedInterceptorNames)) {
1081 nameArrays.push(namedInterceptorNames); 1076 nameArrays.push(namedInterceptorNames);
1082 } 1077 }
1083 } 1078 }
1084 1079
1085 var propertyNames = 1080 var propertyNames =
1086 %Apply(InternalArray.prototype.concat, 1081 %Apply(InternalArray.prototype.concat,
1087 nameArrays[0], nameArrays, 1, nameArrays.length - 1); 1082 nameArrays[0], nameArrays, 1, nameArrays.length - 1);
1088 1083
1089 // Property names are expected to be unique strings, 1084 // Property names are expected to be unique strings,
1090 // but interceptors can interfere with that assumption. 1085 // but interceptors can interfere with that assumption.
1091 if (interceptorInfo != 0) { 1086 if (interceptorInfo != 0) {
1092 var propertySet = { __proto__: null }; 1087 var seenKeys = { __proto__: null };
1093 var j = 0; 1088 var j = 0;
1094 for (var i = 0; i < propertyNames.length; ++i) { 1089 for (var i = 0; i < propertyNames.length; ++i) {
1095 if (IS_SYMBOL(propertyNames[i])) continue; 1090 var name = propertyNames[i];
1096 var name = ToString(propertyNames[i]); 1091 if (symbolsOnly) {
1097 // We need to check for the exact property value since for intrinsic 1092 if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue;
1098 // properties like toString if(propertySet["toString"]) will always 1093 } else {
1099 // succeed. 1094 if (IS_SYMBOL(name)) continue;
1100 if (propertySet[name] === true) { 1095 name = ToString(name);
1101 continue;
1102 } 1096 }
1103 propertySet[name] = true; 1097 if (seenKeys[name]) continue;
1098 seenKeys[name] = true;
1104 propertyNames[j++] = name; 1099 propertyNames[j++] = name;
1105 } 1100 }
1106 propertyNames.length = j; 1101 propertyNames.length = j;
1107 } 1102 }
1108 1103
1109 return propertyNames; 1104 return propertyNames;
1110 } 1105 }
1111 1106
1112 1107
1108 // ES5 section 15.2.3.4.
1109 function ObjectGetOwnPropertyNames(obj) {
1110 if (!IS_SPEC_OBJECT(obj)) {
1111 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1112 }
1113 // Special handling for proxies.
1114 if (%IsJSProxy(obj)) {
1115 var handler = %GetHandler(obj);
1116 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1117 return ToNameArray(names, "getOwnPropertyNames", false);
1118 }
1119
1120 return ObjectGetOwnPropertyKeys(obj, false);
1121 }
1122
1123
1113 // ES5 section 15.2.3.5. 1124 // ES5 section 15.2.3.5.
1114 function ObjectCreate(proto, properties) { 1125 function ObjectCreate(proto, properties) {
1115 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 1126 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
1116 throw MakeTypeError("proto_object_or_null", [proto]); 1127 throw MakeTypeError("proto_object_or_null", [proto]);
1117 } 1128 }
1118 var obj = { __proto__: proto }; 1129 var obj = { __proto__: proto };
1119 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); 1130 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties);
1120 return obj; 1131 return obj;
1121 } 1132 }
1122 1133
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 // Set up non-enumerable functions in the Object object. 1423 // Set up non-enumerable functions in the Object object.
1413 InstallFunctions($Object, DONT_ENUM, $Array( 1424 InstallFunctions($Object, DONT_ENUM, $Array(
1414 "keys", ObjectKeys, 1425 "keys", ObjectKeys,
1415 "create", ObjectCreate, 1426 "create", ObjectCreate,
1416 "defineProperty", ObjectDefineProperty, 1427 "defineProperty", ObjectDefineProperty,
1417 "defineProperties", ObjectDefineProperties, 1428 "defineProperties", ObjectDefineProperties,
1418 "freeze", ObjectFreeze, 1429 "freeze", ObjectFreeze,
1419 "getPrototypeOf", ObjectGetPrototypeOf, 1430 "getPrototypeOf", ObjectGetPrototypeOf,
1420 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1431 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1421 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1432 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1433 // getOwnPropertySymbols is added in symbol.js.
1422 "is", ObjectIs, 1434 "is", ObjectIs,
1423 "isExtensible", ObjectIsExtensible, 1435 "isExtensible", ObjectIsExtensible,
1424 "isFrozen", ObjectIsFrozen, 1436 "isFrozen", ObjectIsFrozen,
1425 "isSealed", ObjectIsSealed, 1437 "isSealed", ObjectIsSealed,
1426 "preventExtensions", ObjectPreventExtension, 1438 "preventExtensions", ObjectPreventExtension,
1427 "seal", ObjectSeal 1439 "seal", ObjectSeal
1440 // deliverChangeRecords, getNotifier, observe and unobserve are added
1441 // in object-observe.js.
1428 )); 1442 ));
1429 } 1443 }
1430 1444
1431 SetUpObject(); 1445 SetUpObject();
1432 1446
1433 1447
1434 // ---------------------------------------------------------------------------- 1448 // ----------------------------------------------------------------------------
1435 // Boolean 1449 // Boolean
1436 1450
1437 function BooleanConstructor(x) { 1451 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 1858 // Eventually, we should move to a real event queue that allows to maintain
1845 // relative ordering of different kinds of tasks. 1859 // relative ordering of different kinds of tasks.
1846 1860
1847 RunMicrotasks.runners = new InternalArray; 1861 RunMicrotasks.runners = new InternalArray;
1848 1862
1849 function RunMicrotasks() { 1863 function RunMicrotasks() {
1850 while (%SetMicrotaskPending(false)) { 1864 while (%SetMicrotaskPending(false)) {
1851 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); 1865 for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i]();
1852 } 1866 }
1853 } 1867 }
OLDNEW
« src/runtime.cc ('K') | « src/symbol.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698