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

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

Issue 1325573004: [runtime] Replace many buggy uses of %_CallFunction with %_Call. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address feedback. Created 5 years, 3 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 | « src/full-codegen/x64/full-codegen-x64.cc ('k') | src/harmony-typedarray.js » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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) { 5 (function(global, utils) {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 var length = $toLength(array.length); 88 var length = $toLength(array.length);
89 89
90 return InnerArrayCopyWithin(target, start, end, array, length); 90 return InnerArrayCopyWithin(target, start, end, array, length);
91 } 91 }
92 92
93 function InnerArrayFind(predicate, thisArg, array, length) { 93 function InnerArrayFind(predicate, thisArg, array, length) {
94 if (!IS_CALLABLE(predicate)) { 94 if (!IS_CALLABLE(predicate)) {
95 throw MakeTypeError(kCalledNonCallable, predicate); 95 throw MakeTypeError(kCalledNonCallable, predicate);
96 } 96 }
97 97
98 var needs_wrapper = false;
99 if (IS_NULL(thisArg)) {
100 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
101 } else if (!IS_UNDEFINED(thisArg)) {
102 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
103 }
104
105 for (var i = 0; i < length; i++) { 98 for (var i = 0; i < length; i++) {
106 var element = array[i]; 99 var element = array[i];
107 var newThisArg = needs_wrapper ? TO_OBJECT(thisArg) : thisArg; 100 if (%_Call(predicate, thisArg, element, i, array)) {
108 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
109 return element; 101 return element;
110 } 102 }
111 } 103 }
112 104
113 return; 105 return;
114 } 106 }
115 107
116 // ES6 draft 07-15-13, section 15.4.3.23 108 // ES6 draft 07-15-13, section 15.4.3.23
117 function ArrayFind(predicate, thisArg) { 109 function ArrayFind(predicate, thisArg) {
118 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); 110 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
119 111
120 var array = TO_OBJECT(this); 112 var array = TO_OBJECT(this);
121 var length = $toInteger(array.length); 113 var length = $toInteger(array.length);
122 114
123 return InnerArrayFind(predicate, thisArg, array, length); 115 return InnerArrayFind(predicate, thisArg, array, length);
124 } 116 }
125 117
126 function InnerArrayFindIndex(predicate, thisArg, array, length) { 118 function InnerArrayFindIndex(predicate, thisArg, array, length) {
127 if (!IS_CALLABLE(predicate)) { 119 if (!IS_CALLABLE(predicate)) {
128 throw MakeTypeError(kCalledNonCallable, predicate); 120 throw MakeTypeError(kCalledNonCallable, predicate);
129 } 121 }
130 122
131 var needs_wrapper = false;
132 if (IS_NULL(thisArg)) {
133 if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
134 } else if (!IS_UNDEFINED(thisArg)) {
135 needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
136 }
137
138 for (var i = 0; i < length; i++) { 123 for (var i = 0; i < length; i++) {
139 var element = array[i]; 124 var element = array[i];
140 var newThisArg = needs_wrapper ? TO_OBJECT(thisArg) : thisArg; 125 if (%_Call(predicate, thisArg, element, i, array)) {
141 if (%_CallFunction(newThisArg, element, i, array, predicate)) {
142 return i; 126 return i;
143 } 127 }
144 } 128 }
145 129
146 return -1; 130 return -1;
147 } 131 }
148 132
149 // ES6 draft 07-15-13, section 15.4.3.24 133 // ES6 draft 07-15-13, section 15.4.3.24
150 function ArrayFindIndex(predicate, thisArg) { 134 function ArrayFindIndex(predicate, thisArg) {
151 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); 135 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 189 }
206 190
207 // ES6, draft 10-14-14, section 22.1.2.1 191 // ES6, draft 10-14-14, section 22.1.2.1
208 function ArrayFrom(arrayLike, mapfn, receiver) { 192 function ArrayFrom(arrayLike, mapfn, receiver) {
209 var items = TO_OBJECT(arrayLike); 193 var items = TO_OBJECT(arrayLike);
210 var mapping = !IS_UNDEFINED(mapfn); 194 var mapping = !IS_UNDEFINED(mapfn);
211 195
212 if (mapping) { 196 if (mapping) {
213 if (!IS_CALLABLE(mapfn)) { 197 if (!IS_CALLABLE(mapfn)) {
214 throw MakeTypeError(kCalledNonCallable, mapfn); 198 throw MakeTypeError(kCalledNonCallable, mapfn);
215 } else if (%IsSloppyModeFunction(mapfn)) {
216 if (IS_NULL(receiver)) {
217 receiver = UNDEFINED;
218 } else if (!IS_UNDEFINED(receiver)) {
219 receiver = TO_OBJECT(receiver);
220 }
221 } 199 }
222 } 200 }
223 201
224 var iterable = GetMethod(items, iteratorSymbol); 202 var iterable = GetMethod(items, iteratorSymbol);
225 var k; 203 var k;
226 var result; 204 var result;
227 var mappedValue; 205 var mappedValue;
228 var nextValue; 206 var nextValue;
229 207
230 if (!IS_UNDEFINED(iterable)) { 208 if (!IS_UNDEFINED(iterable)) {
231 result = %IsConstructor(this) ? new this() : []; 209 result = %IsConstructor(this) ? new this() : [];
232 210
233 var iterator = GetIterator(items, iterable); 211 var iterator = GetIterator(items, iterable);
234 212
235 k = 0; 213 k = 0;
236 while (true) { 214 while (true) {
237 var next = iterator.next(); 215 var next = iterator.next();
238 216
239 if (!IS_OBJECT(next)) { 217 if (!IS_OBJECT(next)) {
240 throw MakeTypeError(kIteratorResultNotAnObject, next); 218 throw MakeTypeError(kIteratorResultNotAnObject, next);
241 } 219 }
242 220
243 if (next.done) { 221 if (next.done) {
244 result.length = k; 222 result.length = k;
245 return result; 223 return result;
246 } 224 }
247 225
248 nextValue = next.value; 226 nextValue = next.value;
249 if (mapping) { 227 if (mapping) {
250 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); 228 mappedValue = %_Call(mapfn, receiver, nextValue, k);
251 } else { 229 } else {
252 mappedValue = nextValue; 230 mappedValue = nextValue;
253 } 231 }
254 AddArrayElement(this, result, k, mappedValue); 232 AddArrayElement(this, result, k, mappedValue);
255 k++; 233 k++;
256 } 234 }
257 } else { 235 } else {
258 var len = $toLength(items.length); 236 var len = $toLength(items.length);
259 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len); 237 result = %IsConstructor(this) ? new this(len) : new GlobalArray(len);
260 238
261 for (k = 0; k < len; ++k) { 239 for (k = 0; k < len; ++k) {
262 nextValue = items[k]; 240 nextValue = items[k];
263 if (mapping) { 241 if (mapping) {
264 mappedValue = %_CallFunction(receiver, nextValue, k, mapfn); 242 mappedValue = %_Call(mapfn, receiver, nextValue, k);
265 } else { 243 } else {
266 mappedValue = nextValue; 244 mappedValue = nextValue;
267 } 245 }
268 AddArrayElement(this, result, k, mappedValue); 246 AddArrayElement(this, result, k, mappedValue);
269 } 247 }
270 248
271 result.length = k; 249 result.length = k;
272 return result; 250 return result;
273 } 251 }
274 } 252 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 291
314 utils.Export(function(to) { 292 utils.Export(function(to) {
315 to.ArrayFrom = ArrayFrom; 293 to.ArrayFrom = ArrayFrom;
316 to.InnerArrayCopyWithin = InnerArrayCopyWithin; 294 to.InnerArrayCopyWithin = InnerArrayCopyWithin;
317 to.InnerArrayFill = InnerArrayFill; 295 to.InnerArrayFill = InnerArrayFill;
318 to.InnerArrayFind = InnerArrayFind; 296 to.InnerArrayFind = InnerArrayFind;
319 to.InnerArrayFindIndex = InnerArrayFindIndex; 297 to.InnerArrayFindIndex = InnerArrayFindIndex;
320 }); 298 });
321 299
322 }) 300 })
OLDNEW
« no previous file with comments | « src/full-codegen/x64/full-codegen-x64.cc ('k') | src/harmony-typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698