[Spice-devel] [spice-html5 1/3] Extend the native ArrayBuffer to add a slice() method if missing.

Jeremy White jwhite at codeweavers.com
Fri Apr 19 11:13:28 PDT 2013


This allows IE10 to function.  Note that we would normally subclass
this type, but ArrayBuffer is implemented in native code, and so is
difficult to subclass.

Signed-off-by: Jeremy White <jwhite at codeweavers.com>
---
 spice.html          |    1 +
 spice_auto.html     |    1 +
 spicearraybuffer.js |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+)
 create mode 100644 spicearraybuffer.js

diff --git a/spice.html b/spice.html
index 469cfec..f20b585 100644
--- a/spice.html
+++ b/spice.html
@@ -28,6 +28,7 @@
     <head>
 
         <title>Spice Javascript client</title>
+        <script src="spicearraybuffer.js"></script> 
         <script src="enums.js"></script> 
         <script src="atKeynames.js"></script> 
         <script src="utils.js"></script> 
diff --git a/spice_auto.html b/spice_auto.html
index 5e4bedc..f51f96c 100644
--- a/spice_auto.html
+++ b/spice_auto.html
@@ -28,6 +28,7 @@
     <head>
 
         <title>Spice Javascript client</title>
+        <script src="spicearraybuffer.js"></script> 
         <script src="enums.js"></script>
         <script src="atKeynames.js"></script>
         <script src="utils.js"></script>
diff --git a/spicearraybuffer.js b/spicearraybuffer.js
new file mode 100644
index 0000000..228bce6
--- /dev/null
+++ b/spicearraybuffer.js
@@ -0,0 +1,58 @@
+"use strict";
+/*
+   Copyright (C) 2012 by Jeremy P. White <jwhite at codeweavers.com>
+
+   This file is part of spice-html5.
+
+   spice-html5 is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   spice-html5 is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with spice-html5.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*----------------------------------------------------------------------------
+**  SpiceArrayBufferSlice
+**    This function is a work around for IE 10, which has no slice()
+**    method in it's subclass.
+**--------------------------------------------------------------------------*/
+function SpiceArrayBufferSlice(start, end)
+{
+    start = start || 0;
+    end = end || this.byteLength;
+    if (end < 0)
+        end = this.byteLength + end;
+    if (start < 0)
+        start = this.byteLength + start;
+    if (start < 0)
+        start = 0;
+    if (end < 0)
+        end = 0;
+    if (end > this.byteLength)
+        end = this.byteLength;
+    if (start > end)
+        start = end;
+
+    var ret = new ArrayBuffer(end - start);
+    var in1 = new Uint8Array(this, start, end - start);
+    var out = new Uint8Array(ret);
+    var i;
+
+    for (i = 0; i < end - start; i++)
+        out[i] = in1[i];
+
+    return ret;
+}
+
+if (! ArrayBuffer.prototype.slice)
+{
+    ArrayBuffer.prototype.slice = SpiceArrayBufferSlice;
+    console.log("WARNING:  ArrayBuffer.slice() is missing; we are extending ArrayBuffer to compensate");
+}
-- 
1.7.10.4





More information about the Spice-devel mailing list