Index: tools/dom/templates/html/dart2js/impl_ArrayBuffer.darttemplate |
diff --git a/tools/dom/templates/html/dart2js/impl_ArrayBuffer.darttemplate b/tools/dom/templates/html/dart2js/impl_ArrayBuffer.darttemplate |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ab440b0cac2e351761e0eb4ae4d2585aa0398018 |
--- /dev/null |
+++ b/tools/dom/templates/html/dart2js/impl_ArrayBuffer.darttemplate |
@@ -0,0 +1,38 @@ |
+// 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; |
+ |
+/// @domName $DOMNAME$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; |
+ } |
+ } |
+} |