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

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

Issue 2091153002: TypedArray.prototype.set uses internal length property, not real one. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: shorter lines Created 4 years, 6 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 | « no previous file | test/mjsunit/es6/typedarray-set-length-internal.js » ('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
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 else { 342 else {
343 for (var i = 0; i < sourceLength; i++) { 343 for (var i = 0; i < sourceLength; i++) {
344 target[i] = source[i]; 344 target[i] = source[i];
345 } 345 }
346 } 346 }
347 } 347 }
348 348
349 function TypedArraySetFromOverlappingTypedArray(target, source, offset) { 349 function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
350 var sourceElementSize = source.BYTES_PER_ELEMENT; 350 var sourceElementSize = source.BYTES_PER_ELEMENT;
351 var targetElementSize = target.BYTES_PER_ELEMENT; 351 var targetElementSize = target.BYTES_PER_ELEMENT;
352 var sourceLength = source.length; 352 var sourceLength = %_TypedArrayGetLength(source);
353 353
354 // Copy left part. 354 // Copy left part.
355 function CopyLeftPart() { 355 function CopyLeftPart() {
356 // First un-mutated byte after the next write 356 // First un-mutated byte after the next write
357 var targetPtr = target.byteOffset + (offset + 1) * targetElementSize; 357 var targetPtr = target.byteOffset + (offset + 1) * targetElementSize;
358 // Next read at sourcePtr. We do not care for memory changing before 358 // Next read at sourcePtr. We do not care for memory changing before
359 // sourcePtr - we have already copied it. 359 // sourcePtr - we have already copied it.
360 var sourcePtr = source.byteOffset; 360 var sourcePtr = source.byteOffset;
361 for (var leftIndex = 0; 361 for (var leftIndex = 0;
362 leftIndex < sourceLength && targetPtr <= sourcePtr; 362 leftIndex < sourceLength && targetPtr <= sourcePtr;
363 leftIndex++) { 363 leftIndex++) {
364 target[offset + leftIndex] = source[leftIndex]; 364 target[offset + leftIndex] = source[leftIndex];
365 targetPtr += targetElementSize; 365 targetPtr += targetElementSize;
366 sourcePtr += sourceElementSize; 366 sourcePtr += sourceElementSize;
367 } 367 }
368 return leftIndex; 368 return leftIndex;
369 } 369 }
370 var leftIndex = CopyLeftPart(); 370 var leftIndex = CopyLeftPart();
371 371
372 // Copy rigth part; 372 // Copy right part;
373 function CopyRightPart() { 373 function CopyRightPart() {
374 // First unmutated byte before the next write 374 // First unmutated byte before the next write
375 var targetPtr = 375 var targetPtr =
376 target.byteOffset + (offset + sourceLength - 1) * targetElementSize; 376 target.byteOffset + (offset + sourceLength - 1) * targetElementSize;
377 // Next read before sourcePtr. We do not care for memory changing after 377 // Next read before sourcePtr. We do not care for memory changing after
378 // sourcePtr - we have already copied it. 378 // sourcePtr - we have already copied it.
379 var sourcePtr = 379 var sourcePtr =
380 source.byteOffset + sourceLength * sourceElementSize; 380 source.byteOffset + sourceLength * sourceElementSize;
381 for(var rightIndex = sourceLength - 1; 381 for(var rightIndex = sourceLength - 1;
382 rightIndex >= leftIndex && targetPtr >= sourcePtr; 382 rightIndex >= leftIndex && targetPtr >= sourcePtr;
(...skipping 23 matching lines...) Expand all
406 throw MakeRangeError(kTypedArraySetSourceTooLarge); 406 throw MakeRangeError(kTypedArraySetSourceTooLarge);
407 } 407 }
408 switch (%TypedArraySetFastCases(this, obj, intOffset)) { 408 switch (%TypedArraySetFastCases(this, obj, intOffset)) {
409 // These numbers should be synchronized with runtime.cc. 409 // These numbers should be synchronized with runtime.cc.
410 case 0: // TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE 410 case 0: // TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE
411 return; 411 return;
412 case 1: // TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING 412 case 1: // TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING
413 TypedArraySetFromOverlappingTypedArray(this, obj, intOffset); 413 TypedArraySetFromOverlappingTypedArray(this, obj, intOffset);
414 return; 414 return;
415 case 2: // TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING 415 case 2: // TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING
416 TypedArraySetFromArrayLike(this, obj, obj.length, intOffset); 416 TypedArraySetFromArrayLike(this,
417 obj, %_TypedArrayGetLength(obj), intOffset);
417 return; 418 return;
418 case 3: // TYPED_ARRAY_SET_NON_TYPED_ARRAY 419 case 3: // TYPED_ARRAY_SET_NON_TYPED_ARRAY
419 var l = obj.length; 420 var l = obj.length;
420 if (IS_UNDEFINED(l)) { 421 if (IS_UNDEFINED(l)) {
421 if (IS_NUMBER(obj)) { 422 if (IS_NUMBER(obj)) {
422 // For number as a first argument, throw TypeError 423 // For number as a first argument, throw TypeError
423 // instead of silently ignoring the call, so that 424 // instead of silently ignoring the call, so that
424 // the user knows (s)he did something wrong. 425 // the user knows (s)he did something wrong.
425 // (Consistent with Firefox and Blink/WebKit) 426 // (Consistent with Firefox and Blink/WebKit)
426 throw MakeTypeError(kInvalidArgument); 427 throw MakeTypeError(kInvalidArgument);
427 } 428 }
428 return; 429 return;
429 } 430 }
430 l = TO_LENGTH(l); 431 l = TO_LENGTH(l);
431 if (intOffset + l > this.length) { 432 if (intOffset + l > %_TypedArrayGetLength(this)) {
432 throw MakeRangeError(kTypedArraySetSourceTooLarge); 433 throw MakeRangeError(kTypedArraySetSourceTooLarge);
433 } 434 }
434 TypedArraySetFromArrayLike(this, obj, l, intOffset); 435 TypedArraySetFromArrayLike(this, obj, l, intOffset);
435 return; 436 return;
436 } 437 }
437 } 438 }
438 %FunctionSetLength(TypedArraySet, 1); 439 %FunctionSetLength(TypedArraySet, 1);
439 440
440 function TypedArrayGetToStringTag() { 441 function TypedArrayGetToStringTag() {
441 if (!IS_TYPEDARRAY(this)) return; 442 if (!IS_TYPEDARRAY(this)) return;
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 "setUint32", DataViewSetUint32JS, 900 "setUint32", DataViewSetUint32JS,
900 901
901 "getFloat32", DataViewGetFloat32JS, 902 "getFloat32", DataViewGetFloat32JS,
902 "setFloat32", DataViewSetFloat32JS, 903 "setFloat32", DataViewSetFloat32JS,
903 904
904 "getFloat64", DataViewGetFloat64JS, 905 "getFloat64", DataViewGetFloat64JS,
905 "setFloat64", DataViewSetFloat64JS 906 "setFloat64", DataViewSetFloat64JS
906 ]); 907 ]);
907 908
908 }) 909 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/typedarray-set-length-internal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698