Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 // array.js has to come before typedarray.js for this to work | 14 // array.js has to come before typedarray.js for this to work |
| 15 var ArrayToString = utils.ImportNow("ArrayToString"); | 15 var ArrayToString = utils.ImportNow("ArrayToString"); |
| 16 var ArrayValues; | |
| 17 var GetIterator; | 16 var GetIterator; |
| 18 var GetMethod; | 17 var GetMethod; |
| 19 var GlobalArray = global.Array; | 18 var GlobalArray = global.Array; |
| 20 var GlobalArrayBuffer = global.ArrayBuffer; | 19 var GlobalArrayBuffer = global.ArrayBuffer; |
| 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; | 20 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; |
| 22 var GlobalObject = global.Object; | 21 var GlobalObject = global.Object; |
| 23 var InnerArrayFilter; | 22 var InnerArrayFilter; |
| 24 var InnerArrayFind; | 23 var InnerArrayFind; |
| 25 var InnerArrayFindIndex; | 24 var InnerArrayFindIndex; |
| 26 var InnerArrayJoin; | 25 var InnerArrayJoin; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 50 | 49 |
| 51 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) | 50 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) |
| 52 var GlobalNAME = global.NAME; | 51 var GlobalNAME = global.NAME; |
| 53 endmacro | 52 endmacro |
| 54 | 53 |
| 55 TYPED_ARRAYS(DECLARE_GLOBALS) | 54 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 56 | 55 |
| 57 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); | 56 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); |
| 58 | 57 |
| 59 utils.Import(function(from) { | 58 utils.Import(function(from) { |
| 60 ArrayValues = from.ArrayValues; | |
| 61 GetIterator = from.GetIterator; | 59 GetIterator = from.GetIterator; |
| 62 GetMethod = from.GetMethod; | 60 GetMethod = from.GetMethod; |
| 63 InnerArrayFilter = from.InnerArrayFilter; | 61 InnerArrayFilter = from.InnerArrayFilter; |
| 64 InnerArrayFind = from.InnerArrayFind; | 62 InnerArrayFind = from.InnerArrayFind; |
| 65 InnerArrayFindIndex = from.InnerArrayFindIndex; | 63 InnerArrayFindIndex = from.InnerArrayFindIndex; |
| 66 InnerArrayJoin = from.InnerArrayJoin; | 64 InnerArrayJoin = from.InnerArrayJoin; |
| 67 InnerArraySort = from.InnerArraySort; | 65 InnerArraySort = from.InnerArraySort; |
| 68 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 66 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
| 69 MaxSimple = from.MaxSimple; | 67 MaxSimple = from.MaxSimple; |
| 70 MinSimple = from.MinSimple; | 68 MinSimple = from.MinSimple; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 88 throw %make_type_error(kIncompatibleMethodReceiver, | 86 throw %make_type_error(kIncompatibleMethodReceiver, |
| 89 "TypedArrayDefaultConstructor", this); | 87 "TypedArrayDefaultConstructor", this); |
| 90 } | 88 } |
| 91 | 89 |
| 92 function TypedArrayCreate(constructor, arg0, arg1, arg2) { | 90 function TypedArrayCreate(constructor, arg0, arg1, arg2) { |
| 93 if (IS_UNDEFINED(arg1)) { | 91 if (IS_UNDEFINED(arg1)) { |
| 94 var newTypedArray = new constructor(arg0); | 92 var newTypedArray = new constructor(arg0); |
| 95 } else { | 93 } else { |
| 96 var newTypedArray = new constructor(arg0, arg1, arg2); | 94 var newTypedArray = new constructor(arg0, arg1, arg2); |
| 97 } | 95 } |
| 98 if (!IS_TYPEDARRAY(newTypedArray)) throw %make_type_error(kNotTypedArray); | 96 %ValidateTypedArray(newTypedArray, "TypedArrayCreate"); |
|
adamk
2017/03/27 19:48:20
I'm worried that adding a runtime call here might
Choongwoo Han
2017/03/28 09:50:58
Actually this function is not related with default
| |
| 99 // TODO(littledan): Check for being detached, here and elsewhere | |
| 100 // All callers where the first argument is a Number have no additional | |
| 101 // arguments. | |
| 102 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { | 97 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { |
| 103 throw %make_type_error(kTypedArrayTooShort); | 98 throw %make_type_error(kTypedArrayTooShort); |
| 104 } | 99 } |
| 105 return newTypedArray; | 100 return newTypedArray; |
| 106 } | 101 } |
| 107 | 102 |
| 108 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { | 103 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) { |
| 109 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); | 104 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); |
| 110 var constructor = SpeciesConstructor(exemplar, defaultConstructor, | 105 var constructor = SpeciesConstructor(exemplar, defaultConstructor); |
| 111 conservative); | |
| 112 return TypedArrayCreate(constructor, arg0, arg1, arg2); | 106 return TypedArrayCreate(constructor, arg0, arg1, arg2); |
| 113 } | 107 } |
| 114 | 108 |
| 115 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 109 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 116 function NAMEConstructByIterable(obj, iterable, iteratorFn) { | 110 function NAMEConstructByIterable(obj, iterable, iteratorFn) { |
| 117 var list = new InternalArray(); | 111 var list = new InternalArray(); |
| 118 // Reading the Symbol.iterator property of iterable twice would be | 112 // Reading the Symbol.iterator property of iterable twice would be |
| 119 // observable with getters, so instead, we call the function which | 113 // observable with getters, so instead, we call the function which |
| 120 // was already looked up, and wrap it in another iterable. The | 114 // was already looked up, and wrap it in another iterable. The |
| 121 // __proto__ of the new iterable is set to null to avoid any chance | 115 // __proto__ of the new iterable is set to null to avoid any chance |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 endInt = MinSimple(endInt, srcLength); | 188 endInt = MinSimple(endInt, srcLength); |
| 195 } | 189 } |
| 196 | 190 |
| 197 if (endInt < beginInt) { | 191 if (endInt < beginInt) { |
| 198 endInt = beginInt; | 192 endInt = beginInt; |
| 199 } | 193 } |
| 200 | 194 |
| 201 var newLength = endInt - beginInt; | 195 var newLength = endInt - beginInt; |
| 202 var beginByteOffset = | 196 var beginByteOffset = |
| 203 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 197 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 204 // BUG(v8:4665): For web compatibility, subarray needs to always build an | 198 return TypedArraySpeciesCreate(this, %TypedArrayGetBuffer(this), |
| 205 // instance of the default constructor. | 199 beginByteOffset, newLength); |
| 206 // TODO(littledan): Switch to the standard or standardize the fix | |
| 207 return new GlobalNAME(%TypedArrayGetBuffer(this), beginByteOffset, newLength); | |
| 208 } | 200 } |
| 209 endmacro | 201 endmacro |
| 210 | 202 |
| 211 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 203 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 212 | 204 |
| 213 function TypedArraySubArray(begin, end) { | 205 function TypedArraySubArray(begin, end) { |
| 214 switch (%_ClassOf(this)) { | 206 switch (%_ClassOf(this)) { |
| 215 macro TYPED_ARRAY_SUBARRAY_CASE(ARRAY_ID, NAME, ELEMENT_SIZE) | 207 macro TYPED_ARRAY_SUBARRAY_CASE(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 216 case "NAME": | 208 case "NAME": |
| 217 return %_Call(NAMESubArray, this, begin, end); | 209 return %_Call(NAMESubArray, this, begin, end); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 if (i in array) { | 336 if (i in array) { |
| 345 var element = array[i]; | 337 var element = array[i]; |
| 346 if (!%_Call(f, receiver, element, i, array)) return false; | 338 if (!%_Call(f, receiver, element, i, array)) return false; |
| 347 } | 339 } |
| 348 } | 340 } |
| 349 return true; | 341 return true; |
| 350 } | 342 } |
| 351 | 343 |
| 352 // ES6 draft 05-05-15, section 22.2.3.7 | 344 // ES6 draft 05-05-15, section 22.2.3.7 |
| 353 function TypedArrayEvery(f, receiver) { | 345 function TypedArrayEvery(f, receiver) { |
| 354 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 346 %ValidateTypedArray(this, "TypedArray.prototype.every"); |
|
adamk
2017/03/27 19:48:20
Hmm, again this is likely to be much more expensiv
Choongwoo Han
2017/03/28 09:50:58
Yes, it was too expensive than my expectation (2x
| |
| 355 | 347 |
| 356 var length = %_TypedArrayGetLength(this); | 348 var length = %_TypedArrayGetLength(this); |
| 357 | 349 |
| 358 return InnerTypedArrayEvery(f, receiver, this, length); | 350 return InnerTypedArrayEvery(f, receiver, this, length); |
| 359 } | 351 } |
| 360 %FunctionSetLength(TypedArrayEvery, 1); | 352 %FunctionSetLength(TypedArrayEvery, 1); |
| 361 | 353 |
| 362 function InnerTypedArrayForEach(f, receiver, array, length) { | 354 function InnerTypedArrayForEach(f, receiver, array, length) { |
| 363 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 355 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 364 | 356 |
| 365 if (IS_UNDEFINED(receiver)) { | 357 if (IS_UNDEFINED(receiver)) { |
| 366 for (var i = 0; i < length; i++) { | 358 for (var i = 0; i < length; i++) { |
| 367 if (i in array) { | 359 if (i in array) { |
| 368 var element = array[i]; | 360 var element = array[i]; |
| 369 f(element, i, array); | 361 f(element, i, array); |
| 370 } | 362 } |
| 371 } | 363 } |
| 372 } else { | 364 } else { |
| 373 for (var i = 0; i < length; i++) { | 365 for (var i = 0; i < length; i++) { |
| 374 if (i in array) { | 366 if (i in array) { |
| 375 var element = array[i]; | 367 var element = array[i]; |
| 376 %_Call(f, receiver, element, i, array); | 368 %_Call(f, receiver, element, i, array); |
| 377 } | 369 } |
| 378 } | 370 } |
| 379 } | 371 } |
| 380 } | 372 } |
| 381 | 373 |
| 382 // ES6 draft 08-24-14, section 22.2.3.12 | 374 // ES6 draft 08-24-14, section 22.2.3.12 |
| 383 function TypedArrayForEach(f, receiver) { | 375 function TypedArrayForEach(f, receiver) { |
| 384 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 376 %ValidateTypedArray(this, "TypedArray.prototype.forEach"); |
| 385 | 377 |
| 386 var length = %_TypedArrayGetLength(this); | 378 var length = %_TypedArrayGetLength(this); |
| 387 | 379 |
| 388 InnerTypedArrayForEach(f, receiver, this, length); | 380 InnerTypedArrayForEach(f, receiver, this, length); |
| 389 } | 381 } |
| 390 %FunctionSetLength(TypedArrayForEach, 1); | 382 %FunctionSetLength(TypedArrayForEach, 1); |
| 391 | 383 |
| 392 | 384 |
| 393 // ES6 draft 07-15-13, section 22.2.3.9 | 385 // ES6 draft 07-15-13, section 22.2.3.9 |
| 394 function TypedArrayFilter(f, thisArg) { | 386 function TypedArrayFilter(f, thisArg) { |
| 395 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 387 %ValidateTypedArray(this, "TypeArray.prototype.filter"); |
| 396 | 388 |
| 397 var length = %_TypedArrayGetLength(this); | 389 var length = %_TypedArrayGetLength(this); |
| 398 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 390 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 399 var result = new InternalArray(); | 391 var result = new InternalArray(); |
| 400 InnerArrayFilter(f, thisArg, this, length, result); | 392 InnerArrayFilter(f, thisArg, this, length, result); |
| 401 var captured = result.length; | 393 var captured = result.length; |
| 402 var output = TypedArraySpeciesCreate(this, captured); | 394 var output = TypedArraySpeciesCreate(this, captured); |
| 403 for (var i = 0; i < captured; i++) { | 395 for (var i = 0; i < captured; i++) { |
| 404 output[i] = result[i]; | 396 output[i] = result[i]; |
| 405 } | 397 } |
| 406 return output; | 398 return output; |
| 407 } | 399 } |
| 408 %FunctionSetLength(TypedArrayFilter, 1); | 400 %FunctionSetLength(TypedArrayFilter, 1); |
| 409 | 401 |
| 410 | 402 |
| 411 // ES6 draft 07-15-13, section 22.2.3.10 | 403 // ES6 draft 07-15-13, section 22.2.3.10 |
| 412 function TypedArrayFind(predicate, thisArg) { | 404 function TypedArrayFind(predicate, thisArg) { |
| 413 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 405 %ValidateTypedArray(this, "TypedArray.prototype.find"); |
| 414 | 406 |
| 415 var length = %_TypedArrayGetLength(this); | 407 var length = %_TypedArrayGetLength(this); |
| 416 | 408 |
| 417 return InnerArrayFind(predicate, thisArg, this, length); | 409 return InnerArrayFind(predicate, thisArg, this, length); |
| 418 } | 410 } |
| 419 %FunctionSetLength(TypedArrayFind, 1); | 411 %FunctionSetLength(TypedArrayFind, 1); |
| 420 | 412 |
| 421 | 413 |
| 422 // ES6 draft 07-15-13, section 22.2.3.11 | 414 // ES6 draft 07-15-13, section 22.2.3.11 |
| 423 function TypedArrayFindIndex(predicate, thisArg) { | 415 function TypedArrayFindIndex(predicate, thisArg) { |
| 424 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 416 %ValidateTypedArray(this, "TypedArray.prototype.findIndex"); |
| 425 | 417 |
| 426 var length = %_TypedArrayGetLength(this); | 418 var length = %_TypedArrayGetLength(this); |
| 427 | 419 |
| 428 return InnerArrayFindIndex(predicate, thisArg, this, length); | 420 return InnerArrayFindIndex(predicate, thisArg, this, length); |
| 429 } | 421 } |
| 430 %FunctionSetLength(TypedArrayFindIndex, 1); | 422 %FunctionSetLength(TypedArrayFindIndex, 1); |
| 431 | 423 |
| 432 | 424 |
| 433 // ES6 draft 05-18-15, section 22.2.3.25 | 425 // ES6 draft 05-18-15, section 22.2.3.25 |
| 434 function TypedArraySort(comparefn) { | 426 function TypedArraySort(comparefn) { |
| 435 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 427 %ValidateTypedArray(this, "TypedArray.prototype.sort"); |
| 436 | 428 |
| 437 var length = %_TypedArrayGetLength(this); | 429 var length = %_TypedArrayGetLength(this); |
| 438 | 430 |
| 439 if (IS_UNDEFINED(comparefn)) { | 431 if (IS_UNDEFINED(comparefn)) { |
| 440 return %TypedArraySortFast(this); | 432 return %TypedArraySortFast(this); |
| 441 } | 433 } |
| 442 | 434 |
| 443 return InnerArraySort(this, length, comparefn); | 435 return InnerArraySort(this, length, comparefn); |
| 444 } | 436 } |
| 445 | 437 |
| 446 | 438 |
| 447 // ES6 draft 07-15-13, section 22.2.3.18 | 439 // ES6 draft 07-15-13, section 22.2.3.18 |
| 448 function TypedArrayMap(f, thisArg) { | 440 function TypedArrayMap(f, thisArg) { |
| 449 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 441 %ValidateTypedArray(this, "TypedArray.prototype.map"); |
| 450 | 442 |
| 451 var length = %_TypedArrayGetLength(this); | 443 var length = %_TypedArrayGetLength(this); |
| 452 var result = TypedArraySpeciesCreate(this, length); | 444 var result = TypedArraySpeciesCreate(this, length); |
| 453 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 445 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 454 for (var i = 0; i < length; i++) { | 446 for (var i = 0; i < length; i++) { |
| 455 var element = this[i]; | 447 var element = this[i]; |
| 456 result[i] = %_Call(f, thisArg, element, i, this); | 448 result[i] = %_Call(f, thisArg, element, i, this); |
| 457 } | 449 } |
| 458 return result; | 450 return result; |
| 459 } | 451 } |
| 460 %FunctionSetLength(TypedArrayMap, 1); | 452 %FunctionSetLength(TypedArrayMap, 1); |
| 461 | 453 |
| 462 function InnerTypedArraySome(f, receiver, array, length) { | 454 function InnerTypedArraySome(f, receiver, array, length) { |
| 463 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 455 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 464 | 456 |
| 465 for (var i = 0; i < length; i++) { | 457 for (var i = 0; i < length; i++) { |
| 466 if (i in array) { | 458 if (i in array) { |
| 467 var element = array[i]; | 459 var element = array[i]; |
| 468 if (%_Call(f, receiver, element, i, array)) return true; | 460 if (%_Call(f, receiver, element, i, array)) return true; |
| 469 } | 461 } |
| 470 } | 462 } |
| 471 return false; | 463 return false; |
| 472 } | 464 } |
| 473 | 465 |
| 474 // ES6 draft 05-05-15, section 22.2.3.24 | 466 // ES6 draft 05-05-15, section 22.2.3.24 |
| 475 function TypedArraySome(f, receiver) { | 467 function TypedArraySome(f, receiver) { |
| 476 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 468 %ValidateTypedArray(this, "TypedArray.prototype.some"); |
| 477 | 469 |
| 478 var length = %_TypedArrayGetLength(this); | 470 var length = %_TypedArrayGetLength(this); |
| 479 | 471 |
| 480 return InnerTypedArraySome(f, receiver, this, length); | 472 return InnerTypedArraySome(f, receiver, this, length); |
| 481 } | 473 } |
| 482 %FunctionSetLength(TypedArraySome, 1); | 474 %FunctionSetLength(TypedArraySome, 1); |
| 483 | 475 |
| 484 | 476 |
| 485 // ES6 section 22.2.3.27 | 477 // ES6 section 22.2.3.27 |
| 486 function TypedArrayToLocaleString() { | 478 function TypedArrayToLocaleString() { |
| 487 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 479 %ValidateTypedArray(this, "TypedArray.prototype.toLocaleString"); |
| 488 | 480 |
| 489 var length = %_TypedArrayGetLength(this); | 481 var length = %_TypedArrayGetLength(this); |
| 490 | 482 |
| 491 return InnerArrayToLocaleString(this, length); | 483 return InnerArrayToLocaleString(this, length); |
| 492 } | 484 } |
| 493 | 485 |
| 494 | 486 |
| 495 // ES6 section 22.2.3.14 | 487 // ES6 section 22.2.3.14 |
| 496 function TypedArrayJoin(separator) { | 488 function TypedArrayJoin(separator) { |
| 497 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 489 %ValidateTypedArray(this, "TypedArray.prototype.join"); |
| 498 | 490 |
| 499 var length = %_TypedArrayGetLength(this); | 491 var length = %_TypedArrayGetLength(this); |
| 500 | 492 |
| 501 return InnerArrayJoin(separator, this, length); | 493 return InnerArrayJoin(separator, this, length); |
| 502 } | 494 } |
| 503 | 495 |
| 504 function InnerTypedArrayReduce( | 496 function InnerTypedArrayReduce( |
| 505 callback, current, array, length, argumentsLength) { | 497 callback, current, array, length, argumentsLength) { |
| 506 if (!IS_CALLABLE(callback)) { | 498 if (!IS_CALLABLE(callback)) { |
| 507 throw %make_type_error(kCalledNonCallable, callback); | 499 throw %make_type_error(kCalledNonCallable, callback); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 522 if (i in array) { | 514 if (i in array) { |
| 523 var element = array[i]; | 515 var element = array[i]; |
| 524 current = callback(current, element, i, array); | 516 current = callback(current, element, i, array); |
| 525 } | 517 } |
| 526 } | 518 } |
| 527 return current; | 519 return current; |
| 528 } | 520 } |
| 529 | 521 |
| 530 // ES6 draft 07-15-13, section 22.2.3.19 | 522 // ES6 draft 07-15-13, section 22.2.3.19 |
| 531 function TypedArrayReduce(callback, current) { | 523 function TypedArrayReduce(callback, current) { |
| 532 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 524 %ValidateTypedArray(this, "TypedArray.prototype.reduce"); |
| 533 | 525 |
| 534 var length = %_TypedArrayGetLength(this); | 526 var length = %_TypedArrayGetLength(this); |
| 535 return InnerTypedArrayReduce( | 527 return InnerTypedArrayReduce( |
| 536 callback, current, this, length, arguments.length); | 528 callback, current, this, length, arguments.length); |
| 537 } | 529 } |
| 538 %FunctionSetLength(TypedArrayReduce, 1); | 530 %FunctionSetLength(TypedArrayReduce, 1); |
| 539 | 531 |
| 540 function InnerArrayReduceRight(callback, current, array, length, | 532 function InnerArrayReduceRight(callback, current, array, length, |
| 541 argumentsLength) { | 533 argumentsLength) { |
| 542 if (!IS_CALLABLE(callback)) { | 534 if (!IS_CALLABLE(callback)) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 558 if (i in array) { | 550 if (i in array) { |
| 559 var element = array[i]; | 551 var element = array[i]; |
| 560 current = callback(current, element, i, array); | 552 current = callback(current, element, i, array); |
| 561 } | 553 } |
| 562 } | 554 } |
| 563 return current; | 555 return current; |
| 564 } | 556 } |
| 565 | 557 |
| 566 // ES6 draft 07-15-13, section 22.2.3.19 | 558 // ES6 draft 07-15-13, section 22.2.3.19 |
| 567 function TypedArrayReduceRight(callback, current) { | 559 function TypedArrayReduceRight(callback, current) { |
| 568 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 560 %ValidateTypedArray(this, "TypedArray.prototype.reduceRight"); |
| 569 | 561 |
| 570 var length = %_TypedArrayGetLength(this); | 562 var length = %_TypedArrayGetLength(this); |
| 571 return InnerArrayReduceRight(callback, current, this, length, | 563 return InnerArrayReduceRight(callback, current, this, length, |
| 572 arguments.length); | 564 arguments.length); |
| 573 } | 565 } |
| 574 %FunctionSetLength(TypedArrayReduceRight, 1); | 566 %FunctionSetLength(TypedArrayReduceRight, 1); |
| 575 | 567 |
| 576 | 568 |
| 577 function TypedArraySlice(start, end) { | 569 function TypedArraySlice(start, end) { |
| 578 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 570 %ValidateTypedArray(this, "TypedArray.prototype.slice"); |
| 571 | |
| 579 var len = %_TypedArrayGetLength(this); | 572 var len = %_TypedArrayGetLength(this); |
| 580 | 573 |
| 581 var relativeStart = TO_INTEGER(start); | 574 var relativeStart = TO_INTEGER(start); |
| 582 | 575 |
| 583 var k; | 576 var k; |
| 584 if (relativeStart < 0) { | 577 if (relativeStart < 0) { |
| 585 k = MaxSimple(len + relativeStart, 0); | 578 k = MaxSimple(len + relativeStart, 0); |
| 586 } else { | 579 } else { |
| 587 k = MinSimple(relativeStart, len); | 580 k = MinSimple(relativeStart, len); |
| 588 } | 581 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 %AddNamedProperty(GlobalNAME.prototype, | 716 %AddNamedProperty(GlobalNAME.prototype, |
| 724 "constructor", global.NAME, DONT_ENUM); | 717 "constructor", global.NAME, DONT_ENUM); |
| 725 %AddNamedProperty(GlobalNAME.prototype, | 718 %AddNamedProperty(GlobalNAME.prototype, |
| 726 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 719 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 727 READ_ONLY | DONT_ENUM | DONT_DELETE); | 720 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 728 endmacro | 721 endmacro |
| 729 | 722 |
| 730 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 723 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 731 | 724 |
| 732 }) | 725 }) |
| OLD | NEW |