| OLD | NEW |
| 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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 // Pull out the length so that modifications to the length in the | 1006 // Pull out the length so that modifications to the length in the |
| 1007 // loop will not affect the looping and side effects are visible. | 1007 // loop will not affect the looping and side effects are visible. |
| 1008 var array = ToObject(this); | 1008 var array = ToObject(this); |
| 1009 var length = ToUint32(array.length); | 1009 var length = ToUint32(array.length); |
| 1010 | 1010 |
| 1011 if (!IS_SPEC_FUNCTION(f)) { | 1011 if (!IS_SPEC_FUNCTION(f)) { |
| 1012 throw MakeTypeError('called_non_callable', [ f ]); | 1012 throw MakeTypeError('called_non_callable', [ f ]); |
| 1013 } | 1013 } |
| 1014 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1014 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1015 receiver = %GetDefaultReceiver(f) || receiver; | 1015 receiver = %GetDefaultReceiver(f) || receiver; |
| 1016 } else if (!IS_SPEC_OBJECT(receiver)) { |
| 1017 receiver = ToObject(receiver); |
| 1016 } | 1018 } |
| 1017 | 1019 |
| 1018 var result = []; | 1020 var result = new $Array(); |
| 1019 var result_length = 0; | 1021 var accumulator = new InternalArray(); |
| 1022 var accumulator_length = 0; |
| 1020 for (var i = 0; i < length; i++) { | 1023 for (var i = 0; i < length; i++) { |
| 1021 var current = array[i]; | 1024 var current = array[i]; |
| 1022 if (!IS_UNDEFINED(current) || i in array) { | 1025 if (!IS_UNDEFINED(current) || i in array) { |
| 1023 if (%_CallFunction(receiver, current, i, array, f)) { | 1026 if (%_CallFunction(receiver, current, i, array, f)) { |
| 1024 result[result_length++] = current; | 1027 accumulator[accumulator_length++] = current; |
| 1025 } | 1028 } |
| 1026 } | 1029 } |
| 1027 } | 1030 } |
| 1031 %MoveArrayContents(accumulator, result); |
| 1028 return result; | 1032 return result; |
| 1029 } | 1033 } |
| 1030 | 1034 |
| 1031 | 1035 |
| 1032 function ArrayForEach(f, receiver) { | 1036 function ArrayForEach(f, receiver) { |
| 1033 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 1037 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1034 throw MakeTypeError("called_on_null_or_undefined", | 1038 throw MakeTypeError("called_on_null_or_undefined", |
| 1035 ["Array.prototype.forEach"]); | 1039 ["Array.prototype.forEach"]); |
| 1036 } | 1040 } |
| 1037 | 1041 |
| 1038 // Pull out the length so that modifications to the length in the | 1042 // Pull out the length so that modifications to the length in the |
| 1039 // loop will not affect the looping and side effects are visible. | 1043 // loop will not affect the looping and side effects are visible. |
| 1040 var array = ToObject(this); | 1044 var array = ToObject(this); |
| 1041 var length = TO_UINT32(array.length); | 1045 var length = TO_UINT32(array.length); |
| 1042 | 1046 |
| 1043 if (!IS_SPEC_FUNCTION(f)) { | 1047 if (!IS_SPEC_FUNCTION(f)) { |
| 1044 throw MakeTypeError('called_non_callable', [ f ]); | 1048 throw MakeTypeError('called_non_callable', [ f ]); |
| 1045 } | 1049 } |
| 1046 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1050 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1047 receiver = %GetDefaultReceiver(f) || receiver; | 1051 receiver = %GetDefaultReceiver(f) || receiver; |
| 1052 } else if (!IS_SPEC_OBJECT(receiver)) { |
| 1053 receiver = ToObject(receiver); |
| 1048 } | 1054 } |
| 1049 | 1055 |
| 1050 for (var i = 0; i < length; i++) { | 1056 for (var i = 0; i < length; i++) { |
| 1051 var current = array[i]; | 1057 var current = array[i]; |
| 1052 if (!IS_UNDEFINED(current) || i in array) { | 1058 if (!IS_UNDEFINED(current) || i in array) { |
| 1053 %_CallFunction(receiver, current, i, array, f); | 1059 %_CallFunction(receiver, current, i, array, f); |
| 1054 } | 1060 } |
| 1055 } | 1061 } |
| 1056 } | 1062 } |
| 1057 | 1063 |
| 1058 | 1064 |
| 1059 // Executes the function once for each element present in the | 1065 // Executes the function once for each element present in the |
| 1060 // array until it finds one where callback returns true. | 1066 // array until it finds one where callback returns true. |
| 1061 function ArraySome(f, receiver) { | 1067 function ArraySome(f, receiver) { |
| 1062 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 1068 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1063 throw MakeTypeError("called_on_null_or_undefined", | 1069 throw MakeTypeError("called_on_null_or_undefined", |
| 1064 ["Array.prototype.some"]); | 1070 ["Array.prototype.some"]); |
| 1065 } | 1071 } |
| 1066 | 1072 |
| 1067 // Pull out the length so that modifications to the length in the | 1073 // Pull out the length so that modifications to the length in the |
| 1068 // loop will not affect the looping and side effects are visible. | 1074 // loop will not affect the looping and side effects are visible. |
| 1069 var array = ToObject(this); | 1075 var array = ToObject(this); |
| 1070 var length = TO_UINT32(array.length); | 1076 var length = TO_UINT32(array.length); |
| 1071 | 1077 |
| 1072 if (!IS_SPEC_FUNCTION(f)) { | 1078 if (!IS_SPEC_FUNCTION(f)) { |
| 1073 throw MakeTypeError('called_non_callable', [ f ]); | 1079 throw MakeTypeError('called_non_callable', [ f ]); |
| 1074 } | 1080 } |
| 1075 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1081 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1076 receiver = %GetDefaultReceiver(f) || receiver; | 1082 receiver = %GetDefaultReceiver(f) || receiver; |
| 1083 } else if (!IS_SPEC_OBJECT(receiver)) { |
| 1084 receiver = ToObject(receiver); |
| 1077 } | 1085 } |
| 1078 | 1086 |
| 1079 for (var i = 0; i < length; i++) { | 1087 for (var i = 0; i < length; i++) { |
| 1080 var current = array[i]; | 1088 var current = array[i]; |
| 1081 if (!IS_UNDEFINED(current) || i in array) { | 1089 if (!IS_UNDEFINED(current) || i in array) { |
| 1082 if (%_CallFunction(receiver, current, i, array, f)) return true; | 1090 if (%_CallFunction(receiver, current, i, array, f)) return true; |
| 1083 } | 1091 } |
| 1084 } | 1092 } |
| 1085 return false; | 1093 return false; |
| 1086 } | 1094 } |
| 1087 | 1095 |
| 1088 | 1096 |
| 1089 function ArrayEvery(f, receiver) { | 1097 function ArrayEvery(f, receiver) { |
| 1090 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 1098 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1091 throw MakeTypeError("called_on_null_or_undefined", | 1099 throw MakeTypeError("called_on_null_or_undefined", |
| 1092 ["Array.prototype.every"]); | 1100 ["Array.prototype.every"]); |
| 1093 } | 1101 } |
| 1094 | 1102 |
| 1095 // Pull out the length so that modifications to the length in the | 1103 // Pull out the length so that modifications to the length in the |
| 1096 // loop will not affect the looping and side effects are visible. | 1104 // loop will not affect the looping and side effects are visible. |
| 1097 var array = ToObject(this); | 1105 var array = ToObject(this); |
| 1098 var length = TO_UINT32(array.length); | 1106 var length = TO_UINT32(array.length); |
| 1099 | 1107 |
| 1100 if (!IS_SPEC_FUNCTION(f)) { | 1108 if (!IS_SPEC_FUNCTION(f)) { |
| 1101 throw MakeTypeError('called_non_callable', [ f ]); | 1109 throw MakeTypeError('called_non_callable', [ f ]); |
| 1102 } | 1110 } |
| 1103 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1111 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1104 receiver = %GetDefaultReceiver(f) || receiver; | 1112 receiver = %GetDefaultReceiver(f) || receiver; |
| 1113 } else if (!IS_SPEC_OBJECT(receiver)) { |
| 1114 receiver = ToObject(receiver); |
| 1105 } | 1115 } |
| 1106 | 1116 |
| 1107 for (var i = 0; i < length; i++) { | 1117 for (var i = 0; i < length; i++) { |
| 1108 var current = array[i]; | 1118 var current = array[i]; |
| 1109 if (!IS_UNDEFINED(current) || i in array) { | 1119 if (!IS_UNDEFINED(current) || i in array) { |
| 1110 if (!%_CallFunction(receiver, current, i, array, f)) return false; | 1120 if (!%_CallFunction(receiver, current, i, array, f)) return false; |
| 1111 } | 1121 } |
| 1112 } | 1122 } |
| 1113 return true; | 1123 return true; |
| 1114 } | 1124 } |
| 1115 | 1125 |
| 1116 function ArrayMap(f, receiver) { | 1126 function ArrayMap(f, receiver) { |
| 1117 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 1127 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1118 throw MakeTypeError("called_on_null_or_undefined", | 1128 throw MakeTypeError("called_on_null_or_undefined", |
| 1119 ["Array.prototype.map"]); | 1129 ["Array.prototype.map"]); |
| 1120 } | 1130 } |
| 1121 | 1131 |
| 1122 // Pull out the length so that modifications to the length in the | 1132 // Pull out the length so that modifications to the length in the |
| 1123 // loop will not affect the looping and side effects are visible. | 1133 // loop will not affect the looping and side effects are visible. |
| 1124 var array = ToObject(this); | 1134 var array = ToObject(this); |
| 1125 var length = TO_UINT32(array.length); | 1135 var length = TO_UINT32(array.length); |
| 1126 | 1136 |
| 1127 if (!IS_SPEC_FUNCTION(f)) { | 1137 if (!IS_SPEC_FUNCTION(f)) { |
| 1128 throw MakeTypeError('called_non_callable', [ f ]); | 1138 throw MakeTypeError('called_non_callable', [ f ]); |
| 1129 } | 1139 } |
| 1130 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1140 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1131 receiver = %GetDefaultReceiver(f) || receiver; | 1141 receiver = %GetDefaultReceiver(f) || receiver; |
| 1142 } else if (!IS_SPEC_OBJECT(receiver)) { |
| 1143 receiver = ToObject(receiver); |
| 1132 } | 1144 } |
| 1133 | 1145 |
| 1134 var result = new $Array(); | 1146 var result = new $Array(); |
| 1135 var accumulator = new InternalArray(length); | 1147 var accumulator = new InternalArray(length); |
| 1136 for (var i = 0; i < length; i++) { | 1148 for (var i = 0; i < length; i++) { |
| 1137 var current = array[i]; | 1149 var current = array[i]; |
| 1138 if (!IS_UNDEFINED(current) || i in array) { | 1150 if (!IS_UNDEFINED(current) || i in array) { |
| 1139 accumulator[i] = %_CallFunction(receiver, current, i, array, f); | 1151 accumulator[i] = %_CallFunction(receiver, current, i, array, f); |
| 1140 } | 1152 } |
| 1141 } | 1153 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 // exposed to user code. | 1415 // exposed to user code. |
| 1404 // Adding only the functions that are actually used. | 1416 // Adding only the functions that are actually used. |
| 1405 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1417 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
| 1406 "join", getFunction("join", ArrayJoin), | 1418 "join", getFunction("join", ArrayJoin), |
| 1407 "pop", getFunction("pop", ArrayPop), | 1419 "pop", getFunction("pop", ArrayPop), |
| 1408 "push", getFunction("push", ArrayPush) | 1420 "push", getFunction("push", ArrayPush) |
| 1409 )); | 1421 )); |
| 1410 } | 1422 } |
| 1411 | 1423 |
| 1412 SetUpArray(); | 1424 SetUpArray(); |
| OLD | NEW |