Chromium Code Reviews| Index: src/array.js |
| =================================================================== |
| --- src/array.js (revision 7676) |
| +++ src/array.js (working copy) |
| @@ -375,6 +375,10 @@ |
| function ArrayJoin(separator) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
|
Lasse Reichstein
2011/04/28 10:44:38
Is this correct behavior for an undetectable objec
Lasse Reichstein
2011/04/28 10:50:01
Just checked Firefox 4. It does not throw when pas
MarkM
2011/04/28 15:40:45
Do we have any undetectable objects other that doc
Rico
2011/05/03 08:47:20
Added checks for the undetectable object in all ca
|
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.join"]); |
|
Lasse Reichstein
2011/04/28 10:44:38
The name shouldn't be "Array.prototype.join"?
MarkM
2011/04/28 18:58:21
For all these generics, I wonder about the string
Rico
2011/05/03 08:47:20
Changed
Rico
2011/05/03 08:47:20
Changed to "FUNCTIONNAME called on null or undefin
|
| + } |
| + |
| if (IS_UNDEFINED(separator)) { |
| separator = ','; |
| } else if (!IS_STRING(separator)) { |
| @@ -391,6 +395,10 @@ |
| // Removes the last element from the array and returns it. See |
| // ECMA-262, section 15.4.4.6. |
| function ArrayPop() { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.pop"]); |
| + } |
| + |
| var n = TO_UINT32(this.length); |
| if (n == 0) { |
| this.length = n; |
| @@ -407,6 +415,10 @@ |
| // Appends the arguments to the end of the array and returns the new |
| // length of the array. See ECMA-262, section 15.4.4.7. |
| function ArrayPush() { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.push"]); |
| + } |
| + |
| var n = TO_UINT32(this.length); |
| var m = %_ArgumentsLength(); |
| for (var i = 0; i < m; i++) { |
| @@ -418,6 +430,10 @@ |
| function ArrayConcat(arg1) { // length == 1 |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.concat"]); |
| + } |
| + |
| var arg_count = %_ArgumentsLength(); |
| var arrays = new InternalArray(1 + arg_count); |
| arrays[0] = this; |
| @@ -474,6 +490,10 @@ |
| function ArrayReverse() { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.reverse"]); |
| + } |
| + |
| var j = TO_UINT32(this.length) - 1; |
| if (UseSparseVariant(this, j, IS_ARRAY(this))) { |
| @@ -505,6 +525,10 @@ |
| function ArrayShift() { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.shift"]); |
| + } |
| + |
| var len = TO_UINT32(this.length); |
| if (len === 0) { |
| @@ -526,6 +550,10 @@ |
| function ArrayUnshift(arg1) { // length == 1 |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.unshift"]); |
| + } |
| + |
| var len = TO_UINT32(this.length); |
| var num_arguments = %_ArgumentsLength(); |
| @@ -545,6 +573,10 @@ |
| function ArraySlice(start, end) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.slice"]); |
| + } |
| + |
| var len = TO_UINT32(this.length); |
| var start_i = TO_INTEGER(start); |
| var end_i = len; |
| @@ -582,6 +614,10 @@ |
| function ArraySplice(start, delete_count) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.splice"]); |
| + } |
| + |
| var num_arguments = %_ArgumentsLength(); |
| var len = TO_UINT32(this.length); |
| @@ -653,6 +689,10 @@ |
| function ArraySort(comparefn) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.sort"]); |
| + } |
| + |
| // In-place QuickSort algorithm. |
| // For short (length <= 22) arrays, insertion sort is used for efficiency. |
| @@ -914,6 +954,10 @@ |
| // preserving the semantics, since the calls to the receiver function can add |
| // or delete elements from the array. |
| function ArrayFilter(f, receiver) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.filter"]); |
| + } |
| + |
| if (!IS_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [ f ]); |
| } |
| @@ -935,6 +979,10 @@ |
| function ArrayForEach(f, receiver) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.forEach"]); |
| + } |
| + |
| if (!IS_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [ f ]); |
| } |
| @@ -953,6 +1001,10 @@ |
| // Executes the function once for each element present in the |
| // array until it finds one where callback returns true. |
| function ArraySome(f, receiver) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.some"]); |
| + } |
| + |
| if (!IS_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [ f ]); |
| } |
| @@ -970,6 +1022,10 @@ |
| function ArrayEvery(f, receiver) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.every"]); |
| + } |
| + |
| if (!IS_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [ f ]); |
| } |
| @@ -986,6 +1042,10 @@ |
| } |
| function ArrayMap(f, receiver) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.map"]); |
| + } |
| + |
| if (!IS_FUNCTION(f)) { |
| throw MakeTypeError('called_non_callable', [ f ]); |
| } |
| @@ -1006,6 +1066,10 @@ |
| function ArrayIndexOf(element, index) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.indexOf"]); |
| + } |
| + |
| var length = TO_UINT32(this.length); |
| if (length == 0) return -1; |
| if (IS_UNDEFINED(index)) { |
| @@ -1063,6 +1127,10 @@ |
| function ArrayLastIndexOf(element, index) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.lastIndexOf"]); |
| + } |
| + |
| var length = TO_UINT32(this.length); |
| if (length == 0) return -1; |
| if (%_ArgumentsLength() < 2) { |
| @@ -1116,6 +1184,10 @@ |
| function ArrayReduce(callback, current) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.reduce"]); |
| + } |
| + |
| if (!IS_FUNCTION(callback)) { |
| throw MakeTypeError('called_non_callable', [callback]); |
| } |
| @@ -1145,6 +1217,10 @@ |
| } |
| function ArrayReduceRight(callback, current) { |
| + if (IS_NULL_OR_UNDEFINED(this)) { |
| + throw MakeTypeError("obj_ctor_property_non_object", ["Array.reduceRight"]); |
| + } |
| + |
| if (!IS_FUNCTION(callback)) { |
| throw MakeTypeError('called_non_callable', [callback]); |
| } |