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 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 Loading... | |
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 Loading... | |
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 19:36:36
Could we skip this in the common case where buffer
Dan Ehrenberg
2016/03/01 19:41:36
Good idea, done.
| |
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 | |
255 // 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 | |
257 // in an observably different way. | |
258 var iteratorFn = arg1[iteratorSymbol]; | 280 var iteratorFn = arg1[iteratorSymbol]; |
259 if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) { | 281 if (IS_UNDEFINED(iteratorFn) || iteratorFn === ArrayValues) { |
260 NAMEConstructByArrayLike(this, arg1); | 282 NAMEConstructByArrayLike(this, arg1); |
261 } else { | 283 } else { |
262 NAMEConstructByIterable(this, arg1, iteratorFn); | 284 NAMEConstructByIterable(this, arg1, iteratorFn); |
263 } | 285 } |
264 } | 286 } |
265 } else { | 287 } else { |
266 throw MakeTypeError(kConstructorNotFunction, "NAME") | 288 throw MakeTypeError(kConstructorNotFunction, "NAME") |
267 } | 289 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 return %_Call(NAMESubArray, this, begin, end); | 342 return %_Call(NAMESubArray, this, begin, end); |
321 endmacro | 343 endmacro |
322 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) | 344 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) |
323 } | 345 } |
324 throw MakeTypeError(kIncompatibleMethodReceiver, | 346 throw MakeTypeError(kIncompatibleMethodReceiver, |
325 "get TypedArray.prototype.subarray", this); | 347 "get TypedArray.prototype.subarray", this); |
326 } | 348 } |
327 %SetForceInlineFlag(TypedArraySubArray); | 349 %SetForceInlineFlag(TypedArraySubArray); |
328 | 350 |
329 function TypedArrayGetBuffer() { | 351 function TypedArrayGetBuffer() { |
330 if (!%_IsTypedArray(this)) { | 352 if (!IS_TYPEDARRAY(this)) { |
331 throw MakeTypeError(kIncompatibleMethodReceiver, | 353 throw MakeTypeError(kIncompatibleMethodReceiver, |
332 "get TypedArray.prototype.buffer", this); | 354 "get TypedArray.prototype.buffer", this); |
333 } | 355 } |
334 return %TypedArrayGetBuffer(this); | 356 return %TypedArrayGetBuffer(this); |
335 } | 357 } |
336 %SetForceInlineFlag(TypedArrayGetBuffer); | 358 %SetForceInlineFlag(TypedArrayGetBuffer); |
337 | 359 |
338 function TypedArrayGetByteLength() { | 360 function TypedArrayGetByteLength() { |
339 if (!%_IsTypedArray(this)) { | 361 if (!IS_TYPEDARRAY(this)) { |
340 throw MakeTypeError(kIncompatibleMethodReceiver, | 362 throw MakeTypeError(kIncompatibleMethodReceiver, |
341 "get TypedArray.prototype.byteLength", this); | 363 "get TypedArray.prototype.byteLength", this); |
342 } | 364 } |
343 return %_ArrayBufferViewGetByteLength(this); | 365 return %_ArrayBufferViewGetByteLength(this); |
344 } | 366 } |
345 %SetForceInlineFlag(TypedArrayGetByteLength); | 367 %SetForceInlineFlag(TypedArrayGetByteLength); |
346 | 368 |
347 function TypedArrayGetByteOffset() { | 369 function TypedArrayGetByteOffset() { |
348 if (!%_IsTypedArray(this)) { | 370 if (!IS_TYPEDARRAY(this)) { |
349 throw MakeTypeError(kIncompatibleMethodReceiver, | 371 throw MakeTypeError(kIncompatibleMethodReceiver, |
350 "get TypedArray.prototype.byteOffset", this); | 372 "get TypedArray.prototype.byteOffset", this); |
351 } | 373 } |
352 return %_ArrayBufferViewGetByteOffset(this); | 374 return %_ArrayBufferViewGetByteOffset(this); |
353 } | 375 } |
354 %SetForceInlineFlag(TypedArrayGetByteOffset); | 376 %SetForceInlineFlag(TypedArrayGetByteOffset); |
355 | 377 |
356 function TypedArrayGetLength() { | 378 function TypedArrayGetLength() { |
357 if (!%_IsTypedArray(this)) { | 379 if (!IS_TYPEDARRAY(this)) { |
358 throw MakeTypeError(kIncompatibleMethodReceiver, | 380 throw MakeTypeError(kIncompatibleMethodReceiver, |
359 "get TypedArray.prototype.length", this); | 381 "get TypedArray.prototype.length", this); |
360 } | 382 } |
361 return %_TypedArrayGetLength(this); | 383 return %_TypedArrayGetLength(this); |
362 } | 384 } |
363 %SetForceInlineFlag(TypedArrayGetLength); | 385 %SetForceInlineFlag(TypedArrayGetLength); |
364 | 386 |
365 | 387 |
366 | 388 |
367 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { | 389 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 if (intOffset + l > this.length) { | 484 if (intOffset + l > this.length) { |
463 throw MakeRangeError(kTypedArraySetSourceTooLarge); | 485 throw MakeRangeError(kTypedArraySetSourceTooLarge); |
464 } | 486 } |
465 TypedArraySetFromArrayLike(this, obj, l, intOffset); | 487 TypedArraySetFromArrayLike(this, obj, l, intOffset); |
466 return; | 488 return; |
467 } | 489 } |
468 } | 490 } |
469 %FunctionSetLength(TypedArraySet, 1); | 491 %FunctionSetLength(TypedArraySet, 1); |
470 | 492 |
471 function TypedArrayGetToStringTag() { | 493 function TypedArrayGetToStringTag() { |
472 if (!%_IsTypedArray(this)) return; | 494 if (!IS_TYPEDARRAY(this)) return; |
473 var name = %_ClassOf(this); | 495 var name = %_ClassOf(this); |
474 if (IS_UNDEFINED(name)) return; | 496 if (IS_UNDEFINED(name)) return; |
475 return name; | 497 return name; |
476 } | 498 } |
477 | 499 |
478 | 500 |
479 function TypedArrayCopyWithin(target, start, end) { | 501 function TypedArrayCopyWithin(target, start, end) { |
480 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 502 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
481 | 503 |
482 var length = %_TypedArrayGetLength(this); | 504 var length = %_TypedArrayGetLength(this); |
483 | 505 |
484 // TODO(littledan): Replace with a memcpy for better performance | 506 // TODO(littledan): Replace with a memcpy for better performance |
485 return InnerArrayCopyWithin(target, start, end, this, length); | 507 return InnerArrayCopyWithin(target, start, end, this, length); |
486 } | 508 } |
487 %FunctionSetLength(TypedArrayCopyWithin, 2); | 509 %FunctionSetLength(TypedArrayCopyWithin, 2); |
488 | 510 |
489 | 511 |
490 // ES6 draft 05-05-15, section 22.2.3.7 | 512 // ES6 draft 05-05-15, section 22.2.3.7 |
491 function TypedArrayEvery(f, receiver) { | 513 function TypedArrayEvery(f, receiver) { |
492 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 514 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
493 | 515 |
494 var length = %_TypedArrayGetLength(this); | 516 var length = %_TypedArrayGetLength(this); |
495 | 517 |
496 return InnerArrayEvery(f, receiver, this, length); | 518 return InnerArrayEvery(f, receiver, this, length); |
497 } | 519 } |
498 %FunctionSetLength(TypedArrayEvery, 1); | 520 %FunctionSetLength(TypedArrayEvery, 1); |
499 | 521 |
500 | 522 |
501 // ES6 draft 08-24-14, section 22.2.3.12 | 523 // ES6 draft 08-24-14, section 22.2.3.12 |
502 function TypedArrayForEach(f, receiver) { | 524 function TypedArrayForEach(f, receiver) { |
503 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 525 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
504 | 526 |
505 var length = %_TypedArrayGetLength(this); | 527 var length = %_TypedArrayGetLength(this); |
506 | 528 |
507 InnerArrayForEach(f, receiver, this, length); | 529 InnerArrayForEach(f, receiver, this, length); |
508 } | 530 } |
509 %FunctionSetLength(TypedArrayForEach, 1); | 531 %FunctionSetLength(TypedArrayForEach, 1); |
510 | 532 |
511 | 533 |
512 // ES6 draft 04-05-14 section 22.2.3.8 | 534 // ES6 draft 04-05-14 section 22.2.3.8 |
513 function TypedArrayFill(value, start, end) { | 535 function TypedArrayFill(value, start, end) { |
514 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 536 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
515 | 537 |
516 var length = %_TypedArrayGetLength(this); | 538 var length = %_TypedArrayGetLength(this); |
517 | 539 |
518 return InnerArrayFill(value, start, end, this, length); | 540 return InnerArrayFill(value, start, end, this, length); |
519 } | 541 } |
520 %FunctionSetLength(TypedArrayFill, 1); | 542 %FunctionSetLength(TypedArrayFill, 1); |
521 | 543 |
522 | 544 |
523 // ES6 draft 07-15-13, section 22.2.3.9 | 545 // ES6 draft 07-15-13, section 22.2.3.9 |
524 function TypedArrayFilter(f, thisArg) { | 546 function TypedArrayFilter(f, thisArg) { |
525 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 547 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
526 | 548 |
527 var length = %_TypedArrayGetLength(this); | 549 var length = %_TypedArrayGetLength(this); |
528 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 550 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
529 var result = new InternalArray(); | 551 var result = new InternalArray(); |
530 InnerArrayFilter(f, thisArg, this, length, result); | 552 InnerArrayFilter(f, thisArg, this, length, result); |
531 var captured = result.length; | 553 var captured = result.length; |
532 var output = TypedArraySpeciesCreate(this, captured); | 554 var output = TypedArraySpeciesCreate(this, captured); |
533 for (var i = 0; i < captured; i++) { | 555 for (var i = 0; i < captured; i++) { |
534 output[i] = result[i]; | 556 output[i] = result[i]; |
535 } | 557 } |
536 return output; | 558 return output; |
537 } | 559 } |
538 %FunctionSetLength(TypedArrayFilter, 1); | 560 %FunctionSetLength(TypedArrayFilter, 1); |
539 | 561 |
540 | 562 |
541 // ES6 draft 07-15-13, section 22.2.3.10 | 563 // ES6 draft 07-15-13, section 22.2.3.10 |
542 function TypedArrayFind(predicate, thisArg) { | 564 function TypedArrayFind(predicate, thisArg) { |
543 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 565 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
544 | 566 |
545 var length = %_TypedArrayGetLength(this); | 567 var length = %_TypedArrayGetLength(this); |
546 | 568 |
547 return InnerArrayFind(predicate, thisArg, this, length); | 569 return InnerArrayFind(predicate, thisArg, this, length); |
548 } | 570 } |
549 %FunctionSetLength(TypedArrayFind, 1); | 571 %FunctionSetLength(TypedArrayFind, 1); |
550 | 572 |
551 | 573 |
552 // ES6 draft 07-15-13, section 22.2.3.11 | 574 // ES6 draft 07-15-13, section 22.2.3.11 |
553 function TypedArrayFindIndex(predicate, thisArg) { | 575 function TypedArrayFindIndex(predicate, thisArg) { |
554 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 576 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
555 | 577 |
556 var length = %_TypedArrayGetLength(this); | 578 var length = %_TypedArrayGetLength(this); |
557 | 579 |
558 return InnerArrayFindIndex(predicate, thisArg, this, length); | 580 return InnerArrayFindIndex(predicate, thisArg, this, length); |
559 } | 581 } |
560 %FunctionSetLength(TypedArrayFindIndex, 1); | 582 %FunctionSetLength(TypedArrayFindIndex, 1); |
561 | 583 |
562 | 584 |
563 // ES6 draft 05-18-15, section 22.2.3.21 | 585 // ES6 draft 05-18-15, section 22.2.3.21 |
564 function TypedArrayReverse() { | 586 function TypedArrayReverse() { |
565 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 587 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
566 | 588 |
567 var length = %_TypedArrayGetLength(this); | 589 var length = %_TypedArrayGetLength(this); |
568 | 590 |
569 return PackedArrayReverse(this, length); | 591 return PackedArrayReverse(this, length); |
570 } | 592 } |
571 | 593 |
572 | 594 |
573 function TypedArrayComparefn(x, y) { | 595 function TypedArrayComparefn(x, y) { |
574 if (x === 0 && x === y) { | 596 if (x === 0 && x === y) { |
575 x = 1 / x; | 597 x = 1 / x; |
576 y = 1 / y; | 598 y = 1 / y; |
577 } | 599 } |
578 if (x < y) { | 600 if (x < y) { |
579 return -1; | 601 return -1; |
580 } else if (x > y) { | 602 } else if (x > y) { |
581 return 1; | 603 return 1; |
582 } else if (IsNaN(x) && IsNaN(y)) { | 604 } else if (IsNaN(x) && IsNaN(y)) { |
583 return IsNaN(y) ? 0 : 1; | 605 return IsNaN(y) ? 0 : 1; |
584 } else if (IsNaN(x)) { | 606 } else if (IsNaN(x)) { |
585 return 1; | 607 return 1; |
586 } | 608 } |
587 return 0; | 609 return 0; |
588 } | 610 } |
589 | 611 |
590 | 612 |
591 // ES6 draft 05-18-15, section 22.2.3.25 | 613 // ES6 draft 05-18-15, section 22.2.3.25 |
592 function TypedArraySort(comparefn) { | 614 function TypedArraySort(comparefn) { |
593 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 615 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
594 | 616 |
595 var length = %_TypedArrayGetLength(this); | 617 var length = %_TypedArrayGetLength(this); |
596 | 618 |
597 if (IS_UNDEFINED(comparefn)) { | 619 if (IS_UNDEFINED(comparefn)) { |
598 comparefn = TypedArrayComparefn; | 620 comparefn = TypedArrayComparefn; |
599 } | 621 } |
600 | 622 |
601 return InnerArraySort(this, length, comparefn); | 623 return InnerArraySort(this, length, comparefn); |
602 } | 624 } |
603 | 625 |
604 | 626 |
605 // ES6 section 22.2.3.13 | 627 // ES6 section 22.2.3.13 |
606 function TypedArrayIndexOf(element, index) { | 628 function TypedArrayIndexOf(element, index) { |
607 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 629 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
608 | 630 |
609 var length = %_TypedArrayGetLength(this); | 631 var length = %_TypedArrayGetLength(this); |
610 return InnerArrayIndexOf(this, element, index, length); | 632 return InnerArrayIndexOf(this, element, index, length); |
611 } | 633 } |
612 %FunctionSetLength(TypedArrayIndexOf, 1); | 634 %FunctionSetLength(TypedArrayIndexOf, 1); |
613 | 635 |
614 | 636 |
615 // ES6 section 22.2.3.16 | 637 // ES6 section 22.2.3.16 |
616 function TypedArrayLastIndexOf(element, index) { | 638 function TypedArrayLastIndexOf(element, index) { |
617 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 639 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
618 | 640 |
619 var length = %_TypedArrayGetLength(this); | 641 var length = %_TypedArrayGetLength(this); |
620 | 642 |
621 return InnerArrayLastIndexOf(this, element, index, length, | 643 return InnerArrayLastIndexOf(this, element, index, length, |
622 arguments.length); | 644 arguments.length); |
623 } | 645 } |
624 %FunctionSetLength(TypedArrayLastIndexOf, 1); | 646 %FunctionSetLength(TypedArrayLastIndexOf, 1); |
625 | 647 |
626 | 648 |
627 // ES6 draft 07-15-13, section 22.2.3.18 | 649 // ES6 draft 07-15-13, section 22.2.3.18 |
628 function TypedArrayMap(f, thisArg) { | 650 function TypedArrayMap(f, thisArg) { |
629 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 651 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
630 | 652 |
631 var length = %_TypedArrayGetLength(this); | 653 var length = %_TypedArrayGetLength(this); |
632 var result = TypedArraySpeciesCreate(this, length); | 654 var result = TypedArraySpeciesCreate(this, length); |
633 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 655 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
634 for (var i = 0; i < length; i++) { | 656 for (var i = 0; i < length; i++) { |
635 var element = this[i]; | 657 var element = this[i]; |
636 result[i] = %_Call(f, thisArg, element, i, this); | 658 result[i] = %_Call(f, thisArg, element, i, this); |
637 } | 659 } |
638 return result; | 660 return result; |
639 } | 661 } |
640 %FunctionSetLength(TypedArrayMap, 1); | 662 %FunctionSetLength(TypedArrayMap, 1); |
641 | 663 |
642 | 664 |
643 // ES6 draft 05-05-15, section 22.2.3.24 | 665 // ES6 draft 05-05-15, section 22.2.3.24 |
644 function TypedArraySome(f, receiver) { | 666 function TypedArraySome(f, receiver) { |
645 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 667 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
646 | 668 |
647 var length = %_TypedArrayGetLength(this); | 669 var length = %_TypedArrayGetLength(this); |
648 | 670 |
649 return InnerArraySome(f, receiver, this, length); | 671 return InnerArraySome(f, receiver, this, length); |
650 } | 672 } |
651 %FunctionSetLength(TypedArraySome, 1); | 673 %FunctionSetLength(TypedArraySome, 1); |
652 | 674 |
653 | 675 |
654 // ES6 section 22.2.3.27 | 676 // ES6 section 22.2.3.27 |
655 function TypedArrayToLocaleString() { | 677 function TypedArrayToLocaleString() { |
656 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 678 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
657 | 679 |
658 var length = %_TypedArrayGetLength(this); | 680 var length = %_TypedArrayGetLength(this); |
659 | 681 |
660 return InnerArrayToLocaleString(this, length); | 682 return InnerArrayToLocaleString(this, length); |
661 } | 683 } |
662 | 684 |
663 | 685 |
664 // ES6 section 22.2.3.28 | 686 // ES6 section 22.2.3.28 |
665 function TypedArrayToString() { | 687 function TypedArrayToString() { |
666 return %_Call(ArrayToString, this); | 688 return %_Call(ArrayToString, this); |
667 } | 689 } |
668 | 690 |
669 | 691 |
670 // ES6 section 22.2.3.14 | 692 // ES6 section 22.2.3.14 |
671 function TypedArrayJoin(separator) { | 693 function TypedArrayJoin(separator) { |
672 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 694 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
673 | 695 |
674 var length = %_TypedArrayGetLength(this); | 696 var length = %_TypedArrayGetLength(this); |
675 | 697 |
676 return InnerArrayJoin(separator, this, length); | 698 return InnerArrayJoin(separator, this, length); |
677 } | 699 } |
678 | 700 |
679 | 701 |
680 // ES6 draft 07-15-13, section 22.2.3.19 | 702 // ES6 draft 07-15-13, section 22.2.3.19 |
681 function TypedArrayReduce(callback, current) { | 703 function TypedArrayReduce(callback, current) { |
682 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 704 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
683 | 705 |
684 var length = %_TypedArrayGetLength(this); | 706 var length = %_TypedArrayGetLength(this); |
685 return InnerArrayReduce(callback, current, this, length, | 707 return InnerArrayReduce(callback, current, this, length, |
686 arguments.length); | 708 arguments.length); |
687 } | 709 } |
688 %FunctionSetLength(TypedArrayReduce, 1); | 710 %FunctionSetLength(TypedArrayReduce, 1); |
689 | 711 |
690 | 712 |
691 // ES6 draft 07-15-13, section 22.2.3.19 | 713 // ES6 draft 07-15-13, section 22.2.3.19 |
692 function TypedArrayReduceRight(callback, current) { | 714 function TypedArrayReduceRight(callback, current) { |
693 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 715 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
694 | 716 |
695 var length = %_TypedArrayGetLength(this); | 717 var length = %_TypedArrayGetLength(this); |
696 return InnerArrayReduceRight(callback, current, this, length, | 718 return InnerArrayReduceRight(callback, current, this, length, |
697 arguments.length); | 719 arguments.length); |
698 } | 720 } |
699 %FunctionSetLength(TypedArrayReduceRight, 1); | 721 %FunctionSetLength(TypedArrayReduceRight, 1); |
700 | 722 |
701 | 723 |
702 function TypedArraySlice(start, end) { | 724 function TypedArraySlice(start, end) { |
703 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 725 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
704 var len = %_TypedArrayGetLength(this); | 726 var len = %_TypedArrayGetLength(this); |
705 | 727 |
706 var relativeStart = TO_INTEGER(start); | 728 var relativeStart = TO_INTEGER(start); |
707 | 729 |
708 var k; | 730 var k; |
709 if (relativeStart < 0) { | 731 if (relativeStart < 0) { |
710 k = MaxSimple(len + relativeStart, 0); | 732 k = MaxSimple(len + relativeStart, 0); |
711 } else { | 733 } else { |
712 k = MinSimple(relativeStart, len); | 734 k = MinSimple(relativeStart, len); |
713 } | 735 } |
(...skipping 23 matching lines...) Expand all Loading... | |
737 array[n] = kValue; | 759 array[n] = kValue; |
738 k++; | 760 k++; |
739 n++; | 761 n++; |
740 } | 762 } |
741 return array; | 763 return array; |
742 } | 764 } |
743 | 765 |
744 | 766 |
745 // ES2016 draft, section 22.2.3.14 | 767 // ES2016 draft, section 22.2.3.14 |
746 function TypedArrayIncludes(searchElement, fromIndex) { | 768 function TypedArrayIncludes(searchElement, fromIndex) { |
747 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 769 if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); |
748 | 770 |
749 var length = %_TypedArrayGetLength(this); | 771 var length = %_TypedArrayGetLength(this); |
750 | 772 |
751 return InnerArrayIncludes(searchElement, fromIndex, this, length); | 773 return InnerArrayIncludes(searchElement, fromIndex, this, length); |
752 } | 774 } |
753 %FunctionSetLength(TypedArrayIncludes, 1); | 775 %FunctionSetLength(TypedArrayIncludes, 1); |
754 | 776 |
755 | 777 |
756 // ES6 draft 08-24-14, section 22.2.2.2 | 778 // ES6 draft 08-24-14, section 22.2.2.2 |
757 function TypedArrayOf() { | 779 function TypedArrayOf() { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 "setUint32", DataViewSetUint32JS, | 1005 "setUint32", DataViewSetUint32JS, |
984 | 1006 |
985 "getFloat32", DataViewGetFloat32JS, | 1007 "getFloat32", DataViewGetFloat32JS, |
986 "setFloat32", DataViewSetFloat32JS, | 1008 "setFloat32", DataViewSetFloat32JS, |
987 | 1009 |
988 "getFloat64", DataViewGetFloat64JS, | 1010 "getFloat64", DataViewGetFloat64JS, |
989 "setFloat64", DataViewSetFloat64JS | 1011 "setFloat64", DataViewSetFloat64JS |
990 ]); | 1012 ]); |
991 | 1013 |
992 }) | 1014 }) |
OLD | NEW |