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 InnerArrayEvery; | 23 var InnerArrayFill; |
24 var InnerArrayFilter; | 24 var InnerArrayFilter; |
25 var InnerArrayFind; | 25 var InnerArrayFind; |
26 var InnerArrayFindIndex; | 26 var InnerArrayFindIndex; |
27 var InnerArrayForEach; | |
28 var InnerArrayJoin; | 27 var InnerArrayJoin; |
29 var InnerArrayReduce; | 28 var InnerArrayReduce; |
30 var InnerArrayReduceRight; | 29 var InnerArrayReduceRight; |
31 var InnerArraySome; | |
32 var InnerArraySort; | 30 var InnerArraySort; |
33 var InnerArrayToLocaleString; | 31 var InnerArrayToLocaleString; |
34 var InternalArray = utils.InternalArray; | 32 var InternalArray = utils.InternalArray; |
35 var MaxSimple; | 33 var MaxSimple; |
36 var MinSimple; | 34 var MinSimple; |
37 var PackedArrayReverse; | 35 var PackedArrayReverse; |
38 var SpeciesConstructor; | 36 var SpeciesConstructor; |
39 var ToPositiveInteger; | 37 var ToPositiveInteger; |
40 var ToIndex; | 38 var ToIndex; |
41 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 39 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
(...skipping 17 matching lines...) Expand all Loading... |
59 endmacro | 57 endmacro |
60 | 58 |
61 TYPED_ARRAYS(DECLARE_GLOBALS) | 59 TYPED_ARRAYS(DECLARE_GLOBALS) |
62 | 60 |
63 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); | 61 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); |
64 | 62 |
65 utils.Import(function(from) { | 63 utils.Import(function(from) { |
66 ArrayValues = from.ArrayValues; | 64 ArrayValues = from.ArrayValues; |
67 GetIterator = from.GetIterator; | 65 GetIterator = from.GetIterator; |
68 GetMethod = from.GetMethod; | 66 GetMethod = from.GetMethod; |
69 InnerArrayEvery = from.InnerArrayEvery; | 67 InnerArrayFill = from.InnerArrayFill; |
70 InnerArrayFilter = from.InnerArrayFilter; | 68 InnerArrayFilter = from.InnerArrayFilter; |
71 InnerArrayFind = from.InnerArrayFind; | 69 InnerArrayFind = from.InnerArrayFind; |
72 InnerArrayFindIndex = from.InnerArrayFindIndex; | 70 InnerArrayFindIndex = from.InnerArrayFindIndex; |
73 InnerArrayForEach = from.InnerArrayForEach; | |
74 InnerArrayJoin = from.InnerArrayJoin; | 71 InnerArrayJoin = from.InnerArrayJoin; |
75 InnerArrayReduce = from.InnerArrayReduce; | 72 InnerArrayReduce = from.InnerArrayReduce; |
76 InnerArrayReduceRight = from.InnerArrayReduceRight; | 73 InnerArrayReduceRight = from.InnerArrayReduceRight; |
77 InnerArraySome = from.InnerArraySome; | |
78 InnerArraySort = from.InnerArraySort; | 74 InnerArraySort = from.InnerArraySort; |
79 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 75 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
80 MaxSimple = from.MaxSimple; | 76 MaxSimple = from.MaxSimple; |
81 MinSimple = from.MinSimple; | 77 MinSimple = from.MinSimple; |
82 PackedArrayReverse = from.PackedArrayReverse; | 78 PackedArrayReverse = from.PackedArrayReverse; |
83 SpeciesConstructor = from.SpeciesConstructor; | 79 SpeciesConstructor = from.SpeciesConstructor; |
84 ToPositiveInteger = from.ToPositiveInteger; | 80 ToPositiveInteger = from.ToPositiveInteger; |
85 ToIndex = from.ToIndex; | 81 ToIndex = from.ToIndex; |
86 }); | 82 }); |
87 | 83 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 360 } |
365 %FunctionSetLength(TypedArraySet, 1); | 361 %FunctionSetLength(TypedArraySet, 1); |
366 | 362 |
367 function TypedArrayGetToStringTag() { | 363 function TypedArrayGetToStringTag() { |
368 if (!IS_TYPEDARRAY(this)) return; | 364 if (!IS_TYPEDARRAY(this)) return; |
369 var name = %_ClassOf(this); | 365 var name = %_ClassOf(this); |
370 if (IS_UNDEFINED(name)) return; | 366 if (IS_UNDEFINED(name)) return; |
371 return name; | 367 return name; |
372 } | 368 } |
373 | 369 |
| 370 function InnerTypedArrayEvery(f, receiver, array, length) { |
| 371 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 372 |
| 373 for (var i = 0; i < length; i++) { |
| 374 if (i in array) { |
| 375 var element = array[i]; |
| 376 if (!%_Call(f, receiver, element, i, array)) return false; |
| 377 } |
| 378 } |
| 379 return true; |
| 380 } |
374 | 381 |
375 // ES6 draft 05-05-15, section 22.2.3.7 | 382 // ES6 draft 05-05-15, section 22.2.3.7 |
376 function TypedArrayEvery(f, receiver) { | 383 function TypedArrayEvery(f, receiver) { |
377 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 384 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
378 | 385 |
379 var length = %_TypedArrayGetLength(this); | 386 var length = %_TypedArrayGetLength(this); |
380 | 387 |
381 return InnerArrayEvery(f, receiver, this, length); | 388 return InnerTypedArrayEvery(f, receiver, this, length); |
382 } | 389 } |
383 %FunctionSetLength(TypedArrayEvery, 1); | 390 %FunctionSetLength(TypedArrayEvery, 1); |
384 | 391 |
| 392 function InnerTypedArrayForEach(f, receiver, array, length) { |
| 393 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 394 |
| 395 if (IS_UNDEFINED(receiver)) { |
| 396 for (var i = 0; i < length; i++) { |
| 397 if (i in array) { |
| 398 var element = array[i]; |
| 399 f(element, i, array); |
| 400 } |
| 401 } |
| 402 } else { |
| 403 for (var i = 0; i < length; i++) { |
| 404 if (i in array) { |
| 405 var element = array[i]; |
| 406 %_Call(f, receiver, element, i, array); |
| 407 } |
| 408 } |
| 409 } |
| 410 } |
385 | 411 |
386 // ES6 draft 08-24-14, section 22.2.3.12 | 412 // ES6 draft 08-24-14, section 22.2.3.12 |
387 function TypedArrayForEach(f, receiver) { | 413 function TypedArrayForEach(f, receiver) { |
388 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 414 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
389 | 415 |
390 var length = %_TypedArrayGetLength(this); | 416 var length = %_TypedArrayGetLength(this); |
391 | 417 |
392 InnerArrayForEach(f, receiver, this, length); | 418 InnerTypedArrayForEach(f, receiver, this, length); |
393 } | 419 } |
394 %FunctionSetLength(TypedArrayForEach, 1); | 420 %FunctionSetLength(TypedArrayForEach, 1); |
395 | 421 |
396 | 422 |
397 // ES6 draft 07-15-13, section 22.2.3.9 | 423 // ES6 draft 07-15-13, section 22.2.3.9 |
398 function TypedArrayFilter(f, thisArg) { | 424 function TypedArrayFilter(f, thisArg) { |
399 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 425 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
400 | 426 |
401 var length = %_TypedArrayGetLength(this); | 427 var length = %_TypedArrayGetLength(this); |
402 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 428 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 var result = TypedArraySpeciesCreate(this, length); | 491 var result = TypedArraySpeciesCreate(this, length); |
466 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 492 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
467 for (var i = 0; i < length; i++) { | 493 for (var i = 0; i < length; i++) { |
468 var element = this[i]; | 494 var element = this[i]; |
469 result[i] = %_Call(f, thisArg, element, i, this); | 495 result[i] = %_Call(f, thisArg, element, i, this); |
470 } | 496 } |
471 return result; | 497 return result; |
472 } | 498 } |
473 %FunctionSetLength(TypedArrayMap, 1); | 499 %FunctionSetLength(TypedArrayMap, 1); |
474 | 500 |
| 501 function InnerTypedArraySome(f, receiver, array, length) { |
| 502 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 503 |
| 504 for (var i = 0; i < length; i++) { |
| 505 if (i in array) { |
| 506 var element = array[i]; |
| 507 if (%_Call(f, receiver, element, i, array)) return true; |
| 508 } |
| 509 } |
| 510 return false; |
| 511 } |
475 | 512 |
476 // ES6 draft 05-05-15, section 22.2.3.24 | 513 // ES6 draft 05-05-15, section 22.2.3.24 |
477 function TypedArraySome(f, receiver) { | 514 function TypedArraySome(f, receiver) { |
478 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 515 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
479 | 516 |
480 var length = %_TypedArrayGetLength(this); | 517 var length = %_TypedArrayGetLength(this); |
481 | 518 |
482 return InnerArraySome(f, receiver, this, length); | 519 return InnerTypedArraySome(f, receiver, this, length); |
483 } | 520 } |
484 %FunctionSetLength(TypedArraySome, 1); | 521 %FunctionSetLength(TypedArraySome, 1); |
485 | 522 |
486 | 523 |
487 // ES6 section 22.2.3.27 | 524 // ES6 section 22.2.3.27 |
488 function TypedArrayToLocaleString() { | 525 function TypedArrayToLocaleString() { |
489 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 526 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
490 | 527 |
491 var length = %_TypedArrayGetLength(this); | 528 var length = %_TypedArrayGetLength(this); |
492 | 529 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 %AddNamedProperty(GlobalNAME.prototype, | 713 %AddNamedProperty(GlobalNAME.prototype, |
677 "constructor", global.NAME, DONT_ENUM); | 714 "constructor", global.NAME, DONT_ENUM); |
678 %AddNamedProperty(GlobalNAME.prototype, | 715 %AddNamedProperty(GlobalNAME.prototype, |
679 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 716 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
680 READ_ONLY | DONT_ENUM | DONT_DELETE); | 717 READ_ONLY | DONT_ENUM | DONT_DELETE); |
681 endmacro | 718 endmacro |
682 | 719 |
683 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 720 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
684 | 721 |
685 }) | 722 }) |
OLD | NEW |