OLD | NEW |
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 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 // array.js has to come before typedarray.js for this to work | 14 // array.js has to come before typedarray.js for this to work |
15 var ArrayToString = utils.ImportNow("ArrayToString"); | 15 var ArrayToString = utils.ImportNow("ArrayToString"); |
16 var ArrayValues; | 16 var ArrayValues; |
17 var GetIterator; | 17 var GetIterator; |
18 var GetMethod; | 18 var GetMethod; |
19 var GlobalArray = global.Array; | 19 var GlobalArray = global.Array; |
20 var GlobalArrayBuffer = global.ArrayBuffer; | 20 var GlobalArrayBuffer = global.ArrayBuffer; |
21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; | 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; |
22 var GlobalObject = global.Object; | 22 var GlobalObject = global.Object; |
23 var InnerArrayFilter; | |
24 var InnerArrayFind; | 23 var InnerArrayFind; |
25 var InnerArrayFindIndex; | 24 var InnerArrayFindIndex; |
26 var InnerArrayJoin; | 25 var InnerArrayJoin; |
27 var InnerArraySort; | 26 var InnerArraySort; |
28 var InnerArrayToLocaleString; | 27 var InnerArrayToLocaleString; |
29 var InternalArray = utils.InternalArray; | 28 var InternalArray = utils.InternalArray; |
30 var MaxSimple; | 29 var MaxSimple; |
31 var MinSimple; | 30 var MinSimple; |
32 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 31 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
33 var speciesSymbol = utils.ImportNow("species_symbol"); | 32 var speciesSymbol = utils.ImportNow("species_symbol"); |
(...skipping 16 matching lines...) Expand all Loading... |
50 endmacro | 49 endmacro |
51 | 50 |
52 TYPED_ARRAYS(DECLARE_GLOBALS) | 51 TYPED_ARRAYS(DECLARE_GLOBALS) |
53 | 52 |
54 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); | 53 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); |
55 | 54 |
56 utils.Import(function(from) { | 55 utils.Import(function(from) { |
57 ArrayValues = from.ArrayValues; | 56 ArrayValues = from.ArrayValues; |
58 GetIterator = from.GetIterator; | 57 GetIterator = from.GetIterator; |
59 GetMethod = from.GetMethod; | 58 GetMethod = from.GetMethod; |
60 InnerArrayFilter = from.InnerArrayFilter; | |
61 InnerArrayFind = from.InnerArrayFind; | 59 InnerArrayFind = from.InnerArrayFind; |
62 InnerArrayFindIndex = from.InnerArrayFindIndex; | 60 InnerArrayFindIndex = from.InnerArrayFindIndex; |
63 InnerArrayJoin = from.InnerArrayJoin; | 61 InnerArrayJoin = from.InnerArrayJoin; |
64 InnerArraySort = from.InnerArraySort; | 62 InnerArraySort = from.InnerArraySort; |
65 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 63 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
66 MaxSimple = from.MaxSimple; | 64 MaxSimple = from.MaxSimple; |
67 MinSimple = from.MinSimple; | 65 MinSimple = from.MinSimple; |
68 }); | 66 }); |
69 | 67 |
70 // ES2015 7.3.20 | 68 // ES2015 7.3.20 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // ES6 draft 08-24-14, section 22.2.3.12 | 406 // ES6 draft 08-24-14, section 22.2.3.12 |
409 function TypedArrayForEach(f, receiver) { | 407 function TypedArrayForEach(f, receiver) { |
410 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 408 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
411 | 409 |
412 var length = %_TypedArrayGetLength(this); | 410 var length = %_TypedArrayGetLength(this); |
413 | 411 |
414 InnerTypedArrayForEach(f, receiver, this, length); | 412 InnerTypedArrayForEach(f, receiver, this, length); |
415 } | 413 } |
416 %FunctionSetLength(TypedArrayForEach, 1); | 414 %FunctionSetLength(TypedArrayForEach, 1); |
417 | 415 |
| 416 // The following functions cannot be made efficient on sparse arrays while |
| 417 // preserving the semantics, since the calls to the receiver function can add |
| 418 // or delete elements from the array. |
| 419 function InnerTypedArrayFilter(f, receiver, array, length, result) { |
| 420 var result_length = 0; |
| 421 for (var i = 0; i < length; i++) { |
| 422 if (i in array) { |
| 423 var element = array[i]; |
| 424 if (%_Call(f, receiver, element, i, array)) { |
| 425 %CreateDataProperty(result, result_length, element); |
| 426 result_length++; |
| 427 } |
| 428 } |
| 429 } |
| 430 return result; |
| 431 } |
| 432 |
418 | 433 |
419 // ES6 draft 07-15-13, section 22.2.3.9 | 434 // ES6 draft 07-15-13, section 22.2.3.9 |
420 function TypedArrayFilter(f, thisArg) { | 435 function TypedArrayFilter(f, thisArg) { |
421 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 436 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
422 | 437 |
423 var length = %_TypedArrayGetLength(this); | 438 var length = %_TypedArrayGetLength(this); |
424 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 439 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
425 var result = new InternalArray(); | 440 var result = new InternalArray(); |
426 InnerArrayFilter(f, thisArg, this, length, result); | 441 InnerTypedArrayFilter(f, thisArg, this, length, result); |
427 var captured = result.length; | 442 var captured = result.length; |
428 var output = TypedArraySpeciesCreate(this, captured); | 443 var output = TypedArraySpeciesCreate(this, captured); |
429 for (var i = 0; i < captured; i++) { | 444 for (var i = 0; i < captured; i++) { |
430 output[i] = result[i]; | 445 output[i] = result[i]; |
431 } | 446 } |
432 return output; | 447 return output; |
433 } | 448 } |
434 %FunctionSetLength(TypedArrayFilter, 1); | 449 %FunctionSetLength(TypedArrayFilter, 1); |
435 | 450 |
436 | 451 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 %AddNamedProperty(GlobalNAME.prototype, | 720 %AddNamedProperty(GlobalNAME.prototype, |
706 "constructor", global.NAME, DONT_ENUM); | 721 "constructor", global.NAME, DONT_ENUM); |
707 %AddNamedProperty(GlobalNAME.prototype, | 722 %AddNamedProperty(GlobalNAME.prototype, |
708 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 723 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
709 READ_ONLY | DONT_ENUM | DONT_DELETE); | 724 READ_ONLY | DONT_ENUM | DONT_DELETE); |
710 endmacro | 725 endmacro |
711 | 726 |
712 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 727 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
713 | 728 |
714 }) | 729 }) |
OLD | NEW |