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

Side by Side Diff: src/v8natives.js

Issue 12342003: Use InternalArray in Object.getOwnPropertyNames() implementation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reworked concat usage Created 7 years, 10 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 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 if (!IS_SPEC_OBJECT(obj)) { 1007 if (!IS_SPEC_OBJECT(obj)) {
1008 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); 1008 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1009 } 1009 }
1010 // Special handling for proxies. 1010 // Special handling for proxies.
1011 if (%IsJSProxy(obj)) { 1011 if (%IsJSProxy(obj)) {
1012 var handler = %GetHandler(obj); 1012 var handler = %GetHandler(obj);
1013 var names = CallTrap0(handler, "getOwnPropertyNames", void 0); 1013 var names = CallTrap0(handler, "getOwnPropertyNames", void 0);
1014 return ToStringArray(names, "getOwnPropertyNames"); 1014 return ToStringArray(names, "getOwnPropertyNames");
1015 } 1015 }
1016 1016
1017 var nameArrays = new InternalArray();
1018
1017 // Find all the indexed properties. 1019 // Find all the indexed properties.
1018 1020
1019 // Get the local element names. 1021 // Get the local element names.
1020 var propertyNames = %GetLocalElementNames(obj); 1022 var localElementNames = %GetLocalElementNames(obj);
1021 for (var i = 0; i < propertyNames.length; ++i) { 1023 for (var i = 0; i < localElementNames.length; ++i) {
1022 propertyNames[i] = %_NumberToString(propertyNames[i]); 1024 localElementNames[i] = %_NumberToString(localElementNames[i]);
1023 } 1025 }
1026 nameArrays.push(localElementNames);
1024 1027
1025 // Get names for indexed interceptor properties. 1028 // Get names for indexed interceptor properties.
1026 var interceptorInfo = %GetInterceptorInfo(obj); 1029 var interceptorInfo = %GetInterceptorInfo(obj);
1027 if ((interceptorInfo & 1) != 0) { 1030 if ((interceptorInfo & 1) != 0) {
1028 var indexedInterceptorNames = 1031 var indexedInterceptorNames = %GetIndexedInterceptorElementNames(obj);
1029 %GetIndexedInterceptorElementNames(obj); 1032 if (!IS_UNDEFINED(indexedInterceptorNames)) {
1030 if (indexedInterceptorNames) { 1033 nameArrays.push(indexedInterceptorNames);
1031 propertyNames = propertyNames.concat(indexedInterceptorNames);
1032 } 1034 }
1033 } 1035 }
1034 1036
1035 // Find all the named properties. 1037 // Find all the named properties.
1036 1038
1037 // Get the local property names. 1039 // Get the local property names.
1038 propertyNames = propertyNames.concat(%GetLocalPropertyNames(obj)); 1040 nameArrays.push(%GetLocalPropertyNames(obj));
1039 1041
1040 // Get names for named interceptor properties if any. 1042 // Get names for named interceptor properties if any.
1041 if ((interceptorInfo & 2) != 0) { 1043 if ((interceptorInfo & 2) != 0) {
1042 var namedInterceptorNames = 1044 var namedInterceptorNames = %GetNamedInterceptorPropertyNames(obj);
1043 %GetNamedInterceptorPropertyNames(obj); 1045 if (!IS_UNDEFINED(namedInterceptorNames)) {
1044 if (namedInterceptorNames) { 1046 nameArrays.push(namedInterceptorNames);
1045 propertyNames = propertyNames.concat(namedInterceptorNames);
1046 } 1047 }
1047 } 1048 }
1048 1049
1050 var propertyNames = %Apply(InternalArray.prototype.concat,
1051 new InternalArray(),
1052 nameArrays,
1053 0,
1054 nameArrays.length);
1055
1049 // Property names are expected to be unique strings, 1056 // Property names are expected to be unique strings,
1050 // but interceptors can interfere with that assumption. 1057 // but interceptors can interfere with that assumption.
1051 if (interceptorInfo != 0) { 1058 if (interceptorInfo != 0) {
1052 var propertySet = { __proto__: null }; 1059 var propertySet = { __proto__: null };
1053 var j = 0; 1060 var j = 0;
1054 for (var i = 0; i < propertyNames.length; ++i) { 1061 for (var i = 0; i < propertyNames.length; ++i) {
1055 var name = ToString(propertyNames[i]); 1062 var name = ToString(propertyNames[i]);
1056 // We need to check for the exact property value since for intrinsic 1063 // We need to check for the exact property value since for intrinsic
1057 // properties like toString if(propertySet["toString"]) will always 1064 // properties like toString if(propertySet["toString"]) will always
1058 // succeed. 1065 // succeed.
1059 if (propertySet[name] === true) { 1066 if (propertySet[name] === true) {
1060 continue; 1067 continue;
1061 } 1068 }
1062 propertySet[name] = true; 1069 propertySet[name] = true;
1063 propertyNames[j++] = name; 1070 propertyNames[j++] = name;
1064 } 1071 }
1065 propertyNames.length = j; 1072 propertyNames.length = j;
1066 } 1073 }
1067 1074
1068 return propertyNames; 1075 var result = new $Array();
1076 %MoveArrayContents(propertyNames, result);
Michael Starzinger 2013/03/12 12:09:06 This call to MoveArrayContents has become obsolete
adamk 2013/03/12 18:25:19 Done.
1077 return result;
1069 } 1078 }
1070 1079
1071 1080
1072 // ES5 section 15.2.3.5. 1081 // ES5 section 15.2.3.5.
1073 function ObjectCreate(proto, properties) { 1082 function ObjectCreate(proto, properties) {
1074 if (!IS_SPEC_OBJECT(proto) && proto !== null) { 1083 if (!IS_SPEC_OBJECT(proto) && proto !== null) {
1075 throw MakeTypeError("proto_object_or_null", [proto]); 1084 throw MakeTypeError("proto_object_or_null", [proto]);
1076 } 1085 }
1077 var obj = new $Object(); 1086 var obj = new $Object();
1078 obj.__proto__ = proto; 1087 obj.__proto__ = proto;
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1733
1725 function SetUpFunction() { 1734 function SetUpFunction() {
1726 %CheckIsBootstrapping(); 1735 %CheckIsBootstrapping();
1727 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1736 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1728 "bind", FunctionBind, 1737 "bind", FunctionBind,
1729 "toString", FunctionToString 1738 "toString", FunctionToString
1730 )); 1739 ));
1731 } 1740 }
1732 1741
1733 SetUpFunction(); 1742 SetUpFunction();
OLDNEW
« src/array.js ('K') | « src/array.js ('k') | test/mjsunit/object-get-own-property-names.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698