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

Side by Side Diff: src/array.js

Issue 271072: Implement ES5 Array.isArray (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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 | « no previous file | test/mjsunit/third_party/array-isarray.js » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1051
1052 for (; i >= 0; i--) { 1052 for (; i >= 0; i--) {
1053 var element = this[i]; 1053 var element = this[i];
1054 if (!IS_UNDEFINED(element) || i in this) { 1054 if (!IS_UNDEFINED(element) || i in this) {
1055 current = callback.call(null, current, element, i, this); 1055 current = callback.call(null, current, element, i, this);
1056 } 1056 }
1057 } 1057 }
1058 return current; 1058 return current;
1059 } 1059 }
1060 1060
1061 // ES5, 15.4.3.2
1062 function ArrayIsArray(obj) {
1063 return IS_ARRAY(obj);
1064 }
1061 1065
1062 // ------------------------------------------------------------------- 1066 // -------------------------------------------------------------------
1063 1067
1064 1068
1065 function UpdateFunctionLengths(lengths) { 1069 function UpdateFunctionLengths(lengths) {
1066 for (var key in lengths) { 1070 for (var key in lengths) {
1067 %FunctionSetLength(this[key], lengths[key]); 1071 %FunctionSetLength(this[key], lengths[key]);
1068 } 1072 }
1069 } 1073 }
1070 1074
1071 1075
1072 // ------------------------------------------------------------------- 1076 // -------------------------------------------------------------------
1073 function SetupArray() { 1077 function SetupArray() {
1074 // Setup non-enumerable constructor property on the Array.prototype 1078 // Setup non-enumerable constructor property on the Array.prototype
1075 // object. 1079 // object.
1076 %SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM); 1080 %SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM);
1077 1081
1082 // Setup non-enumerable functions on the Array object.
1083 InstallFunctions($Array, DONT_ENUM, $Array(
1084 "isArray", ArrayIsArray
1085 ));
1086
1078 // Setup non-enumerable functions of the Array.prototype object and 1087 // Setup non-enumerable functions of the Array.prototype object and
1079 // set their names. 1088 // set their names.
1080 InstallFunctionsOnHiddenPrototype($Array.prototype, DONT_ENUM, $Array( 1089 InstallFunctionsOnHiddenPrototype($Array.prototype, DONT_ENUM, $Array(
1081 "toString", ArrayToString, 1090 "toString", ArrayToString,
1082 "toLocaleString", ArrayToLocaleString, 1091 "toLocaleString", ArrayToLocaleString,
1083 "join", ArrayJoin, 1092 "join", ArrayJoin,
1084 "pop", ArrayPop, 1093 "pop", ArrayPop,
1085 "push", ArrayPush, 1094 "push", ArrayPush,
1086 "concat", ArrayConcat, 1095 "concat", ArrayConcat,
1087 "reverse", ArrayReverse, 1096 "reverse", ArrayReverse,
1088 "shift", ArrayShift, 1097 "shift", ArrayShift,
1089 "unshift", ArrayUnshift, 1098 "unshift", ArrayUnshift,
1090 "slice", ArraySlice, 1099 "slice", ArraySlice,
1091 "splice", ArraySplice, 1100 "splice", ArraySplice,
1092 "sort", ArraySort, 1101 "sort", ArraySort,
1093 "filter", ArrayFilter, 1102 "filter", ArrayFilter,
1094 "forEach", ArrayForEach, 1103 "forEach", ArrayForEach,
1095 "some", ArraySome, 1104 "some", ArraySome,
1096 "every", ArrayEvery, 1105 "every", ArrayEvery,
1097 "map", ArrayMap, 1106 "map", ArrayMap,
1098 "indexOf", ArrayIndexOf, 1107 "indexOf", ArrayIndexOf,
1099 "lastIndexOf", ArrayLastIndexOf, 1108 "lastIndexOf", ArrayLastIndexOf,
1100 "reduce", ArrayReduce, 1109 "reduce", ArrayReduce,
1101 "reduceRight", ArrayReduceRight)); 1110 "reduceRight", ArrayReduceRight
1102 1111 ));
1112
1103 // Manipulate the length of some of the functions to meet 1113 // Manipulate the length of some of the functions to meet
1104 // expectations set by ECMA-262 or Mozilla. 1114 // expectations set by ECMA-262 or Mozilla.
1105 UpdateFunctionLengths({ 1115 UpdateFunctionLengths({
1106 ArrayFilter: 1, 1116 ArrayFilter: 1,
1107 ArrayForEach: 1, 1117 ArrayForEach: 1,
1108 ArraySome: 1, 1118 ArraySome: 1,
1109 ArrayEvery: 1, 1119 ArrayEvery: 1,
1110 ArrayMap: 1, 1120 ArrayMap: 1,
1111 ArrayIndexOf: 1, 1121 ArrayIndexOf: 1,
1112 ArrayLastIndexOf: 1, 1122 ArrayLastIndexOf: 1,
1113 ArrayPush: 1, 1123 ArrayPush: 1,
1114 ArrayReduce: 1, 1124 ArrayReduce: 1,
1115 ArrayReduceRight: 1 1125 ArrayReduceRight: 1
1116 }); 1126 });
1117 } 1127 }
1118 1128
1119 1129
1120 SetupArray(); 1130 SetupArray();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/third_party/array-isarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698