| 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; |
| 16 var GetIterator; | 17 var GetIterator; |
| 17 var GetMethod; | 18 var GetMethod; |
| 18 var GlobalArray = global.Array; | 19 var GlobalArray = global.Array; |
| 19 var GlobalArrayBuffer = global.ArrayBuffer; | 20 var GlobalArrayBuffer = global.ArrayBuffer; |
| 20 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; | 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; |
| 21 var GlobalObject = global.Object; | 22 var GlobalObject = global.Object; |
| 22 var InnerArrayFilter; | 23 var InnerArrayFilter; |
| 23 var InnerArrayFind; | 24 var InnerArrayFind; |
| 24 var InnerArrayFindIndex; | 25 var InnerArrayFindIndex; |
| 25 var InnerArrayJoin; | 26 var InnerArrayJoin; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 macro DECLARE_GLOBALS(NAME, SIZE) | 50 macro DECLARE_GLOBALS(NAME, SIZE) |
| 50 var GlobalNAME = global.NAME; | 51 var GlobalNAME = global.NAME; |
| 51 endmacro | 52 endmacro |
| 52 | 53 |
| 53 TYPED_ARRAYS(DECLARE_GLOBALS) | 54 TYPED_ARRAYS(DECLARE_GLOBALS) |
| 54 | 55 |
| 55 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); | 56 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); |
| 56 | 57 |
| 57 utils.Import(function(from) { | 58 utils.Import(function(from) { |
| 59 ArrayValues = from.ArrayValues; |
| 58 GetIterator = from.GetIterator; | 60 GetIterator = from.GetIterator; |
| 59 GetMethod = from.GetMethod; | 61 GetMethod = from.GetMethod; |
| 60 InnerArrayFilter = from.InnerArrayFilter; | 62 InnerArrayFilter = from.InnerArrayFilter; |
| 61 InnerArrayFind = from.InnerArrayFind; | 63 InnerArrayFind = from.InnerArrayFind; |
| 62 InnerArrayFindIndex = from.InnerArrayFindIndex; | 64 InnerArrayFindIndex = from.InnerArrayFindIndex; |
| 63 InnerArrayJoin = from.InnerArrayJoin; | 65 InnerArrayJoin = from.InnerArrayJoin; |
| 64 InnerArraySort = from.InnerArraySort; | 66 InnerArraySort = from.InnerArraySort; |
| 65 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 67 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
| 66 MaxSimple = from.MaxSimple; | 68 MaxSimple = from.MaxSimple; |
| 67 MinSimple = from.MinSimple; | 69 MinSimple = from.MinSimple; |
| 68 SpeciesConstructor = from.SpeciesConstructor; | 70 SpeciesConstructor = from.SpeciesConstructor; |
| 69 ToPositiveInteger = from.ToPositiveInteger; | 71 ToPositiveInteger = from.ToPositiveInteger; |
| 70 ToIndex = from.ToIndex; | 72 ToIndex = from.ToIndex; |
| 71 }); | 73 }); |
| 72 | 74 |
| 73 // --------------- Typed Arrays --------------------- | 75 // --------------- Typed Arrays --------------------- |
| 74 | 76 |
| 75 // ES6 section 22.2.3.5.1 ValidateTypedArray ( O ) | |
| 76 function ValidateTypedArray(array, methodName) { | |
| 77 if (!IS_TYPEDARRAY(array)) throw %make_type_error(kNotTypedArray); | |
| 78 | |
| 79 if (%_ArrayBufferViewWasNeutered(array)) | |
| 80 throw %make_type_error(kDetachedOperation, methodName); | |
| 81 } | |
| 82 | |
| 83 function TypedArrayDefaultConstructor(typedArray) { | 77 function TypedArrayDefaultConstructor(typedArray) { |
| 84 switch (%_ClassOf(typedArray)) { | 78 switch (%_ClassOf(typedArray)) { |
| 85 macro TYPED_ARRAY_CONSTRUCTOR_CASE(NAME, ELEMENT_SIZE) | 79 macro TYPED_ARRAY_CONSTRUCTOR_CASE(NAME, ELEMENT_SIZE) |
| 86 case "NAME": | 80 case "NAME": |
| 87 return GlobalNAME; | 81 return GlobalNAME; |
| 88 endmacro | 82 endmacro |
| 89 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR_CASE) | 83 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR_CASE) |
| 90 } | 84 } |
| 91 // The TypeError should not be generated since all callers should | 85 // The TypeError should not be generated since all callers should |
| 92 // have already called ValidateTypedArray. | 86 // have already called ValidateTypedArray. |
| 93 throw %make_type_error(kIncompatibleMethodReceiver, | 87 throw %make_type_error(kIncompatibleMethodReceiver, |
| 94 "TypedArrayDefaultConstructor", this); | 88 "TypedArrayDefaultConstructor", this); |
| 95 } | 89 } |
| 96 | 90 |
| 97 function TypedArrayCreate(constructor, arg0, arg1, arg2) { | 91 function TypedArrayCreate(constructor, arg0, arg1, arg2) { |
| 98 if (IS_UNDEFINED(arg1)) { | 92 if (IS_UNDEFINED(arg1)) { |
| 99 var newTypedArray = new constructor(arg0); | 93 var newTypedArray = new constructor(arg0); |
| 100 } else { | 94 } else { |
| 101 var newTypedArray = new constructor(arg0, arg1, arg2); | 95 var newTypedArray = new constructor(arg0, arg1, arg2); |
| 102 } | 96 } |
| 103 ValidateTypedArray(newTypedArray, "TypedArrayCreate"); | 97 if (!IS_TYPEDARRAY(newTypedArray)) throw %make_type_error(kNotTypedArray); |
| 98 // TODO(littledan): Check for being detached, here and elsewhere |
| 99 // All callers where the first argument is a Number have no additional |
| 100 // arguments. |
| 104 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { | 101 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) { |
| 105 throw %make_type_error(kTypedArrayTooShort); | 102 throw %make_type_error(kTypedArrayTooShort); |
| 106 } | 103 } |
| 107 return newTypedArray; | 104 return newTypedArray; |
| 108 } | 105 } |
| 109 | 106 |
| 110 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) { | 107 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { |
| 111 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); | 108 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); |
| 112 var constructor = SpeciesConstructor(exemplar, defaultConstructor); | 109 var constructor = SpeciesConstructor(exemplar, defaultConstructor, |
| 110 conservative); |
| 113 return TypedArrayCreate(constructor, arg0, arg1, arg2); | 111 return TypedArrayCreate(constructor, arg0, arg1, arg2); |
| 114 } | 112 } |
| 115 | 113 |
| 116 macro TYPED_ARRAY_CONSTRUCTOR(NAME, ELEMENT_SIZE) | 114 macro TYPED_ARRAY_CONSTRUCTOR(NAME, ELEMENT_SIZE) |
| 117 function NAMEConstructByIterable(obj, iterable, iteratorFn) { | 115 function NAMEConstructByIterable(obj, iterable, iteratorFn) { |
| 118 if (%has_iteration_side_effects(iterable)) { | 116 if (%has_iteration_side_effects(iterable)) { |
| 119 var list = new InternalArray(); | 117 var list = new InternalArray(); |
| 120 // Reading the Symbol.iterator property of iterable twice would be | 118 // Reading the Symbol.iterator property of iterable twice would be |
| 121 // observable with getters, so instead, we call the function which | 119 // observable with getters, so instead, we call the function which |
| 122 // was already looked up, and wrap it in another iterable. The | 120 // was already looked up, and wrap it in another iterable. The |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 endInt = MinSimple(endInt, srcLength); | 200 endInt = MinSimple(endInt, srcLength); |
| 203 } | 201 } |
| 204 | 202 |
| 205 if (endInt < beginInt) { | 203 if (endInt < beginInt) { |
| 206 endInt = beginInt; | 204 endInt = beginInt; |
| 207 } | 205 } |
| 208 | 206 |
| 209 var newLength = endInt - beginInt; | 207 var newLength = endInt - beginInt; |
| 210 var beginByteOffset = | 208 var beginByteOffset = |
| 211 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 209 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 212 return TypedArraySpeciesCreate(this, %TypedArrayGetBuffer(this), | 210 // BUG(v8:4665): For web compatibility, subarray needs to always build an |
| 213 beginByteOffset, newLength); | 211 // instance of the default constructor. |
| 212 // TODO(littledan): Switch to the standard or standardize the fix |
| 213 return new GlobalNAME(%TypedArrayGetBuffer(this), beginByteOffset, newLength); |
| 214 } | 214 } |
| 215 endmacro | 215 endmacro |
| 216 | 216 |
| 217 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 217 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 218 | 218 |
| 219 function TypedArraySubArray(begin, end) { | 219 function TypedArraySubArray(begin, end) { |
| 220 switch (%_ClassOf(this)) { | 220 switch (%_ClassOf(this)) { |
| 221 macro TYPED_ARRAY_SUBARRAY_CASE(NAME, ELEMENT_SIZE) | 221 macro TYPED_ARRAY_SUBARRAY_CASE(NAME, ELEMENT_SIZE) |
| 222 case "NAME": | 222 case "NAME": |
| 223 return %_Call(NAMESubArray, this, begin, end); | 223 return %_Call(NAMESubArray, this, begin, end); |
| 224 endmacro | 224 endmacro |
| 225 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) | 225 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) |
| 226 } | 226 } |
| 227 throw %make_type_error(kIncompatibleMethodReceiver, | 227 throw %make_type_error(kIncompatibleMethodReceiver, |
| 228 "get %TypedArray%.prototype.subarray", this); | 228 "get TypedArray.prototype.subarray", this); |
| 229 } | 229 } |
| 230 %SetForceInlineFlag(TypedArraySubArray); | 230 %SetForceInlineFlag(TypedArraySubArray); |
| 231 | 231 |
| 232 | 232 |
| 233 | 233 |
| 234 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { | 234 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
| 235 if (offset > 0) { | 235 if (offset > 0) { |
| 236 for (var i = 0; i < sourceLength; i++) { | 236 for (var i = 0; i < sourceLength; i++) { |
| 237 target[offset + i] = source[i]; | 237 target[offset + i] = source[i]; |
| 238 } | 238 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 if (i in array) { | 353 if (i in array) { |
| 354 var element = array[i]; | 354 var element = array[i]; |
| 355 if (!%_Call(f, receiver, element, i, array)) return false; | 355 if (!%_Call(f, receiver, element, i, array)) return false; |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 return true; | 358 return true; |
| 359 } | 359 } |
| 360 | 360 |
| 361 // ES6 draft 05-05-15, section 22.2.3.7 | 361 // ES6 draft 05-05-15, section 22.2.3.7 |
| 362 function TypedArrayEvery(f, receiver) { | 362 function TypedArrayEvery(f, receiver) { |
| 363 ValidateTypedArray(this, "%TypedArray%.prototype.every"); | 363 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 364 | 364 |
| 365 var length = %_TypedArrayGetLength(this); | 365 var length = %_TypedArrayGetLength(this); |
| 366 | 366 |
| 367 return InnerTypedArrayEvery(f, receiver, this, length); | 367 return InnerTypedArrayEvery(f, receiver, this, length); |
| 368 } | 368 } |
| 369 %FunctionSetLength(TypedArrayEvery, 1); | 369 %FunctionSetLength(TypedArrayEvery, 1); |
| 370 | 370 |
| 371 function InnerTypedArrayForEach(f, receiver, array, length) { | 371 function InnerTypedArrayForEach(f, receiver, array, length) { |
| 372 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 372 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 373 | 373 |
| 374 if (IS_UNDEFINED(receiver)) { | 374 if (IS_UNDEFINED(receiver)) { |
| 375 for (var i = 0; i < length; i++) { | 375 for (var i = 0; i < length; i++) { |
| 376 if (i in array) { | 376 if (i in array) { |
| 377 var element = array[i]; | 377 var element = array[i]; |
| 378 f(element, i, array); | 378 f(element, i, array); |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 } else { | 381 } else { |
| 382 for (var i = 0; i < length; i++) { | 382 for (var i = 0; i < length; i++) { |
| 383 if (i in array) { | 383 if (i in array) { |
| 384 var element = array[i]; | 384 var element = array[i]; |
| 385 %_Call(f, receiver, element, i, array); | 385 %_Call(f, receiver, element, i, array); |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 // ES6 draft 08-24-14, section 22.2.3.12 | 391 // ES6 draft 08-24-14, section 22.2.3.12 |
| 392 function TypedArrayForEach(f, receiver) { | 392 function TypedArrayForEach(f, receiver) { |
| 393 ValidateTypedArray(this, "%TypedArray%.prototype.forEach"); | 393 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 394 | 394 |
| 395 var length = %_TypedArrayGetLength(this); | 395 var length = %_TypedArrayGetLength(this); |
| 396 | 396 |
| 397 InnerTypedArrayForEach(f, receiver, this, length); | 397 InnerTypedArrayForEach(f, receiver, this, length); |
| 398 } | 398 } |
| 399 %FunctionSetLength(TypedArrayForEach, 1); | 399 %FunctionSetLength(TypedArrayForEach, 1); |
| 400 | 400 |
| 401 | 401 |
| 402 // ES6 draft 07-15-13, section 22.2.3.9 | 402 // ES6 draft 07-15-13, section 22.2.3.9 |
| 403 function TypedArrayFilter(f, thisArg) { | 403 function TypedArrayFilter(f, thisArg) { |
| 404 ValidateTypedArray(this, "%TypeArray%.prototype.filter"); | 404 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 405 | 405 |
| 406 var length = %_TypedArrayGetLength(this); | 406 var length = %_TypedArrayGetLength(this); |
| 407 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 407 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 408 var result = new InternalArray(); | 408 var result = new InternalArray(); |
| 409 InnerArrayFilter(f, thisArg, this, length, result); | 409 InnerArrayFilter(f, thisArg, this, length, result); |
| 410 var captured = result.length; | 410 var captured = result.length; |
| 411 var output = TypedArraySpeciesCreate(this, captured); | 411 var output = TypedArraySpeciesCreate(this, captured); |
| 412 for (var i = 0; i < captured; i++) { | 412 for (var i = 0; i < captured; i++) { |
| 413 output[i] = result[i]; | 413 output[i] = result[i]; |
| 414 } | 414 } |
| 415 return output; | 415 return output; |
| 416 } | 416 } |
| 417 %FunctionSetLength(TypedArrayFilter, 1); | 417 %FunctionSetLength(TypedArrayFilter, 1); |
| 418 | 418 |
| 419 | 419 |
| 420 // ES6 draft 07-15-13, section 22.2.3.10 | 420 // ES6 draft 07-15-13, section 22.2.3.10 |
| 421 function TypedArrayFind(predicate, thisArg) { | 421 function TypedArrayFind(predicate, thisArg) { |
| 422 ValidateTypedArray(this, "%TypedArray%.prototype.find"); | 422 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 423 | 423 |
| 424 var length = %_TypedArrayGetLength(this); | 424 var length = %_TypedArrayGetLength(this); |
| 425 | 425 |
| 426 return InnerArrayFind(predicate, thisArg, this, length); | 426 return InnerArrayFind(predicate, thisArg, this, length); |
| 427 } | 427 } |
| 428 %FunctionSetLength(TypedArrayFind, 1); | 428 %FunctionSetLength(TypedArrayFind, 1); |
| 429 | 429 |
| 430 | 430 |
| 431 // ES6 draft 07-15-13, section 22.2.3.11 | 431 // ES6 draft 07-15-13, section 22.2.3.11 |
| 432 function TypedArrayFindIndex(predicate, thisArg) { | 432 function TypedArrayFindIndex(predicate, thisArg) { |
| 433 ValidateTypedArray(this, "%TypedArray%.prototype.findIndex"); | 433 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 434 | 434 |
| 435 var length = %_TypedArrayGetLength(this); | 435 var length = %_TypedArrayGetLength(this); |
| 436 | 436 |
| 437 return InnerArrayFindIndex(predicate, thisArg, this, length); | 437 return InnerArrayFindIndex(predicate, thisArg, this, length); |
| 438 } | 438 } |
| 439 %FunctionSetLength(TypedArrayFindIndex, 1); | 439 %FunctionSetLength(TypedArrayFindIndex, 1); |
| 440 | 440 |
| 441 | 441 |
| 442 // ES6 draft 05-18-15, section 22.2.3.25 | 442 // ES6 draft 05-18-15, section 22.2.3.25 |
| 443 function TypedArraySort(comparefn) { | 443 function TypedArraySort(comparefn) { |
| 444 ValidateTypedArray(this, "%TypedArray%.prototype.sort"); | 444 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 445 | 445 |
| 446 var length = %_TypedArrayGetLength(this); | 446 var length = %_TypedArrayGetLength(this); |
| 447 | 447 |
| 448 if (IS_UNDEFINED(comparefn)) { | 448 if (IS_UNDEFINED(comparefn)) { |
| 449 return %TypedArraySortFast(this); | 449 return %TypedArraySortFast(this); |
| 450 } | 450 } |
| 451 | 451 |
| 452 return InnerArraySort(this, length, comparefn); | 452 return InnerArraySort(this, length, comparefn); |
| 453 } | 453 } |
| 454 | 454 |
| 455 | 455 |
| 456 // ES6 draft 07-15-13, section 22.2.3.18 | 456 // ES6 draft 07-15-13, section 22.2.3.18 |
| 457 function TypedArrayMap(f, thisArg) { | 457 function TypedArrayMap(f, thisArg) { |
| 458 ValidateTypedArray(this, "%TypedArray%.prototype.map"); | 458 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 459 | 459 |
| 460 var length = %_TypedArrayGetLength(this); | 460 var length = %_TypedArrayGetLength(this); |
| 461 var result = TypedArraySpeciesCreate(this, length); | 461 var result = TypedArraySpeciesCreate(this, length); |
| 462 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 462 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 463 for (var i = 0; i < length; i++) { | 463 for (var i = 0; i < length; i++) { |
| 464 var element = this[i]; | 464 var element = this[i]; |
| 465 result[i] = %_Call(f, thisArg, element, i, this); | 465 result[i] = %_Call(f, thisArg, element, i, this); |
| 466 } | 466 } |
| 467 return result; | 467 return result; |
| 468 } | 468 } |
| 469 %FunctionSetLength(TypedArrayMap, 1); | 469 %FunctionSetLength(TypedArrayMap, 1); |
| 470 | 470 |
| 471 function InnerTypedArraySome(f, receiver, array, length) { | 471 function InnerTypedArraySome(f, receiver, array, length) { |
| 472 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 472 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
| 473 | 473 |
| 474 for (var i = 0; i < length; i++) { | 474 for (var i = 0; i < length; i++) { |
| 475 if (i in array) { | 475 if (i in array) { |
| 476 var element = array[i]; | 476 var element = array[i]; |
| 477 if (%_Call(f, receiver, element, i, array)) return true; | 477 if (%_Call(f, receiver, element, i, array)) return true; |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 return false; | 480 return false; |
| 481 } | 481 } |
| 482 | 482 |
| 483 // ES6 draft 05-05-15, section 22.2.3.24 | 483 // ES6 draft 05-05-15, section 22.2.3.24 |
| 484 function TypedArraySome(f, receiver) { | 484 function TypedArraySome(f, receiver) { |
| 485 ValidateTypedArray(this, "%TypedArray%.prototype.some"); | 485 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 486 | 486 |
| 487 var length = %_TypedArrayGetLength(this); | 487 var length = %_TypedArrayGetLength(this); |
| 488 | 488 |
| 489 return InnerTypedArraySome(f, receiver, this, length); | 489 return InnerTypedArraySome(f, receiver, this, length); |
| 490 } | 490 } |
| 491 %FunctionSetLength(TypedArraySome, 1); | 491 %FunctionSetLength(TypedArraySome, 1); |
| 492 | 492 |
| 493 | 493 |
| 494 // ES6 section 22.2.3.27 | 494 // ES6 section 22.2.3.27 |
| 495 function TypedArrayToLocaleString() { | 495 function TypedArrayToLocaleString() { |
| 496 ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString"); | 496 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 497 | 497 |
| 498 var length = %_TypedArrayGetLength(this); | 498 var length = %_TypedArrayGetLength(this); |
| 499 | 499 |
| 500 return InnerArrayToLocaleString(this, length); | 500 return InnerArrayToLocaleString(this, length); |
| 501 } | 501 } |
| 502 | 502 |
| 503 | 503 |
| 504 // ES6 section 22.2.3.14 | 504 // ES6 section 22.2.3.14 |
| 505 function TypedArrayJoin(separator) { | 505 function TypedArrayJoin(separator) { |
| 506 ValidateTypedArray(this, "%TypedArray%.prototype.join"); | 506 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 507 | 507 |
| 508 var length = %_TypedArrayGetLength(this); | 508 var length = %_TypedArrayGetLength(this); |
| 509 | 509 |
| 510 return InnerArrayJoin(separator, this, length); | 510 return InnerArrayJoin(separator, this, length); |
| 511 } | 511 } |
| 512 | 512 |
| 513 function InnerTypedArrayReduce( | 513 function InnerTypedArrayReduce( |
| 514 callback, current, array, length, argumentsLength) { | 514 callback, current, array, length, argumentsLength) { |
| 515 if (!IS_CALLABLE(callback)) { | 515 if (!IS_CALLABLE(callback)) { |
| 516 throw %make_type_error(kCalledNonCallable, callback); | 516 throw %make_type_error(kCalledNonCallable, callback); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 531 if (i in array) { | 531 if (i in array) { |
| 532 var element = array[i]; | 532 var element = array[i]; |
| 533 current = callback(current, element, i, array); | 533 current = callback(current, element, i, array); |
| 534 } | 534 } |
| 535 } | 535 } |
| 536 return current; | 536 return current; |
| 537 } | 537 } |
| 538 | 538 |
| 539 // ES6 draft 07-15-13, section 22.2.3.19 | 539 // ES6 draft 07-15-13, section 22.2.3.19 |
| 540 function TypedArrayReduce(callback, current) { | 540 function TypedArrayReduce(callback, current) { |
| 541 ValidateTypedArray(this, "%TypedArray%.prototype.reduce"); | 541 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 542 | 542 |
| 543 var length = %_TypedArrayGetLength(this); | 543 var length = %_TypedArrayGetLength(this); |
| 544 return InnerTypedArrayReduce( | 544 return InnerTypedArrayReduce( |
| 545 callback, current, this, length, arguments.length); | 545 callback, current, this, length, arguments.length); |
| 546 } | 546 } |
| 547 %FunctionSetLength(TypedArrayReduce, 1); | 547 %FunctionSetLength(TypedArrayReduce, 1); |
| 548 | 548 |
| 549 function InnerArrayReduceRight(callback, current, array, length, | 549 function InnerArrayReduceRight(callback, current, array, length, |
| 550 argumentsLength) { | 550 argumentsLength) { |
| 551 if (!IS_CALLABLE(callback)) { | 551 if (!IS_CALLABLE(callback)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 567 if (i in array) { | 567 if (i in array) { |
| 568 var element = array[i]; | 568 var element = array[i]; |
| 569 current = callback(current, element, i, array); | 569 current = callback(current, element, i, array); |
| 570 } | 570 } |
| 571 } | 571 } |
| 572 return current; | 572 return current; |
| 573 } | 573 } |
| 574 | 574 |
| 575 // ES6 draft 07-15-13, section 22.2.3.19 | 575 // ES6 draft 07-15-13, section 22.2.3.19 |
| 576 function TypedArrayReduceRight(callback, current) { | 576 function TypedArrayReduceRight(callback, current) { |
| 577 ValidateTypedArray(this, "%TypedArray%.prototype.reduceRight"); | 577 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 578 | 578 |
| 579 var length = %_TypedArrayGetLength(this); | 579 var length = %_TypedArrayGetLength(this); |
| 580 return InnerArrayReduceRight(callback, current, this, length, | 580 return InnerArrayReduceRight(callback, current, this, length, |
| 581 arguments.length); | 581 arguments.length); |
| 582 } | 582 } |
| 583 %FunctionSetLength(TypedArrayReduceRight, 1); | 583 %FunctionSetLength(TypedArrayReduceRight, 1); |
| 584 | 584 |
| 585 | 585 |
| 586 // ES6 draft 08-24-14, section 22.2.2.2 | 586 // ES6 draft 08-24-14, section 22.2.2.2 |
| 587 function TypedArrayOf() { | 587 function TypedArrayOf() { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 %AddNamedProperty(GlobalNAME.prototype, | 688 %AddNamedProperty(GlobalNAME.prototype, |
| 689 "constructor", global.NAME, DONT_ENUM); | 689 "constructor", global.NAME, DONT_ENUM); |
| 690 %AddNamedProperty(GlobalNAME.prototype, | 690 %AddNamedProperty(GlobalNAME.prototype, |
| 691 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 691 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 692 READ_ONLY | DONT_ENUM | DONT_DELETE); | 692 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 693 endmacro | 693 endmacro |
| 694 | 694 |
| 695 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 695 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 696 | 696 |
| 697 }) | 697 }) |
| OLD | NEW |