1- /**
2- * TextEncoder polyfill for IE
3- */
4- if ( typeof TextEncoder === "undefined" ) {
5- TextEncoder = function TextEncoder ( ) { } ;
6- TextEncoder . prototype . encode = function encode ( str ) {
7- "use strict" ;
8- var Len = str . length , resPos = - 1 ;
9- // The Uint8Array's length must be at least 3x the length of the string because an invalid UTF-16
10- // takes up the equivelent space of 3 UTF-8 characters to encode it properly. However, Array's
11- // have an auto expanding length and 1.5x should be just the right balance for most uses.
12- var resArr = typeof Uint8Array === "undefined" ? new Array ( Len * 1.5 ) : new Uint8Array ( Len * 3 ) ;
13- for ( var point = 0 , nextcode = 0 , i = 0 ; i !== Len ; ) {
14- point = str . charCodeAt ( i ) , i += 1 ;
15- if ( point >= 0xD800 && point <= 0xDBFF ) {
16- if ( i === Len ) {
17- resArr [ resPos += 1 ] = 0xef /*0b11101111*/ ; resArr [ resPos += 1 ] = 0xbf /*0b10111111*/ ;
18- resArr [ resPos += 1 ] = 0xbd /*0b10111101*/ ; break ;
19- }
20- // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
21- nextcode = str . charCodeAt ( i ) ;
22- if ( nextcode >= 0xDC00 && nextcode <= 0xDFFF ) {
23- point = ( point - 0xD800 ) * 0x400 + nextcode - 0xDC00 + 0x10000 ;
24- i += 1 ;
25- if ( point > 0xffff ) {
26- resArr [ resPos += 1 ] = ( 0x1e /*0b11110*/ << 3 ) | ( point >>> 18 ) ;
27- resArr [ resPos += 1 ] = ( 0x2 /*0b10*/ << 6 ) | ( ( point >>> 12 ) & 0x3f /*0b00111111*/ ) ;
28- resArr [ resPos += 1 ] = ( 0x2 /*0b10*/ << 6 ) | ( ( point >>> 6 ) & 0x3f /*0b00111111*/ ) ;
29- resArr [ resPos += 1 ] = ( 0x2 /*0b10*/ << 6 ) | ( point & 0x3f /*0b00111111*/ ) ;
30- continue ;
31- }
32- } else {
33- resArr [ resPos += 1 ] = 0xef /*0b11101111*/ ; resArr [ resPos += 1 ] = 0xbf /*0b10111111*/ ;
34- resArr [ resPos += 1 ] = 0xbd /*0b10111101*/ ; continue ;
35- }
36- }
37- if ( point <= 0x007f ) {
38- resArr [ resPos += 1 ] = ( 0x0 /*0b0*/ << 7 ) | point ;
39- } else if ( point <= 0x07ff ) {
40- resArr [ resPos += 1 ] = ( 0x6 /*0b110*/ << 5 ) | ( point >>> 6 ) ;
41- resArr [ resPos += 1 ] = ( 0x2 /*0b10*/ << 6 ) | ( point & 0x3f /*0b00111111*/ ) ;
42- } else {
43- resArr [ resPos += 1 ] = ( 0xe /*0b1110*/ << 4 ) | ( point >>> 12 ) ;
44- resArr [ resPos += 1 ] = ( 0x2 /*0b10*/ << 6 ) | ( ( point >>> 6 ) & 0x3f /*0b00111111*/ ) ;
45- resArr [ resPos += 1 ] = ( 0x2 /*0b10*/ << 6 ) | ( point & 0x3f /*0b00111111*/ ) ;
46- }
47- }
48- if ( typeof Uint8Array !== "undefined" ) return resArr . subarray ( 0 , resPos + 1 ) ;
49- // else // IE 6-9
50- resArr . length = resPos + 1 ; // trim off extra weight
51- return resArr ;
52- } ;
53- TextEncoder . prototype . toString = function ( ) { return "[object TextEncoder]" } ;
54- try { // Object.defineProperty only works on DOM prototypes in IE8
55- Object . defineProperty ( TextEncoder . prototype , "encoding" , {
56- get :function ( ) { if ( TextEncoder . prototype . isPrototypeOf ( this ) ) return "utf-8" ;
57- else throw TypeError ( "Illegal invocation" ) ; }
58- } ) ;
59- } catch ( e ) { /*IE6-8 fallback*/ TextEncoder . prototype . encoding = "utf-8" ; }
60- if ( typeof Symbol !== "undefined" ) TextEncoder . prototype [ Symbol . toStringTag ] = "TextEncoder" ;
61- }
621
632var LibraryWebSocket = {
643 $webSocketState : {
@@ -211,7 +150,7 @@ var LibraryWebSocket = {
211150 console . log ( "[JSLIB WebSocket] Connected." ) ;
212151
213152 if ( webSocketState . onOpen )
214- Runtime . dynCall ( 'vi' , webSocketState . onOpen , [ instanceId ] ) ;
153+ Module . dynCall_vi ( webSocketState . onOpen , instanceId ) ;
215154
216155 } ;
217156
@@ -231,7 +170,7 @@ var LibraryWebSocket = {
231170 HEAPU8 . set ( dataBuffer , buffer ) ;
232171
233172 try {
234- Runtime . dynCall ( 'viii' , webSocketState . onMessage , [ instanceId , buffer , dataBuffer . length ] ) ;
173+ Module . dynCall_viii ( webSocketState . onMessage , instanceId , buffer , dataBuffer . length ) ;
235174 } finally {
236175 _free ( buffer ) ;
237176 }
@@ -243,7 +182,7 @@ var LibraryWebSocket = {
243182 HEAPU8 . set ( dataBuffer , buffer ) ;
244183
245184 try {
246- Runtime . dynCall ( 'viii' , webSocketState . onMessage , [ instanceId , buffer , dataBuffer . length ] ) ;
185+ Module . dynCall_viii ( webSocketState . onMessage , instanceId , buffer , dataBuffer . length ) ;
247186 } finally {
248187 _free ( buffer ) ;
249188 }
@@ -265,7 +204,7 @@ var LibraryWebSocket = {
265204 stringToUTF8 ( msg , msgBuffer , msgBytes ) ;
266205
267206 try {
268- Runtime . dynCall ( 'vii' , webSocketState . onError , [ instanceId , msgBuffer ] ) ;
207+ Module . dynCall_vii ( webSocketState . onError , instanceId , msgBuffer ) ;
269208 } finally {
270209 _free ( msgBuffer ) ;
271210 }
@@ -280,7 +219,7 @@ var LibraryWebSocket = {
280219 console . log ( "[JSLIB WebSocket] Closed." ) ;
281220
282221 if ( webSocketState . onClose )
283- Runtime . dynCall ( 'vii' , webSocketState . onClose , [ instanceId , ev . code ] ) ;
222+ Module . dynCall_vii ( webSocketState . onClose , instanceId , ev . code ) ;
284223
285224 delete instance . ws ;
286225
0 commit comments