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

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

Issue 1754593003: Implement TypedArray(typedarray) constructor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix comment and test262 Created 4 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/macros.py ('k') | test/test262/test262.status » ('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 var AddIndexedProperty; 14 var AddIndexedProperty;
15 var ArrayToString; 15 var 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 GlobalDataView = global.DataView; 22 var GlobalDataView = global.DataView;
22 var GlobalObject = global.Object; 23 var GlobalObject = global.Object;
23 var InternalArray = utils.InternalArray; 24 var InternalArray = utils.InternalArray;
24 var InnerArrayCopyWithin; 25 var InnerArrayCopyWithin;
25 var InnerArrayEvery; 26 var InnerArrayEvery;
26 var InnerArrayFill; 27 var InnerArrayFill;
27 var InnerArrayFilter; 28 var InnerArrayFilter;
28 var InnerArrayFind; 29 var InnerArrayFind;
29 var InnerArrayFindIndex; 30 var InnerArrayFindIndex;
30 var InnerArrayForEach; 31 var InnerArrayForEach;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 throw MakeTypeError(kIncompatibleMethodReceiver, 116 throw MakeTypeError(kIncompatibleMethodReceiver,
116 "TypedArrayDefaultConstructor", this); 117 "TypedArrayDefaultConstructor", this);
117 } 118 }
118 119
119 function TypedArrayCreate(constructor, arg0, arg1, arg2) { 120 function TypedArrayCreate(constructor, arg0, arg1, arg2) {
120 if (IS_UNDEFINED(arg1)) { 121 if (IS_UNDEFINED(arg1)) {
121 var newTypedArray = new constructor(arg0); 122 var newTypedArray = new constructor(arg0);
122 } else { 123 } else {
123 var newTypedArray = new constructor(arg0, arg1, arg2); 124 var newTypedArray = new constructor(arg0, arg1, arg2);
124 } 125 }
125 if (!%_IsTypedArray(newTypedArray)) throw MakeTypeError(kNotTypedArray); 126 if (!IS_TYPEDARRAY(newTypedArray)) throw MakeTypeError(kNotTypedArray);
126 // TODO(littledan): Check for being detached, here and elsewhere 127 // TODO(littledan): Check for being detached, here and elsewhere
127 // All callers where the first argument is a Number have no additional 128 // All callers where the first argument is a Number have no additional
128 // arguments. 129 // arguments.
129 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { 130 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) {
130 throw MakeTypeError(kTypedArrayTooShort); 131 throw MakeTypeError(kTypedArrayTooShort);
131 } 132 }
132 return newTypedArray; 133 return newTypedArray;
133 } 134 }
134 135
135 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { 136 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 }; 237 };
237 // TODO(littledan): Computed properties don't work yet in nosnap. 238 // TODO(littledan): Computed properties don't work yet in nosnap.
238 // Rephrase when they do. 239 // Rephrase when they do.
239 newIterable[iteratorSymbol] = function() { return iterator; } 240 newIterable[iteratorSymbol] = function() { return iterator; }
240 for (var value of newIterable) { 241 for (var value of newIterable) {
241 list.push(value); 242 list.push(value);
242 } 243 }
243 NAMEConstructByArrayLike(obj, list); 244 NAMEConstructByArrayLike(obj, list);
244 } 245 }
245 246
247 // ES#sec-typedarray-typedarray TypedArray ( typedArray )
248 function NAMEConstructByTypedArray(obj, typedArray) {
249 // TODO(littledan): Throw on detached typedArray
250 var srcData = %TypedArrayGetBuffer(typedArray);
251 var length = %_TypedArrayGetLength(typedArray);
252 var byteLength = %_ArrayBufferViewGetByteLength(typedArray);
253 var newByteLength = length * ELEMENT_SIZE;
254 var bufferConstructor = SpeciesConstructor(srcData, GlobalArrayBuffer);
255 var data = new GlobalArrayBuffer(newByteLength);
256 var prototype = bufferConstructor.prototype;
257 // TODO(littledan): Use the right prototype based on bufferConstructor's realm
258 if (!IS_RECEIVER(prototype)) prototype = GlobalArrayBufferPrototype;
259 %InternalSetPrototype(data, prototype);
adamk 2016/03/01 18:49:46 Looks like this is needed to handle ObjectCreate()
Dan Ehrenberg 2016/03/01 19:34:19 Yes, I'm sad too.
260 %_TypedArrayInitialize(obj, ARRAY_ID, data, 0, newByteLength, true);
261 // Note: The separate CloneArrayBuffer path in the spec ensures
262 // that NaNs are not canonicalized, but because V8 does not
263 // canonicalize NaNs, we do not have to do anything different.
264 // TODO(littledan): Make a fastpath based on memcpy
265 for (var i = 0; i < length; i++) {
266 obj[i] = typedArray[i];
267 }
268 }
269
246 function NAMEConstructor(arg1, arg2, arg3) { 270 function NAMEConstructor(arg1, arg2, arg3) {
247 if (!IS_UNDEFINED(new.target)) { 271 if (!IS_UNDEFINED(new.target)) {
248 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { 272 if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) {
249 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); 273 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
250 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || 274 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
251 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { 275 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
252 NAMEConstructByLength(this, arg1); 276 NAMEConstructByLength(this, arg1);
277 } else if (IS_TYPEDARRAY(arg1)) {
278 NAMEConstructByTypedArray(this, arg1);
253 } else { 279 } else {
254 // TODO(littledan): If arg1 is a TypedArray, follow the constructor 280 // TODO(littledan): If arg1 is a TypedArray, follow the constructor
adamk 2016/03/01 18:49:46 Seems like this CL takes care of this TODO?
Dan Ehrenberg 2016/03/01 19:34:19 Removed it
255 // path in ES2015 22.2.4.3, and call SpeciesConstructor, in a 281 // path in ES2015 22.2.4.3, and call SpeciesConstructor, in a
256 // path that seems to be an optimized version of what's below, but 282 // path that seems to be an optimized version of what's below, but
257 // in an observably different way. 283 // in an observably different way.
258 var iteratorFn = arg1[iteratorSymbol]; 284 var iteratorFn = arg1[iteratorSymbol];
259 if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) { 285 if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) {
260 NAMEConstructByArrayLike(this, arg1); 286 NAMEConstructByArrayLike(this, arg1);
261 } else { 287 } else {
262 NAMEConstructByIterable(this, arg1, iteratorFn); 288 NAMEConstructByIterable(this, arg1, iteratorFn);
263 } 289 }
264 } 290 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 return %_Call(NAMESubArray, this, begin, end); 346 return %_Call(NAMESubArray, this, begin, end);
321 endmacro 347 endmacro
322 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) 348 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE)
323 } 349 }
324 throw MakeTypeError(kIncompatibleMethodReceiver, 350 throw MakeTypeError(kIncompatibleMethodReceiver,
325 "get TypedArray.prototype.subarray", this); 351 "get TypedArray.prototype.subarray", this);
326 } 352 }
327 %SetForceInlineFlag(TypedArraySubArray); 353 %SetForceInlineFlag(TypedArraySubArray);
328 354
329 function TypedArrayGetBuffer() { 355 function TypedArrayGetBuffer() {
330 if (!%_IsTypedArray(this)) { 356 if (!IS_TYPEDARRAY(this)) {
331 throw MakeTypeError(kIncompatibleMethodReceiver, 357 throw MakeTypeError(kIncompatibleMethodReceiver,
332 "get TypedArray.prototype.buffer", this); 358 "get TypedArray.prototype.buffer", this);
333 } 359 }
334 return %TypedArrayGetBuffer(this); 360 return %TypedArrayGetBuffer(this);
335 } 361 }
336 %SetForceInlineFlag(TypedArrayGetBuffer); 362 %SetForceInlineFlag(TypedArrayGetBuffer);
337 363
338 function TypedArrayGetByteLength() { 364 function TypedArrayGetByteLength() {
339 if (!%_IsTypedArray(this)) { 365 if (!IS_TYPEDARRAY(this)) {
340 throw MakeTypeError(kIncompatibleMethodReceiver, 366 throw MakeTypeError(kIncompatibleMethodReceiver,
341 "get TypedArray.prototype.byteLength", this); 367 "get TypedArray.prototype.byteLength", this);
342 } 368 }
343 return %_ArrayBufferViewGetByteLength(this); 369 return %_ArrayBufferViewGetByteLength(this);
344 } 370 }
345 %SetForceInlineFlag(TypedArrayGetByteLength); 371 %SetForceInlineFlag(TypedArrayGetByteLength);
346 372
347 function TypedArrayGetByteOffset() { 373 function TypedArrayGetByteOffset() {
348 if (!%_IsTypedArray(this)) { 374 if (!IS_TYPEDARRAY(this)) {
349 throw MakeTypeError(kIncompatibleMethodReceiver, 375 throw MakeTypeError(kIncompatibleMethodReceiver,
350 "get TypedArray.prototype.byteOffset", this); 376 "get TypedArray.prototype.byteOffset", this);
351 } 377 }
352 return %_ArrayBufferViewGetByteOffset(this); 378 return %_ArrayBufferViewGetByteOffset(this);
353 } 379 }
354 %SetForceInlineFlag(TypedArrayGetByteOffset); 380 %SetForceInlineFlag(TypedArrayGetByteOffset);
355 381
356 function TypedArrayGetLength() { 382 function TypedArrayGetLength() {
357 if (!%_IsTypedArray(this)) { 383 if (!IS_TYPEDARRAY(this)) {
358 throw MakeTypeError(kIncompatibleMethodReceiver, 384 throw MakeTypeError(kIncompatibleMethodReceiver,
359 "get TypedArray.prototype.length", this); 385 "get TypedArray.prototype.length", this);
360 } 386 }
361 return %_TypedArrayGetLength(this); 387 return %_TypedArrayGetLength(this);
362 } 388 }
363 %SetForceInlineFlag(TypedArrayGetLength); 389 %SetForceInlineFlag(TypedArrayGetLength);
364 390
365 391
366 392
367 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { 393 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 if (intOffset + l > this.length) { 488 if (intOffset + l > this.length) {
463 throw MakeRangeError(kTypedArraySetSourceTooLarge); 489 throw MakeRangeError(kTypedArraySetSourceTooLarge);
464 } 490 }
465 TypedArraySetFromArrayLike(this, obj, l, intOffset); 491 TypedArraySetFromArrayLike(this, obj, l, intOffset);
466 return; 492 return;
467 } 493 }
468 } 494 }
469 %FunctionSetLength(TypedArraySet, 1); 495 %FunctionSetLength(TypedArraySet, 1);
470 496
471 function TypedArrayGetToStringTag() { 497 function TypedArrayGetToStringTag() {
472 if (!%_IsTypedArray(this)) return; 498 if (!IS_TYPEDARRAY(this)) return;
473 var name = %_ClassOf(this); 499 var name = %_ClassOf(this);
474 if (IS_UNDEFINED(name)) return; 500 if (IS_UNDEFINED(name)) return;
475 return name; 501 return name;
476 } 502 }
477 503
478 504
479 function TypedArrayCopyWithin(target, start, end) { 505 function TypedArrayCopyWithin(target, start, end) {
480 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 506 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
481 507
482 var length = %_TypedArrayGetLength(this); 508 var length = %_TypedArrayGetLength(this);
483 509
484 // TODO(littledan): Replace with a memcpy for better performance 510 // TODO(littledan): Replace with a memcpy for better performance
485 return InnerArrayCopyWithin(target, start, end, this, length); 511 return InnerArrayCopyWithin(target, start, end, this, length);
486 } 512 }
487 %FunctionSetLength(TypedArrayCopyWithin, 2); 513 %FunctionSetLength(TypedArrayCopyWithin, 2);
488 514
489 515
490 // ES6 draft 05-05-15, section 22.2.3.7 516 // ES6 draft 05-05-15, section 22.2.3.7
491 function TypedArrayEvery(f, receiver) { 517 function TypedArrayEvery(f, receiver) {
492 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 518 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
493 519
494 var length = %_TypedArrayGetLength(this); 520 var length = %_TypedArrayGetLength(this);
495 521
496 return InnerArrayEvery(f, receiver, this, length); 522 return InnerArrayEvery(f, receiver, this, length);
497 } 523 }
498 %FunctionSetLength(TypedArrayEvery, 1); 524 %FunctionSetLength(TypedArrayEvery, 1);
499 525
500 526
501 // ES6 draft 08-24-14, section 22.2.3.12 527 // ES6 draft 08-24-14, section 22.2.3.12
502 function TypedArrayForEach(f, receiver) { 528 function TypedArrayForEach(f, receiver) {
503 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 529 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
504 530
505 var length = %_TypedArrayGetLength(this); 531 var length = %_TypedArrayGetLength(this);
506 532
507 InnerArrayForEach(f, receiver, this, length); 533 InnerArrayForEach(f, receiver, this, length);
508 } 534 }
509 %FunctionSetLength(TypedArrayForEach, 1); 535 %FunctionSetLength(TypedArrayForEach, 1);
510 536
511 537
512 // ES6 draft 04-05-14 section 22.2.3.8 538 // ES6 draft 04-05-14 section 22.2.3.8
513 function TypedArrayFill(value, start, end) { 539 function TypedArrayFill(value, start, end) {
514 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 540 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
515 541
516 var length = %_TypedArrayGetLength(this); 542 var length = %_TypedArrayGetLength(this);
517 543
518 return InnerArrayFill(value, start, end, this, length); 544 return InnerArrayFill(value, start, end, this, length);
519 } 545 }
520 %FunctionSetLength(TypedArrayFill, 1); 546 %FunctionSetLength(TypedArrayFill, 1);
521 547
522 548
523 // ES6 draft 07-15-13, section 22.2.3.9 549 // ES6 draft 07-15-13, section 22.2.3.9
524 function TypedArrayFilter(f, thisArg) { 550 function TypedArrayFilter(f, thisArg) {
525 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 551 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
526 552
527 var length = %_TypedArrayGetLength(this); 553 var length = %_TypedArrayGetLength(this);
528 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 554 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
529 var result = new InternalArray(); 555 var result = new InternalArray();
530 InnerArrayFilter(f, thisArg, this, length, result); 556 InnerArrayFilter(f, thisArg, this, length, result);
531 var captured = result.length; 557 var captured = result.length;
532 var output = TypedArraySpeciesCreate(this, captured); 558 var output = TypedArraySpeciesCreate(this, captured);
533 for (var i = 0; i < captured; i++) { 559 for (var i = 0; i < captured; i++) {
534 output[i] = result[i]; 560 output[i] = result[i];
535 } 561 }
536 return output; 562 return output;
537 } 563 }
538 %FunctionSetLength(TypedArrayFilter, 1); 564 %FunctionSetLength(TypedArrayFilter, 1);
539 565
540 566
541 // ES6 draft 07-15-13, section 22.2.3.10 567 // ES6 draft 07-15-13, section 22.2.3.10
542 function TypedArrayFind(predicate, thisArg) { 568 function TypedArrayFind(predicate, thisArg) {
543 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 569 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
544 570
545 var length = %_TypedArrayGetLength(this); 571 var length = %_TypedArrayGetLength(this);
546 572
547 return InnerArrayFind(predicate, thisArg, this, length); 573 return InnerArrayFind(predicate, thisArg, this, length);
548 } 574 }
549 %FunctionSetLength(TypedArrayFind, 1); 575 %FunctionSetLength(TypedArrayFind, 1);
550 576
551 577
552 // ES6 draft 07-15-13, section 22.2.3.11 578 // ES6 draft 07-15-13, section 22.2.3.11
553 function TypedArrayFindIndex(predicate, thisArg) { 579 function TypedArrayFindIndex(predicate, thisArg) {
554 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 580 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
555 581
556 var length = %_TypedArrayGetLength(this); 582 var length = %_TypedArrayGetLength(this);
557 583
558 return InnerArrayFindIndex(predicate, thisArg, this, length); 584 return InnerArrayFindIndex(predicate, thisArg, this, length);
559 } 585 }
560 %FunctionSetLength(TypedArrayFindIndex, 1); 586 %FunctionSetLength(TypedArrayFindIndex, 1);
561 587
562 588
563 // ES6 draft 05-18-15, section 22.2.3.21 589 // ES6 draft 05-18-15, section 22.2.3.21
564 function TypedArrayReverse() { 590 function TypedArrayReverse() {
565 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 591 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
566 592
567 var length = %_TypedArrayGetLength(this); 593 var length = %_TypedArrayGetLength(this);
568 594
569 return PackedArrayReverse(this, length); 595 return PackedArrayReverse(this, length);
570 } 596 }
571 597
572 598
573 function TypedArrayComparefn(x, y) { 599 function TypedArrayComparefn(x, y) {
574 if (x === 0 && x === y) { 600 if (x === 0 && x === y) {
575 x = 1 / x; 601 x = 1 / x;
576 y = 1 / y; 602 y = 1 / y;
577 } 603 }
578 if (x < y) { 604 if (x < y) {
579 return -1; 605 return -1;
580 } else if (x > y) { 606 } else if (x > y) {
581 return 1; 607 return 1;
582 } else if (IsNaN(x) && IsNaN(y)) { 608 } else if (IsNaN(x) && IsNaN(y)) {
583 return IsNaN(y) ? 0 : 1; 609 return IsNaN(y) ? 0 : 1;
584 } else if (IsNaN(x)) { 610 } else if (IsNaN(x)) {
585 return 1; 611 return 1;
586 } 612 }
587 return 0; 613 return 0;
588 } 614 }
589 615
590 616
591 // ES6 draft 05-18-15, section 22.2.3.25 617 // ES6 draft 05-18-15, section 22.2.3.25
592 function TypedArraySort(comparefn) { 618 function TypedArraySort(comparefn) {
593 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 619 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
594 620
595 var length = %_TypedArrayGetLength(this); 621 var length = %_TypedArrayGetLength(this);
596 622
597 if (IS_UNDEFINED(comparefn)) { 623 if (IS_UNDEFINED(comparefn)) {
598 comparefn = TypedArrayComparefn; 624 comparefn = TypedArrayComparefn;
599 } 625 }
600 626
601 return InnerArraySort(this, length, comparefn); 627 return InnerArraySort(this, length, comparefn);
602 } 628 }
603 629
604 630
605 // ES6 section 22.2.3.13 631 // ES6 section 22.2.3.13
606 function TypedArrayIndexOf(element, index) { 632 function TypedArrayIndexOf(element, index) {
607 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 633 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
608 634
609 var length = %_TypedArrayGetLength(this); 635 var length = %_TypedArrayGetLength(this);
610 return InnerArrayIndexOf(this, element, index, length); 636 return InnerArrayIndexOf(this, element, index, length);
611 } 637 }
612 %FunctionSetLength(TypedArrayIndexOf, 1); 638 %FunctionSetLength(TypedArrayIndexOf, 1);
613 639
614 640
615 // ES6 section 22.2.3.16 641 // ES6 section 22.2.3.16
616 function TypedArrayLastIndexOf(element, index) { 642 function TypedArrayLastIndexOf(element, index) {
617 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 643 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
618 644
619 var length = %_TypedArrayGetLength(this); 645 var length = %_TypedArrayGetLength(this);
620 646
621 return InnerArrayLastIndexOf(this, element, index, length, 647 return InnerArrayLastIndexOf(this, element, index, length,
622 arguments.length); 648 arguments.length);
623 } 649 }
624 %FunctionSetLength(TypedArrayLastIndexOf, 1); 650 %FunctionSetLength(TypedArrayLastIndexOf, 1);
625 651
626 652
627 // ES6 draft 07-15-13, section 22.2.3.18 653 // ES6 draft 07-15-13, section 22.2.3.18
628 function TypedArrayMap(f, thisArg) { 654 function TypedArrayMap(f, thisArg) {
629 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 655 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
630 656
631 var length = %_TypedArrayGetLength(this); 657 var length = %_TypedArrayGetLength(this);
632 var result = TypedArraySpeciesCreate(this, length); 658 var result = TypedArraySpeciesCreate(this, length);
633 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 659 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
634 for (var i = 0; i < length; i++) { 660 for (var i = 0; i < length; i++) {
635 var element = this[i]; 661 var element = this[i];
636 result[i] = %_Call(f, thisArg, element, i, this); 662 result[i] = %_Call(f, thisArg, element, i, this);
637 } 663 }
638 return result; 664 return result;
639 } 665 }
640 %FunctionSetLength(TypedArrayMap, 1); 666 %FunctionSetLength(TypedArrayMap, 1);
641 667
642 668
643 // ES6 draft 05-05-15, section 22.2.3.24 669 // ES6 draft 05-05-15, section 22.2.3.24
644 function TypedArraySome(f, receiver) { 670 function TypedArraySome(f, receiver) {
645 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 671 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
646 672
647 var length = %_TypedArrayGetLength(this); 673 var length = %_TypedArrayGetLength(this);
648 674
649 return InnerArraySome(f, receiver, this, length); 675 return InnerArraySome(f, receiver, this, length);
650 } 676 }
651 %FunctionSetLength(TypedArraySome, 1); 677 %FunctionSetLength(TypedArraySome, 1);
652 678
653 679
654 // ES6 section 22.2.3.27 680 // ES6 section 22.2.3.27
655 function TypedArrayToLocaleString() { 681 function TypedArrayToLocaleString() {
656 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 682 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
657 683
658 var length = %_TypedArrayGetLength(this); 684 var length = %_TypedArrayGetLength(this);
659 685
660 return InnerArrayToLocaleString(this, length); 686 return InnerArrayToLocaleString(this, length);
661 } 687 }
662 688
663 689
664 // ES6 section 22.2.3.28 690 // ES6 section 22.2.3.28
665 function TypedArrayToString() { 691 function TypedArrayToString() {
666 return %_Call(ArrayToString, this); 692 return %_Call(ArrayToString, this);
667 } 693 }
668 694
669 695
670 // ES6 section 22.2.3.14 696 // ES6 section 22.2.3.14
671 function TypedArrayJoin(separator) { 697 function TypedArrayJoin(separator) {
672 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 698 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
673 699
674 var length = %_TypedArrayGetLength(this); 700 var length = %_TypedArrayGetLength(this);
675 701
676 return InnerArrayJoin(separator, this, length); 702 return InnerArrayJoin(separator, this, length);
677 } 703 }
678 704
679 705
680 // ES6 draft 07-15-13, section 22.2.3.19 706 // ES6 draft 07-15-13, section 22.2.3.19
681 function TypedArrayReduce(callback, current) { 707 function TypedArrayReduce(callback, current) {
682 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 708 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
683 709
684 var length = %_TypedArrayGetLength(this); 710 var length = %_TypedArrayGetLength(this);
685 return InnerArrayReduce(callback, current, this, length, 711 return InnerArrayReduce(callback, current, this, length,
686 arguments.length); 712 arguments.length);
687 } 713 }
688 %FunctionSetLength(TypedArrayReduce, 1); 714 %FunctionSetLength(TypedArrayReduce, 1);
689 715
690 716
691 // ES6 draft 07-15-13, section 22.2.3.19 717 // ES6 draft 07-15-13, section 22.2.3.19
692 function TypedArrayReduceRight(callback, current) { 718 function TypedArrayReduceRight(callback, current) {
693 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 719 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
694 720
695 var length = %_TypedArrayGetLength(this); 721 var length = %_TypedArrayGetLength(this);
696 return InnerArrayReduceRight(callback, current, this, length, 722 return InnerArrayReduceRight(callback, current, this, length,
697 arguments.length); 723 arguments.length);
698 } 724 }
699 %FunctionSetLength(TypedArrayReduceRight, 1); 725 %FunctionSetLength(TypedArrayReduceRight, 1);
700 726
701 727
702 function TypedArraySlice(start, end) { 728 function TypedArraySlice(start, end) {
703 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 729 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
704 var len = %_TypedArrayGetLength(this); 730 var len = %_TypedArrayGetLength(this);
705 731
706 var relativeStart = TO_INTEGER(start); 732 var relativeStart = TO_INTEGER(start);
707 733
708 var k; 734 var k;
709 if (relativeStart < 0) { 735 if (relativeStart < 0) {
710 k = MaxSimple(len + relativeStart, 0); 736 k = MaxSimple(len + relativeStart, 0);
711 } else { 737 } else {
712 k = MinSimple(relativeStart, len); 738 k = MinSimple(relativeStart, len);
713 } 739 }
(...skipping 23 matching lines...) Expand all
737 array[n] = kValue; 763 array[n] = kValue;
738 k++; 764 k++;
739 n++; 765 n++;
740 } 766 }
741 return array; 767 return array;
742 } 768 }
743 769
744 770
745 // ES2016 draft, section 22.2.3.14 771 // ES2016 draft, section 22.2.3.14
746 function TypedArrayIncludes(searchElement, fromIndex) { 772 function TypedArrayIncludes(searchElement, fromIndex) {
747 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 773 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
748 774
749 var length = %_TypedArrayGetLength(this); 775 var length = %_TypedArrayGetLength(this);
750 776
751 return InnerArrayIncludes(searchElement, fromIndex, this, length); 777 return InnerArrayIncludes(searchElement, fromIndex, this, length);
752 } 778 }
753 %FunctionSetLength(TypedArrayIncludes, 1); 779 %FunctionSetLength(TypedArrayIncludes, 1);
754 780
755 781
756 // ES6 draft 08-24-14, section 22.2.2.2 782 // ES6 draft 08-24-14, section 22.2.2.2
757 function TypedArrayOf() { 783 function TypedArrayOf() {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 "setUint32", DataViewSetUint32JS, 1009 "setUint32", DataViewSetUint32JS,
984 1010
985 "getFloat32", DataViewGetFloat32JS, 1011 "getFloat32", DataViewGetFloat32JS,
986 "setFloat32", DataViewSetFloat32JS, 1012 "setFloat32", DataViewSetFloat32JS,
987 1013
988 "getFloat64", DataViewGetFloat64JS, 1014 "getFloat64", DataViewGetFloat64JS,
989 "setFloat64", DataViewSetFloat64JS 1015 "setFloat64", DataViewSetFloat64JS
990 ]); 1016 ]);
991 1017
992 }) 1018 })
OLDNEW
« no previous file with comments | « src/js/macros.py ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698