| 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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 throw MakeTypeError('called_non_callable', [ f ]); | 918 throw MakeTypeError('called_non_callable', [ f ]); |
| 919 } | 919 } |
| 920 // Pull out the length so that modifications to the length in the | 920 // Pull out the length so that modifications to the length in the |
| 921 // loop will not affect the looping. | 921 // loop will not affect the looping. |
| 922 var length = this.length; | 922 var length = this.length; |
| 923 var result = []; | 923 var result = []; |
| 924 var result_length = 0; | 924 var result_length = 0; |
| 925 for (var i = 0; i < length; i++) { | 925 for (var i = 0; i < length; i++) { |
| 926 var current = this[i]; | 926 var current = this[i]; |
| 927 if (!IS_UNDEFINED(current) || i in this) { | 927 if (!IS_UNDEFINED(current) || i in this) { |
| 928 if (%_CallFunction(receiver, current, i, this, f)) { | 928 if (f.call(receiver, current, i, this)) { |
| 929 result[result_length++] = current; | 929 result[result_length++] = current; |
| 930 } | 930 } |
| 931 } | 931 } |
| 932 } | 932 } |
| 933 return result; | 933 return result; |
| 934 } | 934 } |
| 935 | 935 |
| 936 | 936 |
| 937 function ArrayForEach(f, receiver) { | 937 function ArrayForEach(f, receiver) { |
| 938 if (!IS_FUNCTION(f)) { | 938 if (!IS_FUNCTION(f)) { |
| 939 throw MakeTypeError('called_non_callable', [ f ]); | 939 throw MakeTypeError('called_non_callable', [ f ]); |
| 940 } | 940 } |
| 941 // Pull out the length so that modifications to the length in the | 941 // Pull out the length so that modifications to the length in the |
| 942 // loop will not affect the looping. | 942 // loop will not affect the looping. |
| 943 var length = TO_UINT32(this.length); | 943 var length = TO_UINT32(this.length); |
| 944 for (var i = 0; i < length; i++) { | 944 for (var i = 0; i < length; i++) { |
| 945 var current = this[i]; | 945 var current = this[i]; |
| 946 if (!IS_UNDEFINED(current) || i in this) { | 946 if (!IS_UNDEFINED(current) || i in this) { |
| 947 %_CallFunction(receiver, current, i, this, f); | 947 f.call(receiver, current, i, this); |
| 948 } | 948 } |
| 949 } | 949 } |
| 950 } | 950 } |
| 951 | 951 |
| 952 | 952 |
| 953 // Executes the function once for each element present in the | 953 // Executes the function once for each element present in the |
| 954 // array until it finds one where callback returns true. | 954 // array until it finds one where callback returns true. |
| 955 function ArraySome(f, receiver) { | 955 function ArraySome(f, receiver) { |
| 956 if (!IS_FUNCTION(f)) { | 956 if (!IS_FUNCTION(f)) { |
| 957 throw MakeTypeError('called_non_callable', [ f ]); | 957 throw MakeTypeError('called_non_callable', [ f ]); |
| 958 } | 958 } |
| 959 // Pull out the length so that modifications to the length in the | 959 // Pull out the length so that modifications to the length in the |
| 960 // loop will not affect the looping. | 960 // loop will not affect the looping. |
| 961 var length = TO_UINT32(this.length); | 961 var length = TO_UINT32(this.length); |
| 962 for (var i = 0; i < length; i++) { | 962 for (var i = 0; i < length; i++) { |
| 963 var current = this[i]; | 963 var current = this[i]; |
| 964 if (!IS_UNDEFINED(current) || i in this) { | 964 if (!IS_UNDEFINED(current) || i in this) { |
| 965 if (%_CallFunction(receiver, current, i, this, f)) return true; | 965 if (f.call(receiver, current, i, this)) return true; |
| 966 } | 966 } |
| 967 } | 967 } |
| 968 return false; | 968 return false; |
| 969 } | 969 } |
| 970 | 970 |
| 971 | 971 |
| 972 function ArrayEvery(f, receiver) { | 972 function ArrayEvery(f, receiver) { |
| 973 if (!IS_FUNCTION(f)) { | 973 if (!IS_FUNCTION(f)) { |
| 974 throw MakeTypeError('called_non_callable', [ f ]); | 974 throw MakeTypeError('called_non_callable', [ f ]); |
| 975 } | 975 } |
| 976 // Pull out the length so that modifications to the length in the | 976 // Pull out the length so that modifications to the length in the |
| 977 // loop will not affect the looping. | 977 // loop will not affect the looping. |
| 978 var length = TO_UINT32(this.length); | 978 var length = TO_UINT32(this.length); |
| 979 for (var i = 0; i < length; i++) { | 979 for (var i = 0; i < length; i++) { |
| 980 var current = this[i]; | 980 var current = this[i]; |
| 981 if (!IS_UNDEFINED(current) || i in this) { | 981 if (!IS_UNDEFINED(current) || i in this) { |
| 982 if (!%_CallFunction(receiver, current, i, this, f)) return false; | 982 if (!f.call(receiver, current, i, this)) return false; |
| 983 } | 983 } |
| 984 } | 984 } |
| 985 return true; | 985 return true; |
| 986 } | 986 } |
| 987 | 987 |
| 988 function ArrayMap(f, receiver) { | 988 function ArrayMap(f, receiver) { |
| 989 if (!IS_FUNCTION(f)) { | 989 if (!IS_FUNCTION(f)) { |
| 990 throw MakeTypeError('called_non_callable', [ f ]); | 990 throw MakeTypeError('called_non_callable', [ f ]); |
| 991 } | 991 } |
| 992 // Pull out the length so that modifications to the length in the | 992 // Pull out the length so that modifications to the length in the |
| 993 // loop will not affect the looping. | 993 // loop will not affect the looping. |
| 994 var length = TO_UINT32(this.length); | 994 var length = TO_UINT32(this.length); |
| 995 var result = new $Array(); | 995 var result = new $Array(); |
| 996 var accumulator = new InternalArray(length); | 996 var accumulator = new InternalArray(length); |
| 997 for (var i = 0; i < length; i++) { | 997 for (var i = 0; i < length; i++) { |
| 998 var current = this[i]; | 998 var current = this[i]; |
| 999 if (!IS_UNDEFINED(current) || i in this) { | 999 if (!IS_UNDEFINED(current) || i in this) { |
| 1000 accumulator[i] = %_CallFunction(receiver, current, i, this, f); | 1000 accumulator[i] = f.call(receiver, current, i, this); |
| 1001 } | 1001 } |
| 1002 } | 1002 } |
| 1003 %MoveArrayContents(accumulator, result); | 1003 %MoveArrayContents(accumulator, result); |
| 1004 return result; | 1004 return result; |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 | 1007 |
| 1008 function ArrayIndexOf(element, index) { | 1008 function ArrayIndexOf(element, index) { |
| 1009 var length = TO_UINT32(this.length); | 1009 var length = TO_UINT32(this.length); |
| 1010 if (length == 0) return -1; | 1010 if (length == 0) return -1; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 InternalArray.prototype.join = getFunction("join", ArrayJoin); | 1240 InternalArray.prototype.join = getFunction("join", ArrayJoin); |
| 1241 InternalArray.prototype.pop = getFunction("pop", ArrayPop); | 1241 InternalArray.prototype.pop = getFunction("pop", ArrayPop); |
| 1242 InternalArray.prototype.push = getFunction("push", ArrayPush); | 1242 InternalArray.prototype.push = getFunction("push", ArrayPush); |
| 1243 InternalArray.prototype.toString = function() { | 1243 InternalArray.prototype.toString = function() { |
| 1244 return "Internal Array, length " + this.length; | 1244 return "Internal Array, length " + this.length; |
| 1245 }; | 1245 }; |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 | 1248 |
| 1249 SetupArray(); | 1249 SetupArray(); |
| OLD | NEW |