| // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| part of $LIBRARYNAME; |
| |
| $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| $!MEMBERS |
| @DomName('ArrayBuffer.slice') |
| ArrayBuffer slice(int begin, [int end]) { |
| // IE10 supports ArrayBuffers but does not have the slice method. |
| if (JS('bool', '!!#.slice', this)) { |
| if (?end) { |
| return JS('ArrayBuffer', '#.slice(#, #)', this, begin, end); |
| } |
| return JS('ArrayBuffer', '#.slice(#)', this, begin); |
| } else { |
| var start = begin; |
| // Negative values go from end. |
| if (start < 0) { |
| start = this.byteLength + start; |
| } |
| var finish = ?end ? min(end, byteLength) : byteLength; |
| if (finish < 0) { |
| finish = this.byteLength + finish; |
| } |
| var length = max(finish - start, 0); |
| |
| var clone = new Int8Array(length); |
| var source = new Int8Array.fromBuffer(this, start); |
| for (var i = 0; i < length; ++i) { |
| clone[i] = source[i]; |
| } |
| return clone.buffer; |
| } |
| } |
| } |