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

Side by Side Diff: src/js/typedarray.js

Issue 2761783002: Always run our fast array builtins. (Closed)
Patch Set: Make sure the strict map is used. Created 3 years, 9 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/js/array.js ('k') | src/runtime/runtime.h » ('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
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;
24 var InnerArrayFilter; 23 var InnerArrayFilter;
25 var InnerArrayFind; 24 var InnerArrayFind;
26 var InnerArrayFindIndex; 25 var InnerArrayFindIndex;
27 var InnerArrayForEach;
28 var InnerArrayJoin; 26 var InnerArrayJoin;
29 var InnerArrayReduce;
30 var InnerArrayReduceRight; 27 var InnerArrayReduceRight;
31 var InnerArraySome;
32 var InnerArraySort; 28 var InnerArraySort;
33 var InnerArrayToLocaleString; 29 var InnerArrayToLocaleString;
34 var InternalArray = utils.InternalArray; 30 var InternalArray = utils.InternalArray;
35 var MaxSimple; 31 var MaxSimple;
36 var MinSimple; 32 var MinSimple;
37 var PackedArrayReverse; 33 var PackedArrayReverse;
38 var SpeciesConstructor; 34 var SpeciesConstructor;
39 var ToPositiveInteger; 35 var ToPositiveInteger;
40 var ToIndex; 36 var ToIndex;
41 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 37 var iteratorSymbol = utils.ImportNow("iterator_symbol");
(...skipping 17 matching lines...) Expand all
59 endmacro 55 endmacro
60 56
61 TYPED_ARRAYS(DECLARE_GLOBALS) 57 TYPED_ARRAYS(DECLARE_GLOBALS)
62 58
63 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); 59 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
64 60
65 utils.Import(function(from) { 61 utils.Import(function(from) {
66 ArrayValues = from.ArrayValues; 62 ArrayValues = from.ArrayValues;
67 GetIterator = from.GetIterator; 63 GetIterator = from.GetIterator;
68 GetMethod = from.GetMethod; 64 GetMethod = from.GetMethod;
69 InnerArrayEvery = from.InnerArrayEvery;
70 InnerArrayFilter = from.InnerArrayFilter; 65 InnerArrayFilter = from.InnerArrayFilter;
71 InnerArrayFind = from.InnerArrayFind; 66 InnerArrayFind = from.InnerArrayFind;
72 InnerArrayFindIndex = from.InnerArrayFindIndex; 67 InnerArrayFindIndex = from.InnerArrayFindIndex;
73 InnerArrayForEach = from.InnerArrayForEach;
74 InnerArrayJoin = from.InnerArrayJoin; 68 InnerArrayJoin = from.InnerArrayJoin;
75 InnerArrayReduce = from.InnerArrayReduce;
76 InnerArrayReduceRight = from.InnerArrayReduceRight; 69 InnerArrayReduceRight = from.InnerArrayReduceRight;
77 InnerArraySome = from.InnerArraySome;
78 InnerArraySort = from.InnerArraySort; 70 InnerArraySort = from.InnerArraySort;
79 InnerArrayToLocaleString = from.InnerArrayToLocaleString; 71 InnerArrayToLocaleString = from.InnerArrayToLocaleString;
80 MaxSimple = from.MaxSimple; 72 MaxSimple = from.MaxSimple;
81 MinSimple = from.MinSimple; 73 MinSimple = from.MinSimple;
82 PackedArrayReverse = from.PackedArrayReverse; 74 PackedArrayReverse = from.PackedArrayReverse;
83 SpeciesConstructor = from.SpeciesConstructor; 75 SpeciesConstructor = from.SpeciesConstructor;
84 ToPositiveInteger = from.ToPositiveInteger; 76 ToPositiveInteger = from.ToPositiveInteger;
85 ToIndex = from.ToIndex; 77 ToIndex = from.ToIndex;
86 }); 78 });
87 79
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 356 }
365 %FunctionSetLength(TypedArraySet, 1); 357 %FunctionSetLength(TypedArraySet, 1);
366 358
367 function TypedArrayGetToStringTag() { 359 function TypedArrayGetToStringTag() {
368 if (!IS_TYPEDARRAY(this)) return; 360 if (!IS_TYPEDARRAY(this)) return;
369 var name = %_ClassOf(this); 361 var name = %_ClassOf(this);
370 if (IS_UNDEFINED(name)) return; 362 if (IS_UNDEFINED(name)) return;
371 return name; 363 return name;
372 } 364 }
373 365
366 function InnerTypedArrayEvery(f, receiver, array, length) {
367 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
368
369 for (var i = 0; i < length; i++) {
370 if (i in array) {
371 var element = array[i];
372 if (!%_Call(f, receiver, element, i, array)) return false;
373 }
374 }
375 return true;
376 }
374 377
375 // ES6 draft 05-05-15, section 22.2.3.7 378 // ES6 draft 05-05-15, section 22.2.3.7
376 function TypedArrayEvery(f, receiver) { 379 function TypedArrayEvery(f, receiver) {
377 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 380 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
378 381
379 var length = %_TypedArrayGetLength(this); 382 var length = %_TypedArrayGetLength(this);
380 383
381 return InnerArrayEvery(f, receiver, this, length); 384 return InnerTypedArrayEvery(f, receiver, this, length);
382 } 385 }
383 %FunctionSetLength(TypedArrayEvery, 1); 386 %FunctionSetLength(TypedArrayEvery, 1);
384 387
388 function InnerTypedArrayForEach(f, receiver, array, length) {
389 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
390
391 if (IS_UNDEFINED(receiver)) {
392 for (var i = 0; i < length; i++) {
393 if (i in array) {
394 var element = array[i];
395 f(element, i, array);
396 }
397 }
398 } else {
399 for (var i = 0; i < length; i++) {
400 if (i in array) {
401 var element = array[i];
402 %_Call(f, receiver, element, i, array);
403 }
404 }
405 }
406 }
385 407
386 // ES6 draft 08-24-14, section 22.2.3.12 408 // ES6 draft 08-24-14, section 22.2.3.12
387 function TypedArrayForEach(f, receiver) { 409 function TypedArrayForEach(f, receiver) {
388 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 410 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
389 411
390 var length = %_TypedArrayGetLength(this); 412 var length = %_TypedArrayGetLength(this);
391 413
392 InnerArrayForEach(f, receiver, this, length); 414 InnerTypedArrayForEach(f, receiver, this, length);
393 } 415 }
394 %FunctionSetLength(TypedArrayForEach, 1); 416 %FunctionSetLength(TypedArrayForEach, 1);
395 417
396 418
397 // ES6 draft 07-15-13, section 22.2.3.9 419 // ES6 draft 07-15-13, section 22.2.3.9
398 function TypedArrayFilter(f, thisArg) { 420 function TypedArrayFilter(f, thisArg) {
399 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 421 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
400 422
401 var length = %_TypedArrayGetLength(this); 423 var length = %_TypedArrayGetLength(this);
402 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 424 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 var result = TypedArraySpeciesCreate(this, length); 487 var result = TypedArraySpeciesCreate(this, length);
466 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 488 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
467 for (var i = 0; i < length; i++) { 489 for (var i = 0; i < length; i++) {
468 var element = this[i]; 490 var element = this[i];
469 result[i] = %_Call(f, thisArg, element, i, this); 491 result[i] = %_Call(f, thisArg, element, i, this);
470 } 492 }
471 return result; 493 return result;
472 } 494 }
473 %FunctionSetLength(TypedArrayMap, 1); 495 %FunctionSetLength(TypedArrayMap, 1);
474 496
497 function InnerTypedArraySome(f, receiver, array, length) {
498 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
499
500 for (var i = 0; i < length; i++) {
501 if (i in array) {
502 var element = array[i];
503 if (%_Call(f, receiver, element, i, array)) return true;
504 }
505 }
506 return false;
507 }
475 508
476 // ES6 draft 05-05-15, section 22.2.3.24 509 // ES6 draft 05-05-15, section 22.2.3.24
477 function TypedArraySome(f, receiver) { 510 function TypedArraySome(f, receiver) {
478 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 511 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
479 512
480 var length = %_TypedArrayGetLength(this); 513 var length = %_TypedArrayGetLength(this);
481 514
482 return InnerArraySome(f, receiver, this, length); 515 return InnerTypedArraySome(f, receiver, this, length);
483 } 516 }
484 %FunctionSetLength(TypedArraySome, 1); 517 %FunctionSetLength(TypedArraySome, 1);
485 518
486 519
487 // ES6 section 22.2.3.27 520 // ES6 section 22.2.3.27
488 function TypedArrayToLocaleString() { 521 function TypedArrayToLocaleString() {
489 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 522 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
490 523
491 var length = %_TypedArrayGetLength(this); 524 var length = %_TypedArrayGetLength(this);
492 525
493 return InnerArrayToLocaleString(this, length); 526 return InnerArrayToLocaleString(this, length);
494 } 527 }
495 528
496 529
497 // ES6 section 22.2.3.14 530 // ES6 section 22.2.3.14
498 function TypedArrayJoin(separator) { 531 function TypedArrayJoin(separator) {
499 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 532 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
500 533
501 var length = %_TypedArrayGetLength(this); 534 var length = %_TypedArrayGetLength(this);
502 535
503 return InnerArrayJoin(separator, this, length); 536 return InnerArrayJoin(separator, this, length);
504 } 537 }
505 538
539 function InnerTypedArrayReduce(
540 callback, current, array, length, argumentsLength) {
541 if (!IS_CALLABLE(callback)) {
542 throw %make_type_error(kCalledNonCallable, callback);
543 }
544
545 var i = 0;
546 find_initial: if (argumentsLength < 2) {
547 for (; i < length; i++) {
548 if (i in array) {
549 current = array[i++];
550 break find_initial;
551 }
552 }
553 throw %make_type_error(kReduceNoInitial);
554 }
555
556 for (; i < length; i++) {
557 if (i in array) {
558 var element = array[i];
559 current = callback(current, element, i, array);
560 }
561 }
562 return current;
563 }
506 564
507 // ES6 draft 07-15-13, section 22.2.3.19 565 // ES6 draft 07-15-13, section 22.2.3.19
508 function TypedArrayReduce(callback, current) { 566 function TypedArrayReduce(callback, current) {
509 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 567 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
510 568
511 var length = %_TypedArrayGetLength(this); 569 var length = %_TypedArrayGetLength(this);
512 return InnerArrayReduce(callback, current, this, length, 570 return InnerTypedArrayReduce(
513 arguments.length); 571 callback, current, this, length, arguments.length);
514 } 572 }
515 %FunctionSetLength(TypedArrayReduce, 1); 573 %FunctionSetLength(TypedArrayReduce, 1);
516 574
517 575
518 // ES6 draft 07-15-13, section 22.2.3.19 576 // ES6 draft 07-15-13, section 22.2.3.19
519 function TypedArrayReduceRight(callback, current) { 577 function TypedArrayReduceRight(callback, current) {
520 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 578 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
521 579
522 var length = %_TypedArrayGetLength(this); 580 var length = %_TypedArrayGetLength(this);
523 return InnerArrayReduceRight(callback, current, this, length, 581 return InnerArrayReduceRight(callback, current, this, length,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 %AddNamedProperty(GlobalNAME.prototype, 734 %AddNamedProperty(GlobalNAME.prototype,
677 "constructor", global.NAME, DONT_ENUM); 735 "constructor", global.NAME, DONT_ENUM);
678 %AddNamedProperty(GlobalNAME.prototype, 736 %AddNamedProperty(GlobalNAME.prototype,
679 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 737 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
680 READ_ONLY | DONT_ENUM | DONT_DELETE); 738 READ_ONLY | DONT_ENUM | DONT_DELETE);
681 endmacro 739 endmacro
682 740
683 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 741 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
684 742
685 }) 743 })
OLDNEW
« no previous file with comments | « src/js/array.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698