| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 function ArraySlice(start, end) { | 670 function ArraySlice(start, end) { |
| 671 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 671 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 672 throw MakeTypeError("called_on_null_or_undefined", | 672 throw MakeTypeError("called_on_null_or_undefined", |
| 673 ["Array.prototype.slice"]); | 673 ["Array.prototype.slice"]); |
| 674 } | 674 } |
| 675 | 675 |
| 676 var len = TO_UINT32(this.length); | 676 var len = TO_UINT32(this.length); |
| 677 var start_i = TO_INTEGER(start); | 677 var start_i = TO_INTEGER(start); |
| 678 var end_i = len; | 678 var end_i = len; |
| 679 | 679 |
| 680 if (end !== void 0) end_i = TO_INTEGER(end); | 680 if (!IS_UNDEFINED(end)) end_i = TO_INTEGER(end); |
| 681 | 681 |
| 682 if (start_i < 0) { | 682 if (start_i < 0) { |
| 683 start_i += len; | 683 start_i += len; |
| 684 if (start_i < 0) start_i = 0; | 684 if (start_i < 0) start_i = 0; |
| 685 } else { | 685 } else { |
| 686 if (start_i > len) start_i = len; | 686 if (start_i > len) start_i = len; |
| 687 } | 687 } |
| 688 | 688 |
| 689 if (end_i < 0) { | 689 if (end_i < 0) { |
| 690 end_i += len; | 690 end_i += len; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 // where a prototype of obj has an element. I.e., shadow all prototype | 1009 // where a prototype of obj has an element. I.e., shadow all prototype |
| 1010 // elements in that range. | 1010 // elements in that range. |
| 1011 var ShadowPrototypeElements = function(obj, from, to) { | 1011 var ShadowPrototypeElements = function(obj, from, to) { |
| 1012 for (var proto = %GetPrototype(obj); proto; proto = %GetPrototype(proto)) { | 1012 for (var proto = %GetPrototype(obj); proto; proto = %GetPrototype(proto)) { |
| 1013 var indices = %GetArrayKeys(proto, to); | 1013 var indices = %GetArrayKeys(proto, to); |
| 1014 if (IS_NUMBER(indices)) { | 1014 if (IS_NUMBER(indices)) { |
| 1015 // It's an interval. | 1015 // It's an interval. |
| 1016 var proto_length = indices; | 1016 var proto_length = indices; |
| 1017 for (var i = from; i < proto_length; i++) { | 1017 for (var i = from; i < proto_length; i++) { |
| 1018 if (proto.hasOwnProperty(i)) { | 1018 if (proto.hasOwnProperty(i)) { |
| 1019 obj[i] = void 0; | 1019 obj[i] = UNDEFINED; |
| 1020 } | 1020 } |
| 1021 } | 1021 } |
| 1022 } else { | 1022 } else { |
| 1023 for (var i = 0; i < indices.length; i++) { | 1023 for (var i = 0; i < indices.length; i++) { |
| 1024 var index = indices[i]; | 1024 var index = indices[i]; |
| 1025 if (!IS_UNDEFINED(index) && from <= index && | 1025 if (!IS_UNDEFINED(index) && from <= index && |
| 1026 proto.hasOwnProperty(index)) { | 1026 proto.hasOwnProperty(index)) { |
| 1027 obj[index] = void 0; | 1027 obj[index] = UNDEFINED; |
| 1028 } | 1028 } |
| 1029 } | 1029 } |
| 1030 } | 1030 } |
| 1031 } | 1031 } |
| 1032 }; | 1032 }; |
| 1033 | 1033 |
| 1034 var SafeRemoveArrayHoles = function SafeRemoveArrayHoles(obj) { | 1034 var SafeRemoveArrayHoles = function SafeRemoveArrayHoles(obj) { |
| 1035 // Copy defined elements from the end to fill in all holes and undefineds | 1035 // Copy defined elements from the end to fill in all holes and undefineds |
| 1036 // in the beginning of the array. Write undefineds and holes at the end | 1036 // in the beginning of the array. Write undefineds and holes at the end |
| 1037 // after loop is finished. | 1037 // after loop is finished. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1054 while (first_undefined < last_defined && | 1054 while (first_undefined < last_defined && |
| 1055 IS_UNDEFINED(obj[last_defined])) { | 1055 IS_UNDEFINED(obj[last_defined])) { |
| 1056 if (!obj.hasOwnProperty(last_defined)) { | 1056 if (!obj.hasOwnProperty(last_defined)) { |
| 1057 num_holes++; | 1057 num_holes++; |
| 1058 } | 1058 } |
| 1059 last_defined--; | 1059 last_defined--; |
| 1060 } | 1060 } |
| 1061 if (first_undefined < last_defined) { | 1061 if (first_undefined < last_defined) { |
| 1062 // Fill in hole or undefined. | 1062 // Fill in hole or undefined. |
| 1063 obj[first_undefined] = obj[last_defined]; | 1063 obj[first_undefined] = obj[last_defined]; |
| 1064 obj[last_defined] = void 0; | 1064 obj[last_defined] = UNDEFINED; |
| 1065 } | 1065 } |
| 1066 } | 1066 } |
| 1067 // If there were any undefineds in the entire array, first_undefined | 1067 // If there were any undefineds in the entire array, first_undefined |
| 1068 // points to one past the last defined element. Make this true if | 1068 // points to one past the last defined element. Make this true if |
| 1069 // there were no undefineds, as well, so that first_undefined == number | 1069 // there were no undefineds, as well, so that first_undefined == number |
| 1070 // of defined elements. | 1070 // of defined elements. |
| 1071 if (!IS_UNDEFINED(obj[first_undefined])) first_undefined++; | 1071 if (!IS_UNDEFINED(obj[first_undefined])) first_undefined++; |
| 1072 // Fill in the undefineds and the holes. There may be a hole where | 1072 // Fill in the undefineds and the holes. There may be a hole where |
| 1073 // an undefined should be and vice versa. | 1073 // an undefined should be and vice versa. |
| 1074 var i; | 1074 var i; |
| 1075 for (i = first_undefined; i < length - num_holes; i++) { | 1075 for (i = first_undefined; i < length - num_holes; i++) { |
| 1076 obj[i] = void 0; | 1076 obj[i] = UNDEFINED; |
| 1077 } | 1077 } |
| 1078 for (i = length - num_holes; i < length; i++) { | 1078 for (i = length - num_holes; i < length; i++) { |
| 1079 // For compatability with Webkit, do not expose elements in the prototype. | 1079 // For compatability with Webkit, do not expose elements in the prototype. |
| 1080 if (i in %GetPrototype(obj)) { | 1080 if (i in %GetPrototype(obj)) { |
| 1081 obj[i] = void 0; | 1081 obj[i] = UNDEFINED; |
| 1082 } else { | 1082 } else { |
| 1083 delete obj[i]; | 1083 delete obj[i]; |
| 1084 } | 1084 } |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 // Return the number of defined elements. | 1087 // Return the number of defined elements. |
| 1088 return first_undefined; | 1088 return first_undefined; |
| 1089 }; | 1089 }; |
| 1090 | 1090 |
| 1091 var length = TO_UINT32(this.length); | 1091 var length = TO_UINT32(this.length); |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 )); | 1652 )); |
| 1653 | 1653 |
| 1654 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1654 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
| 1655 "join", getFunction("join", ArrayJoin), | 1655 "join", getFunction("join", ArrayJoin), |
| 1656 "pop", getFunction("pop", ArrayPop), | 1656 "pop", getFunction("pop", ArrayPop), |
| 1657 "push", getFunction("push", ArrayPush) | 1657 "push", getFunction("push", ArrayPush) |
| 1658 )); | 1658 )); |
| 1659 } | 1659 } |
| 1660 | 1660 |
| 1661 SetUpArray(); | 1661 SetUpArray(); |
| OLD | NEW |