049efc4fe8
This is an update of https://codereview.chromium.org/11968047/ BUG= Review URL: https://codereview.chromium.org//12024002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17323 260f80e4-7a28-3924-810f-c04153c831b5
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
// 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;
|
|
}
|
|
}
|
|
}
|