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