From 006dbd470471ee953bdef4904f629f8001f3edec 2014-10-15 19:23:32 From: MinRK Date: 2014-10-15 19:23:32 Subject: [PATCH] use TextEncoding for string<->ArrayBuffer requires text-encoding js polyfill, for now --- diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index e01c0bd..9ad4fcb 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -5,10 +5,10 @@ define([ 'base/js/namespace', 'jquery', 'base/js/utils', - 'services/kernels/js/comm', - 'widgets/js/init', - './serialize' -], function(IPython, $, utils, comm, widgetmanager, serialize) { + './comm', + './serialize', + 'widgets/js/init' +], function(IPython, $, utils, comm, serialize, widgetmanager) { "use strict"; /** diff --git a/IPython/html/static/services/kernels/js/serialize.js b/IPython/html/static/services/kernels/js/serialize.js index a43bab0..89bde06 100644 --- a/IPython/html/static/services/kernels/js/serialize.js +++ b/IPython/html/static/services/kernels/js/serialize.js @@ -3,7 +3,6 @@ define([ 'jquery', - 'components/utf8/utf8' ], function ($, utf8) { "use strict"; @@ -16,14 +15,9 @@ define([ for (i = 1; i <= nbufs; i++) { offsets.push(data.getInt32(i * 4)); } - // have to convert array to string for utf8.js - var bytestring = String.fromCharCode.apply(null, - new Uint8Array(buf.slice(offsets[0], offsets[1])) - ); + var json_bytes = new Uint8Array(buf.slice(offsets[0], offsets[1])); var msg = $.parseJSON( - utf8.decode( - bytestring - ) + (new TextDecoder('utf8')).decode(json_bytes) ); // the remaining chunks are stored as DataViews in msg.buffers msg.buffers = []; @@ -66,16 +60,6 @@ define([ } }; - var _bytes2buf = function (bytestring) { - // convert bytestring to UInt8Array - var nbytes = bytestring.length; - var buf = new Uint8Array(nbytes); - for (var i = 0; i < nbytes; i++) { - buf[i] = bytestring.charCodeAt(i); - } - return buf; - }; - var _serialize_binary = function (msg) { // implement the binary serialization protocol // serializes JSON message to ArrayBuffer @@ -83,7 +67,7 @@ define([ var offsets = []; var buffers = msg.buffers; delete msg.buffers; - var json_utf8 = _bytes2buf(utf8.encode(JSON.stringify(msg))); + var json_utf8 = (new TextEncoder('utf8')).encode(JSON.stringify(msg)); buffers.unshift(json_utf8); var nbufs = buffers.length; offsets.push(4 * (nbufs + 1)); @@ -112,7 +96,6 @@ define([ }; var serialize = function (msg) { - console.log(msg.buffers, msg.buffers.length); if (msg.buffers && msg.buffers.length) { return _serialize_binary(msg); } else { diff --git a/IPython/html/templates/notebook.html b/IPython/html/templates/notebook.html index 86949ef..52e5928 100644 --- a/IPython/html/templates/notebook.html +++ b/IPython/html/templates/notebook.html @@ -311,6 +311,7 @@ class="notebook_app" {% block script %} {{super()}} +