Skip to content

Commit

Permalink
Workaround minifier bug
Browse files Browse the repository at this point in the history
The function getStringByteSize() refers to an undefined variable in the
minified output. This works around this problem.

See babel/minify#430

Add a verify test for WebSocket.send() to make sure the private
getStringByteSize() can be called without an error being thrown.

Change-Id: I5513e53cc262d13fdc7434601c9557d0814655fc
  • Loading branch information
cpetrov authored and Gerrit Code Review committed Feb 20, 2017
1 parent 1ef9b35 commit 460f84f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tabris/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ Object.defineProperties(WebSocket.prototype, CONSTANTS);

function getStringByteSize(input) {
let len = 0;
// TODO: workaround for https://github.com/babel/babili/issues/430
if (!input.length) {
return 0;
}
for (let i = 0; i < input.length; i++) {
let code = input.charCodeAt(i);
if (code <= 0x7f) {
Expand Down
38 changes: 38 additions & 0 deletions test/tabris/WebSocket.verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const tabris = require('../../build/tabris/');
const chai = require('chai');
const expect = chai.expect;
const sinon = require('sinon');
const sandbox = sinon.sandbox.create();
const restore = sandbox.restore.bind(sandbox);
const stub = sandbox.stub.bind(sandbox);
const sinonChai = require('sinon-chai');

chai.use(sinonChai);

describe('WebSocket', function() {

let webSocket;
let client;

beforeEach(function() {
client = stub({
call: () => {},
create: () => {},
get: () => {},
listen: () => {}
});
tabris._init(client);
webSocket = new tabris.WebSocket('ws://url.com', 'chat-protocol');
});

afterEach(restore);

it('calls send with string data', function() {
tabris._notify(webSocket._proxy.cid, 'open', {});

webSocket.send('hello');

expect(client.call).to.have.been.calledWith(webSocket._proxy.cid, 'send', {data: 'hello'});
});

});

0 comments on commit 460f84f

Please # to comment.