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

Side by Side Diff: src/v8natives.js

Issue 557023002: Refactor ObjectGetOwnPropertyKeys to accept bitmask rather than boolean (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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') | no next file » | 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file relies on the fact that the following declarations have been made 5 // This file relies on the fact that the following declarations have been made
6 // in runtime.js: 6 // in runtime.js:
7 // var $Object = global.Object; 7 // var $Object = global.Object;
8 // var $Boolean = global.Boolean; 8 // var $Boolean = global.Boolean;
9 // var $Number = global.Number; 9 // var $Number = global.Number;
10 // var $Function = global.Function; 10 // var $Function = global.Function;
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 function ObjectGetOwnPropertyKeys(obj, symbolsOnly) { 1041 function ObjectGetOwnPropertyKeys(obj, filter) {
1042 var nameArrays = new InternalArray(); 1042 var nameArrays = new InternalArray();
1043 var filter = symbolsOnly ? 1043 filter = (filter || PROPERTY_ATTRIBUTES_NONE)
1044 PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL : 1044 | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
1045 PROPERTY_ATTRIBUTES_SYMBOLIC;
1046 1045
1047 // Find all the indexed properties. 1046 // Find all the indexed properties.
1048 1047
1049 // Only get own element names if we want to include string keys. 1048 // Only get own element names if we want to include string keys.
1050 if (!symbolsOnly) { 1049 if ((filter & PROPERTY_ATTRIBUTES_STRING) === 0) {
1051 var ownElementNames = %GetOwnElementNames(obj); 1050 var ownElementNames = %GetOwnElementNames(obj);
1052 for (var i = 0; i < ownElementNames.length; ++i) { 1051 for (var i = 0; i < ownElementNames.length; ++i) {
1053 ownElementNames[i] = %_NumberToString(ownElementNames[i]); 1052 ownElementNames[i] = %_NumberToString(ownElementNames[i]);
1054 } 1053 }
1055 nameArrays.push(ownElementNames); 1054 nameArrays.push(ownElementNames);
1056 1055
1057 // Get names for indexed interceptor properties. 1056 // Get names for indexed interceptor properties.
1058 var interceptorInfo = %GetInterceptorInfo(obj); 1057 var interceptorInfo = %GetInterceptorInfo(obj);
1059 if ((interceptorInfo & 1) != 0) { 1058 if ((interceptorInfo & 1) != 0) {
1060 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); 1059 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
(...skipping 21 matching lines...) Expand all
1082 %Apply(InternalArray.prototype.concat, 1081 %Apply(InternalArray.prototype.concat,
1083 nameArrays[0], nameArrays, 1, nameArrays.length - 1); 1082 nameArrays[0], nameArrays, 1, nameArrays.length - 1);
1084 1083
1085 // Property names are expected to be unique strings, 1084 // Property names are expected to be unique strings,
1086 // but interceptors can interfere with that assumption. 1085 // but interceptors can interfere with that assumption.
1087 if (interceptorInfo != 0) { 1086 if (interceptorInfo != 0) {
1088 var seenKeys = { __proto__: null }; 1087 var seenKeys = { __proto__: null };
1089 var j = 0; 1088 var j = 0;
1090 for (var i = 0; i < propertyNames.length; ++i) { 1089 for (var i = 0; i < propertyNames.length; ++i) {
1091 var name = propertyNames[i]; 1090 var name = propertyNames[i];
1092 if (symbolsOnly) { 1091
1093 if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue; 1092 if (IS_PRIVATE(name)) continue;
arv (Not doing code reviews) 2014/09/09 20:56:53 IS_PRIVATE is only true if IS_SYMBOL is also true
1093 if (IS_SYMBOL(name)) {
1094 if (filter & PROPERTY_ATTRIBUTES_SYMBOLIC)
1095 continue;
arv (Not doing code reviews) 2014/09/09 20:56:53 fits on previous line V8 style is to always use {
1096 } else if (filter & PROPERTY_ATTRIBUTES_STRING) {
1097 continue;
1094 } else { 1098 } else {
1095 if (IS_SYMBOL(name)) continue; 1099 name = ToSTring(name);
arv (Not doing code reviews) 2014/09/09 20:56:53 typo
1096 name = ToString(name);
1097 } 1100 }
1101
1098 if (seenKeys[name]) continue; 1102 if (seenKeys[name]) continue;
1099 seenKeys[name] = true; 1103 seenKeys[name] = true;
1100 propertyNames[j++] = name; 1104 propertyNames[j++] = name;
1101 } 1105 }
1102 propertyNames.length = j; 1106 propertyNames.length = j;
1103 } 1107 }
1104 1108
1105 return propertyNames; 1109 return propertyNames;
1106 } 1110 }
1107 1111
1108 1112
1109 // ES5 section 15.2.3.4. 1113 // ES5 section 15.2.3.4.
1110 function ObjectGetOwnPropertyNames(obj) { 1114 function ObjectGetOwnPropertyNames(obj) {
1111 if (!IS_SPEC_OBJECT(obj)) { 1115 if (!IS_SPEC_OBJECT(obj)) {
1112 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); 1116 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1113 } 1117 }
1114 // Special handling for proxies. 1118 // Special handling for proxies.
1115 if (%IsJSProxy(obj)) { 1119 if (%IsJSProxy(obj)) {
1116 var handler = %GetHandler(obj); 1120 var handler = %GetHandler(obj);
1117 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); 1121 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1118 return ToNameArray(names, "getOwnPropertyNames", false); 1122 return ToNameArray(names, "getOwnPropertyNames", false);
1119 } 1123 }
1120 1124
1121 return ObjectGetOwnPropertyKeys(obj, false); 1125 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC);
1122 } 1126 }
1123 1127
1124 1128
1125 // ES5 section 15.2.3.5. 1129 // ES5 section 15.2.3.5.
1126 function ObjectCreate(proto, properties) { 1130 function ObjectCreate(proto, properties) {
1127 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 1131 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
1128 throw MakeTypeError("proto_object_or_null", [proto]); 1132 throw MakeTypeError("proto_object_or_null", [proto]);
1129 } 1133 }
1130 var obj = {}; 1134 var obj = {};
1131 %InternalSetPrototype(obj, proto); 1135 %InternalSetPrototype(obj, proto);
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 } 1905 }
1902 if (!IS_SPEC_FUNCTION(method)) { 1906 if (!IS_SPEC_FUNCTION(method)) {
1903 throw MakeTypeError('not_iterable', [obj]); 1907 throw MakeTypeError('not_iterable', [obj]);
1904 } 1908 }
1905 var iterator = %_CallFunction(obj, method); 1909 var iterator = %_CallFunction(obj, method);
1906 if (!IS_SPEC_OBJECT(iterator)) { 1910 if (!IS_SPEC_OBJECT(iterator)) {
1907 throw MakeTypeError('not_an_iterator', [iterator]); 1911 throw MakeTypeError('not_an_iterator', [iterator]);
1908 } 1912 }
1909 return iterator; 1913 return iterator;
1910 } 1914 }
OLDNEW
« no previous file with comments | « src/symbol.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698