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

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: Fix nits Created 6 years, 1 month 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 |= PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL;
1044 PROPERTY_ATTRIBUTES_STRING | PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL :
1045 PROPERTY_ATTRIBUTES_SYMBOLIC;
1046 1044
1047 // Find all the indexed properties. 1045 // Find all the indexed properties.
1048 1046
1049 // Only get own element names if we want to include string keys. 1047 // Only get own element names if we want to include string keys.
1050 if (!symbolsOnly) { 1048 if ((filter & PROPERTY_ATTRIBUTES_STRING) === 0) {
1051 var ownElementNames = %GetOwnElementNames(obj); 1049 var ownElementNames = %GetOwnElementNames(obj);
1052 for (var i = 0; i < ownElementNames.length; ++i) { 1050 for (var i = 0; i < ownElementNames.length; ++i) {
1053 ownElementNames[i] = %_NumberToString(ownElementNames[i]); 1051 ownElementNames[i] = %_NumberToString(ownElementNames[i]);
1054 } 1052 }
1055 nameArrays.push(ownElementNames); 1053 nameArrays.push(ownElementNames);
1056 1054
1057 // Get names for indexed interceptor properties. 1055 // Get names for indexed interceptor properties.
1058 var interceptorInfo = %GetInterceptorInfo(obj); 1056 var interceptorInfo = %GetInterceptorInfo(obj);
1059 if ((interceptorInfo & 1) != 0) { 1057 if ((interceptorInfo & 1) != 0) {
1060 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj); 1058 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
(...skipping 21 matching lines...) Expand all
1082 %Apply(InternalArray.prototype.concat, 1080 %Apply(InternalArray.prototype.concat,
1083 nameArrays[0], nameArrays, 1, nameArrays.length - 1); 1081 nameArrays[0], nameArrays, 1, nameArrays.length - 1);
1084 1082
1085 // Property names are expected to be unique strings, 1083 // Property names are expected to be unique strings,
1086 // but interceptors can interfere with that assumption. 1084 // but interceptors can interfere with that assumption.
1087 if (interceptorInfo != 0) { 1085 if (interceptorInfo != 0) {
1088 var seenKeys = { __proto__: null }; 1086 var seenKeys = { __proto__: null };
1089 var j = 0; 1087 var j = 0;
1090 for (var i = 0; i < propertyNames.length; ++i) { 1088 for (var i = 0; i < propertyNames.length; ++i) {
1091 var name = propertyNames[i]; 1089 var name = propertyNames[i];
1092 if (symbolsOnly) { 1090 if (IS_SYMBOL(name)) {
1093 if (!IS_SYMBOL(name) || IS_PRIVATE(name)) continue; 1091 if ((filter & PROPERTY_ATTRIBUTES_SYMBOLIC) || IS_PRIVATE(name)) {
1092 continue;
1093 }
1094 } else { 1094 } else {
1095 if (IS_SYMBOL(name)) continue; 1095 if (filter & PROPERTY_ATTRIBUTES_STRING) continue;
1096 name = ToString(name); 1096 name = ToString(name);
1097 } 1097 }
1098 if (seenKeys[name]) continue; 1098 if (seenKeys[name]) continue;
1099 seenKeys[name] = true; 1099 seenKeys[name] = true;
1100 propertyNames[j++] = name; 1100 propertyNames[j++] = name;
1101 } 1101 }
1102 propertyNames.length = j; 1102 propertyNames.length = j;
1103 } 1103 }
1104 1104
1105 return propertyNames; 1105 return propertyNames;
1106 } 1106 }
1107 1107
1108 1108
1109 // ES5 section 15.2.3.4. 1109 // ES5 section 15.2.3.4.
1110 function ObjectGetOwnPropertyNames(obj) { 1110 function ObjectGetOwnPropertyNames(obj) {
1111 obj = ToObject(obj); 1111 obj = ToObject(obj);
1112 // Special handling for proxies. 1112 // Special handling for proxies.
1113 if (%_IsJSProxy(obj)) { 1113 if (%_IsJSProxy(obj)) {
1114 var handler = %GetHandler(obj); 1114 var handler = %GetHandler(obj);
1115 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED); 1115 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1116 return ToNameArray(names, "getOwnPropertyNames", false); 1116 return ToNameArray(names, "getOwnPropertyNames", false);
1117 } 1117 }
1118 1118
1119 return ObjectGetOwnPropertyKeys(obj, false); 1119 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_SYMBOLIC);
1120 } 1120 }
1121 1121
1122 1122
1123 // ES5 section 15.2.3.5. 1123 // ES5 section 15.2.3.5.
1124 function ObjectCreate(proto, properties) { 1124 function ObjectCreate(proto, properties) {
1125 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 1125 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
1126 throw MakeTypeError("proto_object_or_null", [proto]); 1126 throw MakeTypeError("proto_object_or_null", [proto]);
1127 } 1127 }
1128 var obj = {}; 1128 var obj = {};
1129 %InternalSetPrototype(obj, proto); 1129 %InternalSetPrototype(obj, proto);
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 } 1902 }
1903 if (!IS_SPEC_FUNCTION(method)) { 1903 if (!IS_SPEC_FUNCTION(method)) {
1904 throw MakeTypeError('not_iterable', [obj]); 1904 throw MakeTypeError('not_iterable', [obj]);
1905 } 1905 }
1906 var iterator = %_CallFunction(obj, method); 1906 var iterator = %_CallFunction(obj, method);
1907 if (!IS_SPEC_OBJECT(iterator)) { 1907 if (!IS_SPEC_OBJECT(iterator)) {
1908 throw MakeTypeError('not_an_iterator', [iterator]); 1908 throw MakeTypeError('not_an_iterator', [iterator]);
1909 } 1909 }
1910 return iterator; 1910 return iterator;
1911 } 1911 }
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