Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: src/js/typedarray.js

Issue 2778623003: [typedarrays] Check detached buffer at start of typed array methods (Closed)
Patch Set: crankshaft inline Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/crankshaft/hydrogen.cc ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
71 SpeciesConstructor = from.SpeciesConstructor; 69 SpeciesConstructor = from.SpeciesConstructor;
72 ToPositiveInteger = from.ToPositiveInteger; 70 ToPositiveInteger = from.ToPositiveInteger;
73 ToIndex = from.ToIndex; 71 ToIndex = from.ToIndex;
74 }); 72 });
75 73
76 // --------------- Typed Arrays --------------------- 74 // --------------- Typed Arrays ---------------------
77 75
76 function ValidateTypedArray(array, method) {
adamk 2017/03/30 18:58:32 Please add a comment making it clear that this is
adamk 2017/03/30 18:58:32 Nit: I'd prefer the name "methodName" instead of "
Choongwoo Han 2017/03/31 00:39:43 Done.
Choongwoo Han 2017/03/31 00:39:43 Done.
77 if (!IS_TYPEDARRAY(array)) throw %make_type_error(kNotTypedArray);
78
79 if (%_ArrayBufferViewWasNeutered(array))
80 throw %make_type_error(kDetachedOperation, method);
81 }
82
78 function TypedArrayDefaultConstructor(typedArray) { 83 function TypedArrayDefaultConstructor(typedArray) {
79 switch (%_ClassOf(typedArray)) { 84 switch (%_ClassOf(typedArray)) {
80 macro TYPED_ARRAY_CONSTRUCTOR_CASE(ARRAY_ID, NAME, ELEMENT_SIZE) 85 macro TYPED_ARRAY_CONSTRUCTOR_CASE(ARRAY_ID, NAME, ELEMENT_SIZE)
81 case "NAME": 86 case "NAME":
82 return GlobalNAME; 87 return GlobalNAME;
83 endmacro 88 endmacro
84 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR_CASE) 89 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR_CASE)
85 } 90 }
86 // The TypeError should not be generated since all callers should 91 // The TypeError should not be generated since all callers should
87 // have already called ValidateTypedArray. 92 // have already called ValidateTypedArray.
88 throw %make_type_error(kIncompatibleMethodReceiver, 93 throw %make_type_error(kIncompatibleMethodReceiver,
89 "TypedArrayDefaultConstructor", this); 94 "TypedArrayDefaultConstructor", this);
90 } 95 }
91 96
92 function TypedArrayCreate(constructor, arg0, arg1, arg2) { 97 function TypedArrayCreate(constructor, arg0, arg1, arg2) {
93 if (IS_UNDEFINED(arg1)) { 98 if (IS_UNDEFINED(arg1)) {
94 var newTypedArray = new constructor(arg0); 99 var newTypedArray = new constructor(arg0);
95 } else { 100 } else {
96 var newTypedArray = new constructor(arg0, arg1, arg2); 101 var newTypedArray = new constructor(arg0, arg1, arg2);
97 } 102 }
98 if (!IS_TYPEDARRAY(newTypedArray)) throw %make_type_error(kNotTypedArray); 103 ValidateTypedArray(newTypedArray, "TypedArrayCreate");
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) { 104 if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) {
103 throw %make_type_error(kTypedArrayTooShort); 105 throw %make_type_error(kTypedArrayTooShort);
104 } 106 }
105 return newTypedArray; 107 return newTypedArray;
106 } 108 }
107 109
108 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { 110 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) {
109 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); 111 var defaultConstructor = TypedArrayDefaultConstructor(exemplar);
110 var constructor = SpeciesConstructor(exemplar, defaultConstructor, 112 var constructor = SpeciesConstructor(exemplar, defaultConstructor);
111 conservative);
112 return TypedArrayCreate(constructor, arg0, arg1, arg2); 113 return TypedArrayCreate(constructor, arg0, arg1, arg2);
113 } 114 }
114 115
115 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) 116 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
116 function NAMEConstructByIterable(obj, iterable, iteratorFn) { 117 function NAMEConstructByIterable(obj, iterable, iteratorFn) {
117 var list = new InternalArray(); 118 var list = new InternalArray();
118 // Reading the Symbol.iterator property of iterable twice would be 119 // Reading the Symbol.iterator property of iterable twice would be
119 // observable with getters, so instead, we call the function which 120 // observable with getters, so instead, we call the function which
120 // was already looked up, and wrap it in another iterable. The 121 // 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 122 // __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
194 endInt = MinSimple(endInt, srcLength); 195 endInt = MinSimple(endInt, srcLength);
195 } 196 }
196 197
197 if (endInt < beginInt) { 198 if (endInt < beginInt) {
198 endInt = beginInt; 199 endInt = beginInt;
199 } 200 }
200 201
201 var newLength = endInt - beginInt; 202 var newLength = endInt - beginInt;
202 var beginByteOffset = 203 var beginByteOffset =
203 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; 204 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
204 // BUG(v8:4665): For web compatibility, subarray needs to always build an 205 return TypedArraySpeciesCreate(this, %TypedArrayGetBuffer(this),
205 // instance of the default constructor. 206 beginByteOffset, newLength);
206 // TODO(littledan): Switch to the standard or standardize the fix
207 return new GlobalNAME(%TypedArrayGetBuffer(this), beginByteOffset, newLength);
208 } 207 }
209 endmacro 208 endmacro
210 209
211 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) 210 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
212 211
213 function TypedArraySubArray(begin, end) { 212 function TypedArraySubArray(begin, end) {
214 switch (%_ClassOf(this)) { 213 switch (%_ClassOf(this)) {
215 macro TYPED_ARRAY_SUBARRAY_CASE(ARRAY_ID, NAME, ELEMENT_SIZE) 214 macro TYPED_ARRAY_SUBARRAY_CASE(ARRAY_ID, NAME, ELEMENT_SIZE)
216 case "NAME": 215 case "NAME":
217 return %_Call(NAMESubArray, this, begin, end); 216 return %_Call(NAMESubArray, this, begin, end);
218 endmacro 217 endmacro
219 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) 218 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE)
220 } 219 }
221 throw %make_type_error(kIncompatibleMethodReceiver, 220 throw %make_type_error(kIncompatibleMethodReceiver,
222 "get TypedArray.prototype.subarray", this); 221 "get %TypedArray%.prototype.subarray", this);
223 } 222 }
224 %SetForceInlineFlag(TypedArraySubArray); 223 %SetForceInlineFlag(TypedArraySubArray);
225 224
226 225
227 226
228 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { 227 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
229 if (offset > 0) { 228 if (offset > 0) {
230 for (var i = 0; i < sourceLength; i++) { 229 for (var i = 0; i < sourceLength; i++) {
231 target[offset + i] = source[i]; 230 target[offset + i] = source[i];
232 } 231 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (i in array) { 343 if (i in array) {
345 var element = array[i]; 344 var element = array[i];
346 if (!%_Call(f, receiver, element, i, array)) return false; 345 if (!%_Call(f, receiver, element, i, array)) return false;
347 } 346 }
348 } 347 }
349 return true; 348 return true;
350 } 349 }
351 350
352 // ES6 draft 05-05-15, section 22.2.3.7 351 // ES6 draft 05-05-15, section 22.2.3.7
353 function TypedArrayEvery(f, receiver) { 352 function TypedArrayEvery(f, receiver) {
354 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 353 ValidateTypedArray(this, "%TypedArray%.prototype.every");
355 354
356 var length = %_TypedArrayGetLength(this); 355 var length = %_TypedArrayGetLength(this);
357 356
358 return InnerTypedArrayEvery(f, receiver, this, length); 357 return InnerTypedArrayEvery(f, receiver, this, length);
359 } 358 }
360 %FunctionSetLength(TypedArrayEvery, 1); 359 %FunctionSetLength(TypedArrayEvery, 1);
361 360
362 function InnerTypedArrayForEach(f, receiver, array, length) { 361 function InnerTypedArrayForEach(f, receiver, array, length) {
363 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 362 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
364 363
365 if (IS_UNDEFINED(receiver)) { 364 if (IS_UNDEFINED(receiver)) {
366 for (var i = 0; i < length; i++) { 365 for (var i = 0; i < length; i++) {
367 if (i in array) { 366 if (i in array) {
368 var element = array[i]; 367 var element = array[i];
369 f(element, i, array); 368 f(element, i, array);
370 } 369 }
371 } 370 }
372 } else { 371 } else {
373 for (var i = 0; i < length; i++) { 372 for (var i = 0; i < length; i++) {
374 if (i in array) { 373 if (i in array) {
375 var element = array[i]; 374 var element = array[i];
376 %_Call(f, receiver, element, i, array); 375 %_Call(f, receiver, element, i, array);
377 } 376 }
378 } 377 }
379 } 378 }
380 } 379 }
381 380
382 // ES6 draft 08-24-14, section 22.2.3.12 381 // ES6 draft 08-24-14, section 22.2.3.12
383 function TypedArrayForEach(f, receiver) { 382 function TypedArrayForEach(f, receiver) {
384 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 383 ValidateTypedArray(this, "%TypedArray%.prototype.forEach");
385 384
386 var length = %_TypedArrayGetLength(this); 385 var length = %_TypedArrayGetLength(this);
387 386
388 InnerTypedArrayForEach(f, receiver, this, length); 387 InnerTypedArrayForEach(f, receiver, this, length);
389 } 388 }
390 %FunctionSetLength(TypedArrayForEach, 1); 389 %FunctionSetLength(TypedArrayForEach, 1);
391 390
392 391
393 // ES6 draft 07-15-13, section 22.2.3.9 392 // ES6 draft 07-15-13, section 22.2.3.9
394 function TypedArrayFilter(f, thisArg) { 393 function TypedArrayFilter(f, thisArg) {
395 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 394 ValidateTypedArray(this, "TypeArray.prototype.filter");
396 395
397 var length = %_TypedArrayGetLength(this); 396 var length = %_TypedArrayGetLength(this);
398 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 397 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
399 var result = new InternalArray(); 398 var result = new InternalArray();
400 InnerArrayFilter(f, thisArg, this, length, result); 399 InnerArrayFilter(f, thisArg, this, length, result);
401 var captured = result.length; 400 var captured = result.length;
402 var output = TypedArraySpeciesCreate(this, captured); 401 var output = TypedArraySpeciesCreate(this, captured);
403 for (var i = 0; i < captured; i++) { 402 for (var i = 0; i < captured; i++) {
404 output[i] = result[i]; 403 output[i] = result[i];
405 } 404 }
406 return output; 405 return output;
407 } 406 }
408 %FunctionSetLength(TypedArrayFilter, 1); 407 %FunctionSetLength(TypedArrayFilter, 1);
409 408
410 409
411 // ES6 draft 07-15-13, section 22.2.3.10 410 // ES6 draft 07-15-13, section 22.2.3.10
412 function TypedArrayFind(predicate, thisArg) { 411 function TypedArrayFind(predicate, thisArg) {
413 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 412 ValidateTypedArray(this, "%TypedArray%.prototype.find");
414 413
415 var length = %_TypedArrayGetLength(this); 414 var length = %_TypedArrayGetLength(this);
416 415
417 return InnerArrayFind(predicate, thisArg, this, length); 416 return InnerArrayFind(predicate, thisArg, this, length);
418 } 417 }
419 %FunctionSetLength(TypedArrayFind, 1); 418 %FunctionSetLength(TypedArrayFind, 1);
420 419
421 420
422 // ES6 draft 07-15-13, section 22.2.3.11 421 // ES6 draft 07-15-13, section 22.2.3.11
423 function TypedArrayFindIndex(predicate, thisArg) { 422 function TypedArrayFindIndex(predicate, thisArg) {
424 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 423 ValidateTypedArray(this, "%TypedArray%.prototype.findIndex");
425 424
426 var length = %_TypedArrayGetLength(this); 425 var length = %_TypedArrayGetLength(this);
427 426
428 return InnerArrayFindIndex(predicate, thisArg, this, length); 427 return InnerArrayFindIndex(predicate, thisArg, this, length);
429 } 428 }
430 %FunctionSetLength(TypedArrayFindIndex, 1); 429 %FunctionSetLength(TypedArrayFindIndex, 1);
431 430
432 431
433 // ES6 draft 05-18-15, section 22.2.3.25 432 // ES6 draft 05-18-15, section 22.2.3.25
434 function TypedArraySort(comparefn) { 433 function TypedArraySort(comparefn) {
435 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 434 ValidateTypedArray(this, "%TypedArray%.prototype.sort");
436 435
437 var length = %_TypedArrayGetLength(this); 436 var length = %_TypedArrayGetLength(this);
438 437
439 if (IS_UNDEFINED(comparefn)) { 438 if (IS_UNDEFINED(comparefn)) {
440 return %TypedArraySortFast(this); 439 return %TypedArraySortFast(this);
441 } 440 }
442 441
443 return InnerArraySort(this, length, comparefn); 442 return InnerArraySort(this, length, comparefn);
444 } 443 }
445 444
446 445
447 // ES6 draft 07-15-13, section 22.2.3.18 446 // ES6 draft 07-15-13, section 22.2.3.18
448 function TypedArrayMap(f, thisArg) { 447 function TypedArrayMap(f, thisArg) {
449 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 448 ValidateTypedArray(this, "%TypedArray%.prototype.map");
450 449
451 var length = %_TypedArrayGetLength(this); 450 var length = %_TypedArrayGetLength(this);
452 var result = TypedArraySpeciesCreate(this, length); 451 var result = TypedArraySpeciesCreate(this, length);
453 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 452 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
454 for (var i = 0; i < length; i++) { 453 for (var i = 0; i < length; i++) {
455 var element = this[i]; 454 var element = this[i];
456 result[i] = %_Call(f, thisArg, element, i, this); 455 result[i] = %_Call(f, thisArg, element, i, this);
457 } 456 }
458 return result; 457 return result;
459 } 458 }
460 %FunctionSetLength(TypedArrayMap, 1); 459 %FunctionSetLength(TypedArrayMap, 1);
461 460
462 function InnerTypedArraySome(f, receiver, array, length) { 461 function InnerTypedArraySome(f, receiver, array, length) {
463 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); 462 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
464 463
465 for (var i = 0; i < length; i++) { 464 for (var i = 0; i < length; i++) {
466 if (i in array) { 465 if (i in array) {
467 var element = array[i]; 466 var element = array[i];
468 if (%_Call(f, receiver, element, i, array)) return true; 467 if (%_Call(f, receiver, element, i, array)) return true;
469 } 468 }
470 } 469 }
471 return false; 470 return false;
472 } 471 }
473 472
474 // ES6 draft 05-05-15, section 22.2.3.24 473 // ES6 draft 05-05-15, section 22.2.3.24
475 function TypedArraySome(f, receiver) { 474 function TypedArraySome(f, receiver) {
476 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 475 ValidateTypedArray(this, "%TypedArray%.prototype.some");
477 476
478 var length = %_TypedArrayGetLength(this); 477 var length = %_TypedArrayGetLength(this);
479 478
480 return InnerTypedArraySome(f, receiver, this, length); 479 return InnerTypedArraySome(f, receiver, this, length);
481 } 480 }
482 %FunctionSetLength(TypedArraySome, 1); 481 %FunctionSetLength(TypedArraySome, 1);
483 482
484 483
485 // ES6 section 22.2.3.27 484 // ES6 section 22.2.3.27
486 function TypedArrayToLocaleString() { 485 function TypedArrayToLocaleString() {
487 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 486 ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString");
488 487
489 var length = %_TypedArrayGetLength(this); 488 var length = %_TypedArrayGetLength(this);
490 489
491 return InnerArrayToLocaleString(this, length); 490 return InnerArrayToLocaleString(this, length);
492 } 491 }
493 492
494 493
495 // ES6 section 22.2.3.14 494 // ES6 section 22.2.3.14
496 function TypedArrayJoin(separator) { 495 function TypedArrayJoin(separator) {
497 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 496 ValidateTypedArray(this, "%TypedArray%.prototype.join");
498 497
499 var length = %_TypedArrayGetLength(this); 498 var length = %_TypedArrayGetLength(this);
500 499
501 return InnerArrayJoin(separator, this, length); 500 return InnerArrayJoin(separator, this, length);
502 } 501 }
503 502
504 function InnerTypedArrayReduce( 503 function InnerTypedArrayReduce(
505 callback, current, array, length, argumentsLength) { 504 callback, current, array, length, argumentsLength) {
506 if (!IS_CALLABLE(callback)) { 505 if (!IS_CALLABLE(callback)) {
507 throw %make_type_error(kCalledNonCallable, callback); 506 throw %make_type_error(kCalledNonCallable, callback);
(...skipping 14 matching lines...) Expand all
522 if (i in array) { 521 if (i in array) {
523 var element = array[i]; 522 var element = array[i];
524 current = callback(current, element, i, array); 523 current = callback(current, element, i, array);
525 } 524 }
526 } 525 }
527 return current; 526 return current;
528 } 527 }
529 528
530 // ES6 draft 07-15-13, section 22.2.3.19 529 // ES6 draft 07-15-13, section 22.2.3.19
531 function TypedArrayReduce(callback, current) { 530 function TypedArrayReduce(callback, current) {
532 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 531 ValidateTypedArray(this, "%TypedArray%.prototype.reduce");
533 532
534 var length = %_TypedArrayGetLength(this); 533 var length = %_TypedArrayGetLength(this);
535 return InnerTypedArrayReduce( 534 return InnerTypedArrayReduce(
536 callback, current, this, length, arguments.length); 535 callback, current, this, length, arguments.length);
537 } 536 }
538 %FunctionSetLength(TypedArrayReduce, 1); 537 %FunctionSetLength(TypedArrayReduce, 1);
539 538
540 function InnerArrayReduceRight(callback, current, array, length, 539 function InnerArrayReduceRight(callback, current, array, length,
541 argumentsLength) { 540 argumentsLength) {
542 if (!IS_CALLABLE(callback)) { 541 if (!IS_CALLABLE(callback)) {
(...skipping 15 matching lines...) Expand all
558 if (i in array) { 557 if (i in array) {
559 var element = array[i]; 558 var element = array[i];
560 current = callback(current, element, i, array); 559 current = callback(current, element, i, array);
561 } 560 }
562 } 561 }
563 return current; 562 return current;
564 } 563 }
565 564
566 // ES6 draft 07-15-13, section 22.2.3.19 565 // ES6 draft 07-15-13, section 22.2.3.19
567 function TypedArrayReduceRight(callback, current) { 566 function TypedArrayReduceRight(callback, current) {
568 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 567 ValidateTypedArray(this, "%TypedArray%.prototype.reduceRight");
569 568
570 var length = %_TypedArrayGetLength(this); 569 var length = %_TypedArrayGetLength(this);
571 return InnerArrayReduceRight(callback, current, this, length, 570 return InnerArrayReduceRight(callback, current, this, length,
572 arguments.length); 571 arguments.length);
573 } 572 }
574 %FunctionSetLength(TypedArrayReduceRight, 1); 573 %FunctionSetLength(TypedArrayReduceRight, 1);
575 574
576 575
577 function TypedArraySlice(start, end) { 576 function TypedArraySlice(start, end) {
578 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 577 ValidateTypedArray(this, "%TypedArray%.prototype.slice");
578
579 var len = %_TypedArrayGetLength(this); 579 var len = %_TypedArrayGetLength(this);
580 580
581 var relativeStart = TO_INTEGER(start); 581 var relativeStart = TO_INTEGER(start);
582 582
583 var k; 583 var k;
584 if (relativeStart < 0) { 584 if (relativeStart < 0) {
585 k = MaxSimple(len + relativeStart, 0); 585 k = MaxSimple(len + relativeStart, 0);
586 } else { 586 } else {
587 k = MinSimple(relativeStart, len); 587 k = MinSimple(relativeStart, len);
588 } 588 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 %AddNamedProperty(GlobalNAME.prototype, 723 %AddNamedProperty(GlobalNAME.prototype,
724 "constructor", global.NAME, DONT_ENUM); 724 "constructor", global.NAME, DONT_ENUM);
725 %AddNamedProperty(GlobalNAME.prototype, 725 %AddNamedProperty(GlobalNAME.prototype,
726 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 726 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
727 READ_ONLY | DONT_ENUM | DONT_DELETE); 727 READ_ONLY | DONT_ENUM | DONT_DELETE);
728 endmacro 728 endmacro
729 729
730 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 730 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
731 731
732 }) 732 })
OLDNEW
« no previous file with comments | « src/crankshaft/hydrogen.cc ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698