| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /// @domName $DOMNAME$ANNOTATIONS | 7 $ANNOTATIONS |
| 8 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 8 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 9 $!MEMBERS | 9 $!MEMBERS |
| 10 /// @domName ArrayBuffer.slice; | 10 @DomName('ArrayBuffer.slice') |
| 11 ArrayBuffer slice(int begin, [int end]) { | 11 ArrayBuffer slice(int begin, [int end]) { |
| 12 // IE10 supports ArrayBuffers but does not have the slice method. | 12 // IE10 supports ArrayBuffers but does not have the slice method. |
| 13 if (JS('bool', '!!#.slice', this)) { | 13 if (JS('bool', '!!#.slice', this)) { |
| 14 if (?end) { | 14 if (?end) { |
| 15 return JS('ArrayBuffer', '#.slice(#, #)', this, begin, end); | 15 return JS('ArrayBuffer', '#.slice(#, #)', this, begin, end); |
| 16 } | 16 } |
| 17 return JS('ArrayBuffer', '#.slice(#)', this, begin); | 17 return JS('ArrayBuffer', '#.slice(#)', this, begin); |
| 18 } else { | 18 } else { |
| 19 var start = begin; | 19 var start = begin; |
| 20 // Negative values go from end. | 20 // Negative values go from end. |
| 21 if (start < 0) { | 21 if (start < 0) { |
| 22 start = this.byteLength + start; | 22 start = this.byteLength + start; |
| 23 } | 23 } |
| 24 var finish = ?end ? min(end, byteLength) : byteLength; | 24 var finish = ?end ? min(end, byteLength) : byteLength; |
| 25 if (finish < 0) { | 25 if (finish < 0) { |
| 26 finish = this.byteLength + finish; | 26 finish = this.byteLength + finish; |
| 27 } | 27 } |
| 28 var length = max(finish - start, 0); | 28 var length = max(finish - start, 0); |
| 29 | 29 |
| 30 var clone = new Int8Array(length); | 30 var clone = new Int8Array(length); |
| 31 var source = new Int8Array.fromBuffer(this, start); | 31 var source = new Int8Array.fromBuffer(this, start); |
| 32 for (var i = 0; i < length; ++i) { | 32 for (var i = 0; i < length; ++i) { |
| 33 clone[i] = source[i]; | 33 clone[i] = source[i]; |
| 34 } | 34 } |
| 35 return clone.buffer; | 35 return clone.buffer; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 } | 38 } |
| OLD | NEW |