| 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 SpeciesConstructor; | 31 var SpeciesConstructor; |
| 33 var ToPositiveInteger; | 32 var ToPositiveInteger; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 endmacro | 51 endmacro |
| 53 | 52 |
| 54 TYPED_ARRAYS(DECLARE_GLOBALS) | 53 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 55 | 54 |
| 56 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); | 55 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); |
| 57 | 56 |
| 58 utils.Import(function(from) { | 57 utils.Import(function(from) { |
| 59 ArrayValues = from.ArrayValues; | 58 ArrayValues = from.ArrayValues; |
| 60 GetIterator = from.GetIterator; | 59 GetIterator = from.GetIterator; |
| 61 GetMethod = from.GetMethod; | 60 GetMethod = from.GetMethod; |
| 62 InnerArrayFilter = from.InnerArrayFilter; | |
| 63 InnerArrayFind = from.InnerArrayFind; | 61 InnerArrayFind = from.InnerArrayFind; |
| 64 InnerArrayFindIndex = from.InnerArrayFindIndex; | 62 InnerArrayFindIndex = from.InnerArrayFindIndex; |
| 65 InnerArrayJoin = from.InnerArrayJoin; | 63 InnerArrayJoin = from.InnerArrayJoin; |
| 66 InnerArraySort = from.InnerArraySort; | 64 InnerArraySort = from.InnerArraySort; |
| 67 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 65 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
| 68 MaxSimple = from.MaxSimple; | 66 MaxSimple = from.MaxSimple; |
| 69 MinSimple = from.MinSimple; | 67 MinSimple = from.MinSimple; |
| 70 SpeciesConstructor = from.SpeciesConstructor; | 68 SpeciesConstructor = from.SpeciesConstructor; |
| 71 ToPositiveInteger = from.ToPositiveInteger; | 69 ToPositiveInteger = from.ToPositiveInteger; |
| 72 ToIndex = from.ToIndex; | 70 ToIndex = from.ToIndex; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // ES6 draft 08-24-14, section 22.2.3.12 | 389 // ES6 draft 08-24-14, section 22.2.3.12 |
| 392 function TypedArrayForEach(f, receiver) { | 390 function TypedArrayForEach(f, receiver) { |
| 393 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 391 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 394 | 392 |
| 395 var length = %_TypedArrayGetLength(this); | 393 var length = %_TypedArrayGetLength(this); |
| 396 | 394 |
| 397 InnerTypedArrayForEach(f, receiver, this, length); | 395 InnerTypedArrayForEach(f, receiver, this, length); |
| 398 } | 396 } |
| 399 %FunctionSetLength(TypedArrayForEach, 1); | 397 %FunctionSetLength(TypedArrayForEach, 1); |
| 400 | 398 |
| 399 // The following functions cannot be made efficient on sparse arrays while |
| 400 // preserving the semantics, since the calls to the receiver function can add |
| 401 // or delete elements from the array. |
| 402 function InnerTypedArrayFilter(f, receiver, array, length, result) { |
| 403 var result_length = 0; |
| 404 for (var i = 0; i < length; i++) { |
| 405 if (i in array) { |
| 406 var element = array[i]; |
| 407 if (%_Call(f, receiver, element, i, array)) { |
| 408 %CreateDataProperty(result, result_length, element); |
| 409 result_length++; |
| 410 } |
| 411 } |
| 412 } |
| 413 return result; |
| 414 } |
| 415 |
| 401 | 416 |
| 402 // ES6 draft 07-15-13, section 22.2.3.9 | 417 // ES6 draft 07-15-13, section 22.2.3.9 |
| 403 function TypedArrayFilter(f, thisArg) { | 418 function TypedArrayFilter(f, thisArg) { |
| 404 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 419 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 405 | 420 |
| 406 var length = %_TypedArrayGetLength(this); | 421 var length = %_TypedArrayGetLength(this); |
| 407 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 422 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 408 var result = new InternalArray(); | 423 var result = new InternalArray(); |
| 409 InnerArrayFilter(f, thisArg, this, length, result); | 424 InnerTypedArrayFilter(f, thisArg, this, length, result); |
| 410 var captured = result.length; | 425 var captured = result.length; |
| 411 var output = TypedArraySpeciesCreate(this, captured); | 426 var output = TypedArraySpeciesCreate(this, captured); |
| 412 for (var i = 0; i < captured; i++) { | 427 for (var i = 0; i < captured; i++) { |
| 413 output[i] = result[i]; | 428 output[i] = result[i]; |
| 414 } | 429 } |
| 415 return output; | 430 return output; |
| 416 } | 431 } |
| 417 %FunctionSetLength(TypedArrayFilter, 1); | 432 %FunctionSetLength(TypedArrayFilter, 1); |
| 418 | 433 |
| 419 | 434 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 %AddNamedProperty(GlobalNAME.prototype, | 747 %AddNamedProperty(GlobalNAME.prototype, |
| 733 "constructor", global.NAME, DONT_ENUM); | 748 "constructor", global.NAME, DONT_ENUM); |
| 734 %AddNamedProperty(GlobalNAME.prototype, | 749 %AddNamedProperty(GlobalNAME.prototype, |
| 735 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 750 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 736 READ_ONLY | DONT_ENUM | DONT_DELETE); | 751 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 737 endmacro | 752 endmacro |
| 738 | 753 |
| 739 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 754 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 740 | 755 |
| 741 }) | 756 }) |
| OLD | NEW |