Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/js/array.js

Issue 1950073002: Convert negative zero in ArraySpeciesCreate (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/js/macros.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 25 matching lines...) Expand all
36 36
37 utils.ImportFromExperimental(function(from) { 37 utils.ImportFromExperimental(function(from) {
38 FLAG_harmony_species = from.FLAG_harmony_species; 38 FLAG_harmony_species = from.FLAG_harmony_species;
39 }); 39 });
40 40
41 // ------------------------------------------------------------------- 41 // -------------------------------------------------------------------
42 42
43 43
44 function ArraySpeciesCreate(array, length) { 44 function ArraySpeciesCreate(array, length) {
45 var constructor; 45 var constructor;
46
47 length = INVERT_NEG_ZERO(length);
48
46 if (FLAG_harmony_species) { 49 if (FLAG_harmony_species) {
47 constructor = %ArraySpeciesConstructor(array); 50 constructor = %ArraySpeciesConstructor(array);
48 } else { 51 } else {
49 constructor = GlobalArray; 52 constructor = GlobalArray;
50 } 53 }
51 return new constructor(length); 54 return new constructor(length);
52 } 55 }
53 56
54 57
55 function KeySortCompare(a, b) { 58 function KeySortCompare(a, b) {
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 1189
1187 // For .indexOf, we don't need to pass in the number of arguments 1190 // For .indexOf, we don't need to pass in the number of arguments
1188 // at the callsite since ToInteger(undefined) == 0; however, for 1191 // at the callsite since ToInteger(undefined) == 0; however, for
1189 // .lastIndexOf, we need to pass it, since the behavior for passing 1192 // .lastIndexOf, we need to pass it, since the behavior for passing
1190 // undefined is 0 but for not including the argument is length-1. 1193 // undefined is 0 but for not including the argument is length-1.
1191 function InnerArrayIndexOf(array, element, index, length) { 1194 function InnerArrayIndexOf(array, element, index, length) {
1192 if (length == 0) return -1; 1195 if (length == 0) return -1;
1193 if (IS_UNDEFINED(index)) { 1196 if (IS_UNDEFINED(index)) {
1194 index = 0; 1197 index = 0;
1195 } else { 1198 } else {
1196 index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0 1199 index = INVERT_NEG_ZERO(TO_INTEGER(index));
1197 // If index is negative, index from the end of the array. 1200 // If index is negative, index from the end of the array.
1198 if (index < 0) { 1201 if (index < 0) {
1199 index = length + index; 1202 index = length + index;
1200 // If index is still negative, search the entire array. 1203 // If index is still negative, search the entire array.
1201 if (index < 0) index = 0; 1204 if (index < 0) index = 0;
1202 } 1205 }
1203 } 1206 }
1204 var min = index; 1207 var min = index;
1205 var max = length; 1208 var max = length;
1206 if (UseSparseVariant(array, length, IS_ARRAY(array), max - min)) { 1209 if (UseSparseVariant(array, length, IS_ARRAY(array), max - min)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 var length = TO_LENGTH(this.length); 1251 var length = TO_LENGTH(this.length);
1249 return InnerArrayIndexOf(this, element, index, length); 1252 return InnerArrayIndexOf(this, element, index, length);
1250 } 1253 }
1251 1254
1252 1255
1253 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) { 1256 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) {
1254 if (length == 0) return -1; 1257 if (length == 0) return -1;
1255 if (argumentsLength < 2) { 1258 if (argumentsLength < 2) {
1256 index = length - 1; 1259 index = length - 1;
1257 } else { 1260 } else {
1258 index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0 1261 index = TO_INTEGER(index) + 0; // Add 0 to convert -0 to 0
Dan Ehrenberg 2016/05/04 17:52:24 Also call the macro from here
1259 // If index is negative, index from end of the array. 1262 // If index is negative, index from end of the array.
1260 if (index < 0) index += length; 1263 if (index < 0) index += length;
1261 // If index is still negative, do not search the array. 1264 // If index is still negative, do not search the array.
1262 if (index < 0) return -1; 1265 if (index < 0) return -1;
1263 else if (index >= length) index = length - 1; 1266 else if (index >= length) index = length - 1;
1264 } 1267 }
1265 var min = 0; 1268 var min = 0;
1266 var max = index; 1269 var max = index;
1267 if (UseSparseVariant(array, length, IS_ARRAY(array), index)) { 1270 if (UseSparseVariant(array, length, IS_ARRAY(array), index)) {
1268 %NormalizeElements(array); 1271 %NormalizeElements(array);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 %InstallToContext([ 1793 %InstallToContext([
1791 "array_pop", ArrayPop, 1794 "array_pop", ArrayPop,
1792 "array_push", ArrayPush, 1795 "array_push", ArrayPush,
1793 "array_shift", ArrayShift, 1796 "array_shift", ArrayShift,
1794 "array_splice", ArraySplice, 1797 "array_splice", ArraySplice,
1795 "array_slice", ArraySlice, 1798 "array_slice", ArraySlice,
1796 "array_unshift", ArrayUnshift, 1799 "array_unshift", ArrayUnshift,
1797 ]); 1800 ]);
1798 1801
1799 }); 1802 });
OLDNEW
« no previous file with comments | « no previous file | src/js/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698