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

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

Issue 1154483002: Hook up more import/exports in natives. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
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 var $innerArrayCopyWithin;
6 var $innerArrayFill;
7 var $innerArrayFind;
8 var $innerArrayFindIndex;
9 var $arrayFrom;
10
11 (function(global, utils) { 5 (function(global, utils) {
12 6
13 'use strict'; 7 'use strict';
14 8
15 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
16 10
17 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
18 // Imports 12 // Imports
19 13
20 var GlobalArray = global.Array; 14 var GlobalArray = global.Array;
21 var GlobalSymbol = global.Symbol; 15 var GlobalSymbol = global.Symbol;
22 16
17 var GetIterator;
18 var GetMethod;
23 var MathMax; 19 var MathMax;
24 var MathMin; 20 var MathMin;
21 var ObjectIsFrozen;
25 22
26 utils.Import(function(from) { 23 utils.Import(function(from) {
24 GetIterator = from.GetIterator;
25 GetMethod = from.GetMethod;
27 MathMax = from.MathMax; 26 MathMax = from.MathMax;
28 MathMin = from.MathMin; 27 MathMin = from.MathMin;
28 ObjectIsFrozen = from.ObjectIsFrozen;
29 }); 29 });
30 30
31 // ------------------------------------------------------------------- 31 // -------------------------------------------------------------------
32 32
33 function InnerArrayCopyWithin(target, start, end, array, length) { 33 function InnerArrayCopyWithin(target, start, end, array, length) {
34 target = TO_INTEGER(target); 34 target = TO_INTEGER(target);
35 var to; 35 var to;
36 if (target < 0) { 36 if (target < 0) {
37 to = MathMax(length + target, 0); 37 to = MathMax(length + target, 0);
38 } else { 38 } else {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (i > length) i = length; 172 if (i > length) i = length;
173 } 173 }
174 174
175 if (end < 0) { 175 if (end < 0) {
176 end += length; 176 end += length;
177 if (end < 0) end = 0; 177 if (end < 0) end = 0;
178 } else { 178 } else {
179 if (end > length) end = length; 179 if (end > length) end = length;
180 } 180 }
181 181
182 if ((end - i) > 0 && $objectIsFrozen(array)) { 182 if ((end - i) > 0 && ObjectIsFrozen(array)) {
183 throw MakeTypeError(kArrayFunctionsOnFrozen); 183 throw MakeTypeError(kArrayFunctionsOnFrozen);
184 } 184 }
185 185
186 for (; i < end; i++) 186 for (; i < end; i++)
187 array[i] = value; 187 array[i] = value;
188 return array; 188 return array;
189 } 189 }
190 $innerArrayFill = InnerArrayFill; 190 $innerArrayFill = InnerArrayFill;
191 191
192 // ES6, draft 04-05-14, section 22.1.3.6 192 // ES6, draft 04-05-14, section 22.1.3.6
(...skipping 16 matching lines...) Expand all
209 throw MakeTypeError(kCalledNonCallable, mapfn); 209 throw MakeTypeError(kCalledNonCallable, mapfn);
210 } else if (%IsSloppyModeFunction(mapfn)) { 210 } else if (%IsSloppyModeFunction(mapfn)) {
211 if (IS_NULL(receiver)) { 211 if (IS_NULL(receiver)) {
212 receiver = UNDEFINED; 212 receiver = UNDEFINED;
213 } else if (!IS_UNDEFINED(receiver)) { 213 } else if (!IS_UNDEFINED(receiver)) {
214 receiver = TO_OBJECT_INLINE(receiver); 214 receiver = TO_OBJECT_INLINE(receiver);
215 } 215 }
216 } 216 }
217 } 217 }
218 218
219 var iterable = $getMethod(items, symbolIterator); 219 var iterable = GetMethod(items, symbolIterator);
220 var k; 220 var k;
221 var result; 221 var result;
222 var mappedValue; 222 var mappedValue;
223 var nextValue; 223 var nextValue;
224 224
225 if (!IS_UNDEFINED(iterable)) { 225 if (!IS_UNDEFINED(iterable)) {
226 result = %IsConstructor(this) ? new this() : []; 226 result = %IsConstructor(this) ? new this() : [];
227 227
228 var iterator = $getIterator(items, iterable); 228 var iterator = GetIterator(items, iterable);
229 229
230 k = 0; 230 k = 0;
231 while (true) { 231 while (true) {
232 var next = iterator.next(); 232 var next = iterator.next();
233 233
234 if (!IS_OBJECT(next)) { 234 if (!IS_OBJECT(next)) {
235 throw MakeTypeError(kIteratorResultNotAnObject, next); 235 throw MakeTypeError(kIteratorResultNotAnObject, next);
236 } 236 }
237 237
238 if (next.done) { 238 if (next.done) {
(...skipping 20 matching lines...) Expand all
259 } else { 259 } else {
260 mappedValue = nextValue; 260 mappedValue = nextValue;
261 } 261 }
262 %AddElement(result, k, mappedValue, NONE); 262 %AddElement(result, k, mappedValue, NONE);
263 } 263 }
264 264
265 result.length = k; 265 result.length = k;
266 return result; 266 return result;
267 } 267 }
268 } 268 }
269 $arrayFrom = ArrayFrom; 269
Jakob Kummerow 2015/05/21 13:45:24 nit: surrounding code seems to be happy with just
270 270
271 // ES6, draft 05-22-14, section 22.1.2.3 271 // ES6, draft 05-22-14, section 22.1.2.3
272 function ArrayOf() { 272 function ArrayOf() {
273 var length = %_ArgumentsLength(); 273 var length = %_ArgumentsLength();
274 var constructor = this; 274 var constructor = this;
275 // TODO: Implement IsConstructor (ES6 section 7.2.5) 275 // TODO: Implement IsConstructor (ES6 section 7.2.5)
276 var array = %IsConstructor(constructor) ? new constructor(length) : []; 276 var array = %IsConstructor(constructor) ? new constructor(length) : [];
277 for (var i = 0; i < length; i++) { 277 for (var i = 0; i < length; i++) {
278 %AddElement(array, i, %_Arguments(i), NONE); 278 %AddElement(array, i, %_Arguments(i), NONE);
279 } 279 }
280 array.length = length; 280 array.length = length;
281 return array; 281 return array;
282 } 282 }
283 283
284 // ------------------------------------------------------------------- 284 // -------------------------------------------------------------------
285 285
286 $installConstants(GlobalSymbol, [ 286 utils.InstallConstants(GlobalSymbol, [
287 // TODO(dslomov, caitp): Move to symbol.js when shipping 287 // TODO(dslomov, caitp): Move to symbol.js when shipping
288 "isConcatSpreadable", symbolIsConcatSpreadable 288 "isConcatSpreadable", symbolIsConcatSpreadable
289 ]); 289 ]);
290 290
291 %FunctionSetLength(ArrayCopyWithin, 2); 291 %FunctionSetLength(ArrayCopyWithin, 2);
292 %FunctionSetLength(ArrayFrom, 1); 292 %FunctionSetLength(ArrayFrom, 1);
293 %FunctionSetLength(ArrayFill, 1); 293 %FunctionSetLength(ArrayFill, 1);
294 %FunctionSetLength(ArrayFind, 1); 294 %FunctionSetLength(ArrayFind, 1);
295 %FunctionSetLength(ArrayFindIndex, 1); 295 %FunctionSetLength(ArrayFindIndex, 1);
296 296
297 // Set up non-enumerable functions on the Array object. 297 // Set up non-enumerable functions on the Array object.
298 $installFunctions(GlobalArray, DONT_ENUM, [ 298 utils.InstallFunctions(GlobalArray, DONT_ENUM, [
299 "from", ArrayFrom, 299 "from", ArrayFrom,
300 "of", ArrayOf 300 "of", ArrayOf
301 ]); 301 ]);
302 302
303 // Set up the non-enumerable functions on the Array prototype object. 303 // Set up the non-enumerable functions on the Array prototype object.
304 $installFunctions(GlobalArray.prototype, DONT_ENUM, [ 304 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
305 "copyWithin", ArrayCopyWithin, 305 "copyWithin", ArrayCopyWithin,
306 "find", ArrayFind, 306 "find", ArrayFind,
307 "findIndex", ArrayFindIndex, 307 "findIndex", ArrayFindIndex,
308 "fill", ArrayFill 308 "fill", ArrayFill
309 ]); 309 ]);
310 310
311 // -------------------------------------------------------------------
312 // Exports
313
314 utils.Export(function(to) {
315 to.ArrayFrom = ArrayFrom;
316 to.InnerArrayCopyWithin = InnerArrayCopyWithin;
317 to.InnerArrayFill = InnerArrayFill;
318 to.InnerArrayFind = InnerArrayFind;
319 to.InnerArrayFindIndex = InnerArrayFindIndex;
320 });
321
311 }) 322 })
OLDNEW
« no previous file with comments | « src/generator.js ('k') | src/harmony-array-includes.js » ('j') | src/harmony-typedarray.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698