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