| 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 InnerArrayFind; | 22 var InnerArrayFind; |
| 24 var InnerArrayFindIndex; | 23 var InnerArrayFindIndex; |
| 25 var InnerArrayJoin; | 24 var InnerArrayJoin; |
| 26 var InnerArraySort; | 25 var InnerArraySort; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 | 45 |
| 47 macro DECLARE_GLOBALS(NAME, SIZE) | 46 macro DECLARE_GLOBALS(NAME, SIZE) |
| 48 var GlobalNAME = global.NAME; | 47 var GlobalNAME = global.NAME; |
| 49 endmacro | 48 endmacro |
| 50 | 49 |
| 51 TYPED_ARRAYS(DECLARE_GLOBALS) | 50 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 52 | 51 |
| 53 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); | 52 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); |
| 54 | 53 |
| 55 utils.Import(function(from) { | 54 utils.Import(function(from) { |
| 56 ArrayValues = from.ArrayValues; | |
| 57 GetIterator = from.GetIterator; | 55 GetIterator = from.GetIterator; |
| 58 GetMethod = from.GetMethod; | 56 GetMethod = from.GetMethod; |
| 59 InnerArrayFind = from.InnerArrayFind; | 57 InnerArrayFind = from.InnerArrayFind; |
| 60 InnerArrayFindIndex = from.InnerArrayFindIndex; | 58 InnerArrayFindIndex = from.InnerArrayFindIndex; |
| 61 InnerArrayJoin = from.InnerArrayJoin; | 59 InnerArrayJoin = from.InnerArrayJoin; |
| 62 InnerArraySort = from.InnerArraySort; | 60 InnerArraySort = from.InnerArraySort; |
| 63 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 61 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
| 64 MaxSimple = from.MaxSimple; | 62 MaxSimple = from.MaxSimple; |
| 65 MinSimple = from.MinSimple; | 63 MinSimple = from.MinSimple; |
| 66 }); | 64 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 return defaultConstructor; | 77 return defaultConstructor; |
| 80 } | 78 } |
| 81 if (%IsConstructor(species)) { | 79 if (%IsConstructor(species)) { |
| 82 return species; | 80 return species; |
| 83 } | 81 } |
| 84 throw %make_type_error(kSpeciesNotConstructor); | 82 throw %make_type_error(kSpeciesNotConstructor); |
| 85 } | 83 } |
| 86 | 84 |
| 87 // --------------- Typed Arrays --------------------- | 85 // --------------- Typed Arrays --------------------- |
| 88 | 86 |
| 87 // ES6 section 22.2.3.5.1 ValidateTypedArray ( O ) |
| 88 function ValidateTypedArray(array, methodName) { |
| 89 if (!IS_TYPEDARRAY(array)) throw %make_type_error(kNotTypedArray); |
| 90 |
| 91 if (%_ArrayBufferViewWasNeutered(array)) |
| 92 throw %make_type_error(kDetachedOperation, methodName); |
| 93 } |
| 94 |
| 89 function TypedArrayDefaultConstructor(typedArray) { | 95 function TypedArrayDefaultConstructor(typedArray) { |
| 90 switch (%_ClassOf(typedArray)) { | 96 switch (%_ClassOf(typedArray)) { |
| 91 macro TYPED_ARRAY_CONSTRUCTOR_CASE(NAME, ELEMENT_SIZE) | 97 macro TYPED_ARRAY_CONSTRUCTOR_CASE(NAME, ELEMENT_SIZE) |
| 92 case "NAME": | 98 case "NAME": |
| 93 return GlobalNAME; | 99 return GlobalNAME; |
| 94 endmacro | 100 endmacro |
| 95 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR_CASE) | 101 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR_CASE) |
| 96 } | 102 } |
| 97 // The TypeError should not be generated since all callers should | 103 // The TypeError should not be generated since all callers should |
| 98 // have already called ValidateTypedArray. | 104 // have already called ValidateTypedArray. |
| 99 throw %make_type_error(kIncompatibleMethodReceiver, | 105 throw %make_type_error(kIncompatibleMethodReceiver, |
| 100 "TypedArrayDefaultConstructor", this); | 106 "TypedArrayDefaultConstructor", this); |
| 101 } | 107 } |
| 102 | 108 |
| 103 function TypedArrayCreate(constructor, arg0, arg1, arg2) { | 109 function TypedArrayCreate(constructor, arg0, arg1, arg2) { |
| 104 if (IS_UNDEFINED(arg1)) { | 110 if (IS_UNDEFINED(arg1)) { |
| 105 var newTypedArray = new constructor(arg0); | 111 var newTypedArray = new constructor(arg0); |
| 106 } else { | 112 } else { |
| 107 var newTypedArray = new constructor(arg0, arg1, arg2); | 113 var newTypedArray = new constructor(arg0, arg1, arg2); |
| 108 } | 114 } |
| 109 if (!IS_TYPEDARRAY(newTypedArray)) throw %make_type_error(kNotTypedArray); | 115 ValidateTypedArray(newTypedArray, "TypedArrayCreate"); |
| 110 // TODO(littledan): Check for being detached, here and elsewhere | |
| 111 // All callers where the first argument is a Number have no additional | |
| 112 // arguments. | |
| 113 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { | 116 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { |
| 114 throw %make_type_error(kTypedArrayTooShort); | 117 throw %make_type_error(kTypedArrayTooShort); |
| 115 } | 118 } |
| 116 return newTypedArray; | 119 return newTypedArray; |
| 117 } | 120 } |
| 118 | 121 |
| 119 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { | 122 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) { |
| 120 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); | 123 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); |
| 121 var constructor = SpeciesConstructor(exemplar, defaultConstructor, | 124 var constructor = SpeciesConstructor(exemplar, defaultConstructor); |
| 122 conservative); | |
| 123 return TypedArrayCreate(constructor, arg0, arg1, arg2); | 125 return TypedArrayCreate(constructor, arg0, arg1, arg2); |
| 124 } | 126 } |
| 125 | 127 |
| 126 macro TYPED_ARRAY_CONSTRUCTOR(NAME, ELEMENT_SIZE) | 128 macro TYPED_ARRAY_CONSTRUCTOR(NAME, ELEMENT_SIZE) |
| 127 function NAMEConstructByIterable(obj, iterable, iteratorFn) { | 129 function NAMEConstructByIterable(obj, iterable, iteratorFn) { |
| 128 if (%IterableToListCanBeElided(iterable)) { | 130 if (%IterableToListCanBeElided(iterable)) { |
| 129 // This .length access is unobservable, because it being observable would | 131 // This .length access is unobservable, because it being observable would |
| 130 // mean that iteration has side effects, and we wouldn't reach this path. | 132 // mean that iteration has side effects, and we wouldn't reach this path. |
| 131 %typed_array_construct_by_array_like( | 133 %typed_array_construct_by_array_like( |
| 132 obj, iterable, iterable.length, ELEMENT_SIZE); | 134 obj, iterable, iterable.length, ELEMENT_SIZE); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 endInt = MinSimple(endInt, srcLength); | 219 endInt = MinSimple(endInt, srcLength); |
| 218 } | 220 } |
| 219 | 221 |
| 220 if (endInt < beginInt) { | 222 if (endInt < beginInt) { |
| 221 endInt = beginInt; | 223 endInt = beginInt; |
| 222 } | 224 } |
| 223 | 225 |
| 224 var newLength = endInt - beginInt; | 226 var newLength = endInt - beginInt; |
| 225 var beginByteOffset = | 227 var beginByteOffset = |
| 226 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 228 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 227 // BUG(v8:4665): For web compatibility, subarray needs to always build an | 229 return TypedArraySpeciesCreate(this, %TypedArrayGetBuffer(this), |
| 228 // instance of the default constructor. | 230 beginByteOffset, newLength); |
| 229 // TODO(littledan): Switch to the standard or standardize the fix | |
| 230 return new GlobalNAME(%TypedArrayGetBuffer(this), beginByteOffset, newLength); | |
| 231 } | 231 } |
| 232 endmacro | 232 endmacro |
| 233 | 233 |
| 234 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 234 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 235 | 235 |
| 236 function TypedArraySubArray(begin, end) { | 236 function TypedArraySubArray(begin, end) { |
| 237 switch (%_ClassOf(this)) { | 237 switch (%_ClassOf(this)) { |
| 238 macro TYPED_ARRAY_SUBARRAY_CASE(NAME, ELEMENT_SIZE) | 238 macro TYPED_ARRAY_SUBARRAY_CASE(NAME, ELEMENT_SIZE) |
| 239 case "NAME": | 239 case "NAME": |
| 240 return %_Call(NAMESubArray, this, begin, end); | 240 return %_Call(NAMESubArray, this, begin, end); |
| 241 endmacro | 241 endmacro |
| 242 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) | 242 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) |
| 243 } | 243 } |
| 244 throw %make_type_error(kIncompatibleMethodReceiver, | 244 throw %make_type_error(kIncompatibleMethodReceiver, |
| 245 "get TypedArray.prototype.subarray", this); | 245 "get %TypedArray%.prototype.subarray", this); |
| 246 } | 246 } |
| 247 %SetForceInlineFlag(TypedArraySubArray); | 247 %SetForceInlineFlag(TypedArraySubArray); |
| 248 | 248 |
| 249 | 249 |
| 250 | 250 |
| 251 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { | 251 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
| 252 if (offset > 0) { | 252 if (offset > 0) { |
| 253 for (var i = 0; i < sourceLength; i++) { | 253 for (var i = 0; i < sourceLength; i++) { |
| 254 target[offset + i] = source[i]; | 254 target[offset + i] = source[i]; |
| 255 } | 255 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (i in array) { | 368 if (i in array) { |
| 369 var element = array[i]; | 369 var element = array[i]; |
| 370 if (!%_Call(f, receiver, element, i, array)) return false; | 370 if (!%_Call(f, receiver, element, i, array)) return false; |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 return true; | 373 return true; |
| 374 } | 374 } |
| 375 | 375 |
| 376 // ES6 draft 05-05-15, section 22.2.3.7 | 376 // ES6 draft 05-05-15, section 22.2.3.7 |
| 377 function TypedArrayEvery(f, receiver) { | 377 function TypedArrayEvery(f, receiver) { |
| 378 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 378 ValidateTypedArray(this, "%TypedArray%.prototype.every"); |
| 379 | 379 |
| 380 var length = %_TypedArrayGetLength(this); | 380 var length = %_TypedArrayGetLength(this); |
| 381 | 381 |
| 382 return InnerTypedArrayEvery(f, receiver, this, length); | 382 return InnerTypedArrayEvery(f, receiver, this, length); |
| 383 } | 383 } |
| 384 %FunctionSetLength(TypedArrayEvery, 1); | 384 %FunctionSetLength(TypedArrayEvery, 1); |
| 385 | 385 |
| 386 function InnerTypedArrayForEach(f, receiver, array, length) { | 386 function InnerTypedArrayForEach(f, receiver, array, length) { |
| 387 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 387 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 388 | 388 |
| 389 if (IS_UNDEFINED(receiver)) { | 389 if (IS_UNDEFINED(receiver)) { |
| 390 for (var i = 0; i < length; i++) { | 390 for (var i = 0; i < length; i++) { |
| 391 if (i in array) { | 391 if (i in array) { |
| 392 var element = array[i]; | 392 var element = array[i]; |
| 393 f(element, i, array); | 393 f(element, i, array); |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 } else { | 396 } else { |
| 397 for (var i = 0; i < length; i++) { | 397 for (var i = 0; i < length; i++) { |
| 398 if (i in array) { | 398 if (i in array) { |
| 399 var element = array[i]; | 399 var element = array[i]; |
| 400 %_Call(f, receiver, element, i, array); | 400 %_Call(f, receiver, element, i, array); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 // ES6 draft 08-24-14, section 22.2.3.12 | 406 // ES6 draft 08-24-14, section 22.2.3.12 |
| 407 function TypedArrayForEach(f, receiver) { | 407 function TypedArrayForEach(f, receiver) { |
| 408 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 408 ValidateTypedArray(this, "%TypedArray%.prototype.forEach"); |
| 409 | 409 |
| 410 var length = %_TypedArrayGetLength(this); | 410 var length = %_TypedArrayGetLength(this); |
| 411 | 411 |
| 412 InnerTypedArrayForEach(f, receiver, this, length); | 412 InnerTypedArrayForEach(f, receiver, this, length); |
| 413 } | 413 } |
| 414 %FunctionSetLength(TypedArrayForEach, 1); | 414 %FunctionSetLength(TypedArrayForEach, 1); |
| 415 | 415 |
| 416 // The following functions cannot be made efficient on sparse arrays while | 416 // The following functions cannot be made efficient on sparse arrays while |
| 417 // preserving the semantics, since the calls to the receiver function can add | 417 // preserving the semantics, since the calls to the receiver function can add |
| 418 // or delete elements from the array. | 418 // or delete elements from the array. |
| 419 function InnerTypedArrayFilter(f, receiver, array, length, result) { | 419 function InnerTypedArrayFilter(f, receiver, array, length, result) { |
| 420 var result_length = 0; | 420 var result_length = 0; |
| 421 for (var i = 0; i < length; i++) { | 421 for (var i = 0; i < length; i++) { |
| 422 if (i in array) { | 422 if (i in array) { |
| 423 var element = array[i]; | 423 var element = array[i]; |
| 424 if (%_Call(f, receiver, element, i, array)) { | 424 if (%_Call(f, receiver, element, i, array)) { |
| 425 %CreateDataProperty(result, result_length, element); | 425 %CreateDataProperty(result, result_length, element); |
| 426 result_length++; | 426 result_length++; |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 return result; | 430 return result; |
| 431 } | 431 } |
| 432 | 432 |
| 433 | 433 |
| 434 // ES6 draft 07-15-13, section 22.2.3.9 | 434 // ES6 draft 07-15-13, section 22.2.3.9 |
| 435 function TypedArrayFilter(f, thisArg) { | 435 function TypedArrayFilter(f, thisArg) { |
| 436 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 436 ValidateTypedArray(this, "%TypeArray%.prototype.filter"); |
| 437 | 437 |
| 438 var length = %_TypedArrayGetLength(this); | 438 var length = %_TypedArrayGetLength(this); |
| 439 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 439 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 440 var result = new InternalArray(); | 440 var result = new InternalArray(); |
| 441 InnerTypedArrayFilter(f, thisArg, this, length, result); | 441 InnerTypedArrayFilter(f, thisArg, this, length, result); |
| 442 var captured = result.length; | 442 var captured = result.length; |
| 443 var output = TypedArraySpeciesCreate(this, captured); | 443 var output = TypedArraySpeciesCreate(this, captured); |
| 444 for (var i = 0; i < captured; i++) { | 444 for (var i = 0; i < captured; i++) { |
| 445 output[i] = result[i]; | 445 output[i] = result[i]; |
| 446 } | 446 } |
| 447 return output; | 447 return output; |
| 448 } | 448 } |
| 449 %FunctionSetLength(TypedArrayFilter, 1); | 449 %FunctionSetLength(TypedArrayFilter, 1); |
| 450 | 450 |
| 451 | 451 |
| 452 // ES6 draft 07-15-13, section 22.2.3.10 | 452 // ES6 draft 07-15-13, section 22.2.3.10 |
| 453 function TypedArrayFind(predicate, thisArg) { | 453 function TypedArrayFind(predicate, thisArg) { |
| 454 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 454 ValidateTypedArray(this, "%TypedArray%.prototype.find"); |
| 455 | 455 |
| 456 var length = %_TypedArrayGetLength(this); | 456 var length = %_TypedArrayGetLength(this); |
| 457 | 457 |
| 458 return InnerArrayFind(predicate, thisArg, this, length); | 458 return InnerArrayFind(predicate, thisArg, this, length); |
| 459 } | 459 } |
| 460 %FunctionSetLength(TypedArrayFind, 1); | 460 %FunctionSetLength(TypedArrayFind, 1); |
| 461 | 461 |
| 462 | 462 |
| 463 // ES6 draft 07-15-13, section 22.2.3.11 | 463 // ES6 draft 07-15-13, section 22.2.3.11 |
| 464 function TypedArrayFindIndex(predicate, thisArg) { | 464 function TypedArrayFindIndex(predicate, thisArg) { |
| 465 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 465 ValidateTypedArray(this, "%TypedArray%.prototype.findIndex"); |
| 466 | 466 |
| 467 var length = %_TypedArrayGetLength(this); | 467 var length = %_TypedArrayGetLength(this); |
| 468 | 468 |
| 469 return InnerArrayFindIndex(predicate, thisArg, this, length); | 469 return InnerArrayFindIndex(predicate, thisArg, this, length); |
| 470 } | 470 } |
| 471 %FunctionSetLength(TypedArrayFindIndex, 1); | 471 %FunctionSetLength(TypedArrayFindIndex, 1); |
| 472 | 472 |
| 473 | 473 |
| 474 // ES6 draft 05-18-15, section 22.2.3.25 | 474 // ES6 draft 05-18-15, section 22.2.3.25 |
| 475 function TypedArraySort(comparefn) { | 475 function TypedArraySort(comparefn) { |
| 476 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 476 ValidateTypedArray(this, "%TypedArray%.prototype.sort"); |
| 477 | 477 |
| 478 var length = %_TypedArrayGetLength(this); | 478 var length = %_TypedArrayGetLength(this); |
| 479 | 479 |
| 480 if (IS_UNDEFINED(comparefn)) { | 480 if (IS_UNDEFINED(comparefn)) { |
| 481 return %TypedArraySortFast(this); | 481 return %TypedArraySortFast(this); |
| 482 } | 482 } |
| 483 | 483 |
| 484 return InnerArraySort(this, length, comparefn); | 484 return InnerArraySort(this, length, comparefn); |
| 485 } | 485 } |
| 486 | 486 |
| 487 | 487 |
| 488 // ES6 draft 07-15-13, section 22.2.3.18 | 488 // ES6 draft 07-15-13, section 22.2.3.18 |
| 489 function TypedArrayMap(f, thisArg) { | 489 function TypedArrayMap(f, thisArg) { |
| 490 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 490 ValidateTypedArray(this, "%TypedArray%.prototype.map"); |
| 491 | 491 |
| 492 var length = %_TypedArrayGetLength(this); | 492 var length = %_TypedArrayGetLength(this); |
| 493 var result = TypedArraySpeciesCreate(this, length); | 493 var result = TypedArraySpeciesCreate(this, length); |
| 494 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 494 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 495 for (var i = 0; i < length; i++) { | 495 for (var i = 0; i < length; i++) { |
| 496 var element = this[i]; | 496 var element = this[i]; |
| 497 result[i] = %_Call(f, thisArg, element, i, this); | 497 result[i] = %_Call(f, thisArg, element, i, this); |
| 498 } | 498 } |
| 499 return result; | 499 return result; |
| 500 } | 500 } |
| 501 %FunctionSetLength(TypedArrayMap, 1); | 501 %FunctionSetLength(TypedArrayMap, 1); |
| 502 | 502 |
| 503 function InnerTypedArraySome(f, receiver, array, length) { | 503 function InnerTypedArraySome(f, receiver, array, length) { |
| 504 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 504 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 505 | 505 |
| 506 for (var i = 0; i < length; i++) { | 506 for (var i = 0; i < length; i++) { |
| 507 if (i in array) { | 507 if (i in array) { |
| 508 var element = array[i]; | 508 var element = array[i]; |
| 509 if (%_Call(f, receiver, element, i, array)) return true; | 509 if (%_Call(f, receiver, element, i, array)) return true; |
| 510 } | 510 } |
| 511 } | 511 } |
| 512 return false; | 512 return false; |
| 513 } | 513 } |
| 514 | 514 |
| 515 // ES6 draft 05-05-15, section 22.2.3.24 | 515 // ES6 draft 05-05-15, section 22.2.3.24 |
| 516 function TypedArraySome(f, receiver) { | 516 function TypedArraySome(f, receiver) { |
| 517 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 517 ValidateTypedArray(this, "%TypedArray%.prototype.some"); |
| 518 | 518 |
| 519 var length = %_TypedArrayGetLength(this); | 519 var length = %_TypedArrayGetLength(this); |
| 520 | 520 |
| 521 return InnerTypedArraySome(f, receiver, this, length); | 521 return InnerTypedArraySome(f, receiver, this, length); |
| 522 } | 522 } |
| 523 %FunctionSetLength(TypedArraySome, 1); | 523 %FunctionSetLength(TypedArraySome, 1); |
| 524 | 524 |
| 525 | 525 |
| 526 // ES6 section 22.2.3.27 | 526 // ES6 section 22.2.3.27 |
| 527 function TypedArrayToLocaleString() { | 527 function TypedArrayToLocaleString() { |
| 528 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 528 ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString"); |
| 529 | 529 |
| 530 var length = %_TypedArrayGetLength(this); | 530 var length = %_TypedArrayGetLength(this); |
| 531 | 531 |
| 532 return InnerArrayToLocaleString(this, length); | 532 return InnerArrayToLocaleString(this, length); |
| 533 } | 533 } |
| 534 | 534 |
| 535 | 535 |
| 536 // ES6 section 22.2.3.14 | 536 // ES6 section 22.2.3.14 |
| 537 function TypedArrayJoin(separator) { | 537 function TypedArrayJoin(separator) { |
| 538 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 538 ValidateTypedArray(this, "%TypedArray%.prototype.join"); |
| 539 | 539 |
| 540 var length = %_TypedArrayGetLength(this); | 540 var length = %_TypedArrayGetLength(this); |
| 541 | 541 |
| 542 return InnerArrayJoin(separator, this, length); | 542 return InnerArrayJoin(separator, this, length); |
| 543 } | 543 } |
| 544 | 544 |
| 545 function InnerTypedArrayReduce( | 545 function InnerTypedArrayReduce( |
| 546 callback, current, array, length, argumentsLength) { | 546 callback, current, array, length, argumentsLength) { |
| 547 if (!IS_CALLABLE(callback)) { | 547 if (!IS_CALLABLE(callback)) { |
| 548 throw %make_type_error(kCalledNonCallable, callback); | 548 throw %make_type_error(kCalledNonCallable, callback); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 563 if (i in array) { | 563 if (i in array) { |
| 564 var element = array[i]; | 564 var element = array[i]; |
| 565 current = callback(current, element, i, array); | 565 current = callback(current, element, i, array); |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 return current; | 568 return current; |
| 569 } | 569 } |
| 570 | 570 |
| 571 // ES6 draft 07-15-13, section 22.2.3.19 | 571 // ES6 draft 07-15-13, section 22.2.3.19 |
| 572 function TypedArrayReduce(callback, current) { | 572 function TypedArrayReduce(callback, current) { |
| 573 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 573 ValidateTypedArray(this, "%TypedArray%.prototype.reduce"); |
| 574 | 574 |
| 575 var length = %_TypedArrayGetLength(this); | 575 var length = %_TypedArrayGetLength(this); |
| 576 return InnerTypedArrayReduce( | 576 return InnerTypedArrayReduce( |
| 577 callback, current, this, length, arguments.length); | 577 callback, current, this, length, arguments.length); |
| 578 } | 578 } |
| 579 %FunctionSetLength(TypedArrayReduce, 1); | 579 %FunctionSetLength(TypedArrayReduce, 1); |
| 580 | 580 |
| 581 function InnerArrayReduceRight(callback, current, array, length, | 581 function InnerArrayReduceRight(callback, current, array, length, |
| 582 argumentsLength) { | 582 argumentsLength) { |
| 583 if (!IS_CALLABLE(callback)) { | 583 if (!IS_CALLABLE(callback)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 599 if (i in array) { | 599 if (i in array) { |
| 600 var element = array[i]; | 600 var element = array[i]; |
| 601 current = callback(current, element, i, array); | 601 current = callback(current, element, i, array); |
| 602 } | 602 } |
| 603 } | 603 } |
| 604 return current; | 604 return current; |
| 605 } | 605 } |
| 606 | 606 |
| 607 // ES6 draft 07-15-13, section 22.2.3.19 | 607 // ES6 draft 07-15-13, section 22.2.3.19 |
| 608 function TypedArrayReduceRight(callback, current) { | 608 function TypedArrayReduceRight(callback, current) { |
| 609 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 609 ValidateTypedArray(this, "%TypedArray%.prototype.reduceRight"); |
| 610 | 610 |
| 611 var length = %_TypedArrayGetLength(this); | 611 var length = %_TypedArrayGetLength(this); |
| 612 return InnerArrayReduceRight(callback, current, this, length, | 612 return InnerArrayReduceRight(callback, current, this, length, |
| 613 arguments.length); | 613 arguments.length); |
| 614 } | 614 } |
| 615 %FunctionSetLength(TypedArrayReduceRight, 1); | 615 %FunctionSetLength(TypedArrayReduceRight, 1); |
| 616 | 616 |
| 617 | 617 |
| 618 // ES6 draft 08-24-14, section 22.2.2.2 | 618 // ES6 draft 08-24-14, section 22.2.2.2 |
| 619 function TypedArrayOf() { | 619 function TypedArrayOf() { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 %AddNamedProperty(GlobalNAME.prototype, | 720 %AddNamedProperty(GlobalNAME.prototype, |
| 721 "constructor", global.NAME, DONT_ENUM); | 721 "constructor", global.NAME, DONT_ENUM); |
| 722 %AddNamedProperty(GlobalNAME.prototype, | 722 %AddNamedProperty(GlobalNAME.prototype, |
| 723 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 723 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 724 READ_ONLY | DONT_ENUM | DONT_DELETE); | 724 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 725 endmacro | 725 endmacro |
| 726 | 726 |
| 727 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 727 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 728 | 728 |
| 729 }) | 729 }) |
| OLD | NEW |