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

Side by Side Diff: src/array.js

Issue 7623011: Implement function proxies (except for their use as constructors). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed second round of comments. Created 9 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/arm/macro-assembler-arm.h ('k') | src/builtins.h » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 202
203 function ConvertToLocaleString(e) { 203 function ConvertToLocaleString(e) {
204 if (e == null) { 204 if (e == null) {
205 return ''; 205 return '';
206 } else { 206 } else {
207 // e_obj's toLocaleString might be overwritten, check if it is a function. 207 // e_obj's toLocaleString might be overwritten, check if it is a function.
208 // Call ToString if toLocaleString is not a function. 208 // Call ToString if toLocaleString is not a function.
209 // See issue 877615. 209 // See issue 877615.
210 var e_obj = ToObject(e); 210 var e_obj = ToObject(e);
211 if (IS_FUNCTION(e_obj.toLocaleString)) 211 if (IS_SPEC_FUNCTION(e_obj.toLocaleString))
212 return ToString(e_obj.toLocaleString()); 212 return ToString(e_obj.toLocaleString());
213 else 213 else
214 return ToString(e); 214 return ToString(e);
215 } 215 }
216 } 216 }
217 217
218 218
219 // This function implements the optimized splice implementation that can use 219 // This function implements the optimized splice implementation that can use
220 // special array operations to handle sparse arrays in a sensible fashion. 220 // special array operations to handle sparse arrays in a sensible fashion.
221 function SmartSlice(array, start_i, del_count, len, deleted_elements) { 221 function SmartSlice(array, start_i, del_count, len, deleted_elements) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 723
724 function ArraySort(comparefn) { 724 function ArraySort(comparefn) {
725 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 725 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
726 throw MakeTypeError("called_on_null_or_undefined", 726 throw MakeTypeError("called_on_null_or_undefined",
727 ["Array.prototype.sort"]); 727 ["Array.prototype.sort"]);
728 } 728 }
729 729
730 // In-place QuickSort algorithm. 730 // In-place QuickSort algorithm.
731 // For short (length <= 22) arrays, insertion sort is used for efficiency. 731 // For short (length <= 22) arrays, insertion sort is used for efficiency.
732 732
733 if (!IS_FUNCTION(comparefn)) { 733 if (!IS_SPEC_FUNCTION(comparefn)) {
734 comparefn = function (x, y) { 734 comparefn = function (x, y) {
735 if (x === y) return 0; 735 if (x === y) return 0;
736 if (%_IsSmi(x) && %_IsSmi(y)) { 736 if (%_IsSmi(x) && %_IsSmi(y)) {
737 return %SmiLexicographicCompare(x, y); 737 return %SmiLexicographicCompare(x, y);
738 } 738 }
739 x = ToString(x); 739 x = ToString(x);
740 y = ToString(y); 740 y = ToString(y);
741 if (x == y) return 0; 741 if (x == y) return 0;
742 else return x < y ? -1 : 1; 742 else return x < y ? -1 : 1;
743 }; 743 };
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 987
988 // The following functions cannot be made efficient on sparse arrays while 988 // The following functions cannot be made efficient on sparse arrays while
989 // preserving the semantics, since the calls to the receiver function can add 989 // preserving the semantics, since the calls to the receiver function can add
990 // or delete elements from the array. 990 // or delete elements from the array.
991 function ArrayFilter(f, receiver) { 991 function ArrayFilter(f, receiver) {
992 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 992 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
993 throw MakeTypeError("called_on_null_or_undefined", 993 throw MakeTypeError("called_on_null_or_undefined",
994 ["Array.prototype.filter"]); 994 ["Array.prototype.filter"]);
995 } 995 }
996 996
997 if (!IS_FUNCTION(f)) { 997 if (!IS_SPEC_FUNCTION(f)) {
998 throw MakeTypeError('called_non_callable', [ f ]); 998 throw MakeTypeError('called_non_callable', [ f ]);
999 } 999 }
1000 // Pull out the length so that modifications to the length in the 1000 // Pull out the length so that modifications to the length in the
1001 // loop will not affect the looping. 1001 // loop will not affect the looping.
1002 var length = ToUint32(this.length); 1002 var length = ToUint32(this.length);
1003 var result = []; 1003 var result = [];
1004 var result_length = 0; 1004 var result_length = 0;
1005 for (var i = 0; i < length; i++) { 1005 for (var i = 0; i < length; i++) {
1006 var current = this[i]; 1006 var current = this[i];
1007 if (!IS_UNDEFINED(current) || i in this) { 1007 if (!IS_UNDEFINED(current) || i in this) {
1008 if (f.call(receiver, current, i, this)) { 1008 if (f.call(receiver, current, i, this)) {
1009 result[result_length++] = current; 1009 result[result_length++] = current;
1010 } 1010 }
1011 } 1011 }
1012 } 1012 }
1013 return result; 1013 return result;
1014 } 1014 }
1015 1015
1016 1016
1017 function ArrayForEach(f, receiver) { 1017 function ArrayForEach(f, receiver) {
1018 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1018 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1019 throw MakeTypeError("called_on_null_or_undefined", 1019 throw MakeTypeError("called_on_null_or_undefined",
1020 ["Array.prototype.forEach"]); 1020 ["Array.prototype.forEach"]);
1021 } 1021 }
1022 1022
1023 if (!IS_FUNCTION(f)) { 1023 if (!IS_SPEC_FUNCTION(f)) {
1024 throw MakeTypeError('called_non_callable', [ f ]); 1024 throw MakeTypeError('called_non_callable', [ f ]);
1025 } 1025 }
1026 // Pull out the length so that modifications to the length in the 1026 // Pull out the length so that modifications to the length in the
1027 // loop will not affect the looping. 1027 // loop will not affect the looping.
1028 var length = TO_UINT32(this.length); 1028 var length = TO_UINT32(this.length);
1029 for (var i = 0; i < length; i++) { 1029 for (var i = 0; i < length; i++) {
1030 var current = this[i]; 1030 var current = this[i];
1031 if (!IS_UNDEFINED(current) || i in this) { 1031 if (!IS_UNDEFINED(current) || i in this) {
1032 f.call(receiver, current, i, this); 1032 f.call(receiver, current, i, this);
1033 } 1033 }
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 1037
1038 // Executes the function once for each element present in the 1038 // Executes the function once for each element present in the
1039 // array until it finds one where callback returns true. 1039 // array until it finds one where callback returns true.
1040 function ArraySome(f, receiver) { 1040 function ArraySome(f, receiver) {
1041 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1041 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1042 throw MakeTypeError("called_on_null_or_undefined", 1042 throw MakeTypeError("called_on_null_or_undefined",
1043 ["Array.prototype.some"]); 1043 ["Array.prototype.some"]);
1044 } 1044 }
1045 1045
1046 if (!IS_FUNCTION(f)) { 1046 if (!IS_SPEC_FUNCTION(f)) {
1047 throw MakeTypeError('called_non_callable', [ f ]); 1047 throw MakeTypeError('called_non_callable', [ f ]);
1048 } 1048 }
1049 // Pull out the length so that modifications to the length in the 1049 // Pull out the length so that modifications to the length in the
1050 // loop will not affect the looping. 1050 // loop will not affect the looping.
1051 var length = TO_UINT32(this.length); 1051 var length = TO_UINT32(this.length);
1052 for (var i = 0; i < length; i++) { 1052 for (var i = 0; i < length; i++) {
1053 var current = this[i]; 1053 var current = this[i];
1054 if (!IS_UNDEFINED(current) || i in this) { 1054 if (!IS_UNDEFINED(current) || i in this) {
1055 if (f.call(receiver, current, i, this)) return true; 1055 if (f.call(receiver, current, i, this)) return true;
1056 } 1056 }
1057 } 1057 }
1058 return false; 1058 return false;
1059 } 1059 }
1060 1060
1061 1061
1062 function ArrayEvery(f, receiver) { 1062 function ArrayEvery(f, receiver) {
1063 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1063 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1064 throw MakeTypeError("called_on_null_or_undefined", 1064 throw MakeTypeError("called_on_null_or_undefined",
1065 ["Array.prototype.every"]); 1065 ["Array.prototype.every"]);
1066 } 1066 }
1067 1067
1068 if (!IS_FUNCTION(f)) { 1068 if (!IS_SPEC_FUNCTION(f)) {
1069 throw MakeTypeError('called_non_callable', [ f ]); 1069 throw MakeTypeError('called_non_callable', [ f ]);
1070 } 1070 }
1071 // Pull out the length so that modifications to the length in the 1071 // Pull out the length so that modifications to the length in the
1072 // loop will not affect the looping. 1072 // loop will not affect the looping.
1073 var length = TO_UINT32(this.length); 1073 var length = TO_UINT32(this.length);
1074 for (var i = 0; i < length; i++) { 1074 for (var i = 0; i < length; i++) {
1075 var current = this[i]; 1075 var current = this[i];
1076 if (!IS_UNDEFINED(current) || i in this) { 1076 if (!IS_UNDEFINED(current) || i in this) {
1077 if (!f.call(receiver, current, i, this)) return false; 1077 if (!f.call(receiver, current, i, this)) return false;
1078 } 1078 }
1079 } 1079 }
1080 return true; 1080 return true;
1081 } 1081 }
1082 1082
1083 function ArrayMap(f, receiver) { 1083 function ArrayMap(f, receiver) {
1084 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1084 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1085 throw MakeTypeError("called_on_null_or_undefined", 1085 throw MakeTypeError("called_on_null_or_undefined",
1086 ["Array.prototype.map"]); 1086 ["Array.prototype.map"]);
1087 } 1087 }
1088 1088
1089 if (!IS_FUNCTION(f)) { 1089 if (!IS_SPEC_FUNCTION(f)) {
1090 throw MakeTypeError('called_non_callable', [ f ]); 1090 throw MakeTypeError('called_non_callable', [ f ]);
1091 } 1091 }
1092 // Pull out the length so that modifications to the length in the 1092 // Pull out the length so that modifications to the length in the
1093 // loop will not affect the looping. 1093 // loop will not affect the looping.
1094 var length = TO_UINT32(this.length); 1094 var length = TO_UINT32(this.length);
1095 var result = new $Array(); 1095 var result = new $Array();
1096 var accumulator = new InternalArray(length); 1096 var accumulator = new InternalArray(length);
1097 for (var i = 0; i < length; i++) { 1097 for (var i = 0; i < length; i++) {
1098 var current = this[i]; 1098 var current = this[i];
1099 if (!IS_UNDEFINED(current) || i in this) { 1099 if (!IS_UNDEFINED(current) || i in this) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 return -1; 1224 return -1;
1225 } 1225 }
1226 1226
1227 1227
1228 function ArrayReduce(callback, current) { 1228 function ArrayReduce(callback, current) {
1229 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1229 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1230 throw MakeTypeError("called_on_null_or_undefined", 1230 throw MakeTypeError("called_on_null_or_undefined",
1231 ["Array.prototype.reduce"]); 1231 ["Array.prototype.reduce"]);
1232 } 1232 }
1233 1233
1234 if (!IS_FUNCTION(callback)) { 1234 if (!IS_SPEC_FUNCTION(callback)) {
1235 throw MakeTypeError('called_non_callable', [callback]); 1235 throw MakeTypeError('called_non_callable', [callback]);
1236 } 1236 }
1237 // Pull out the length so that modifications to the length in the 1237 // Pull out the length so that modifications to the length in the
1238 // loop will not affect the looping. 1238 // loop will not affect the looping.
1239 var length = ToUint32(this.length); 1239 var length = ToUint32(this.length);
1240 var i = 0; 1240 var i = 0;
1241 1241
1242 find_initial: if (%_ArgumentsLength() < 2) { 1242 find_initial: if (%_ArgumentsLength() < 2) {
1243 for (; i < length; i++) { 1243 for (; i < length; i++) {
1244 current = this[i]; 1244 current = this[i];
(...skipping 13 matching lines...) Expand all
1258 } 1258 }
1259 return current; 1259 return current;
1260 } 1260 }
1261 1261
1262 function ArrayReduceRight(callback, current) { 1262 function ArrayReduceRight(callback, current) {
1263 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 1263 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1264 throw MakeTypeError("called_on_null_or_undefined", 1264 throw MakeTypeError("called_on_null_or_undefined",
1265 ["Array.prototype.reduceRight"]); 1265 ["Array.prototype.reduceRight"]);
1266 } 1266 }
1267 1267
1268 if (!IS_FUNCTION(callback)) { 1268 if (!IS_SPEC_FUNCTION(callback)) {
1269 throw MakeTypeError('called_non_callable', [callback]); 1269 throw MakeTypeError('called_non_callable', [callback]);
1270 } 1270 }
1271 var i = ToUint32(this.length) - 1; 1271 var i = ToUint32(this.length) - 1;
1272 1272
1273 find_initial: if (%_ArgumentsLength() < 2) { 1273 find_initial: if (%_ArgumentsLength() < 2) {
1274 for (; i >= 0; i--) { 1274 for (; i >= 0; i--) {
1275 current = this[i]; 1275 current = this[i];
1276 if (!IS_UNDEFINED(current) || i in this) { 1276 if (!IS_UNDEFINED(current) || i in this) {
1277 i--; 1277 i--;
1278 break find_initial; 1278 break find_initial;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 InternalArray.prototype.join = getFunction("join", ArrayJoin); 1360 InternalArray.prototype.join = getFunction("join", ArrayJoin);
1361 InternalArray.prototype.pop = getFunction("pop", ArrayPop); 1361 InternalArray.prototype.pop = getFunction("pop", ArrayPop);
1362 InternalArray.prototype.push = getFunction("push", ArrayPush); 1362 InternalArray.prototype.push = getFunction("push", ArrayPush);
1363 InternalArray.prototype.toString = function() { 1363 InternalArray.prototype.toString = function() {
1364 return "Internal Array, length " + this.length; 1364 return "Internal Array, length " + this.length;
1365 }; 1365 };
1366 } 1366 }
1367 1367
1368 1368
1369 SetupArray(); 1369 SetupArray();
OLDNEW
« no previous file with comments | « src/arm/macro-assembler-arm.h ('k') | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698