-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathruntime_wasm.js
47 lines (42 loc) · 1.48 KB
/
runtime_wasm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Module.STDWEB_PRIVATE.alloc = function alloc( size ) {
return Module.web_malloc( size );
};
Module.STDWEB_PRIVATE.dyncall = function( signature, ptr, args ) {
return Module.web_table.get( ptr ).apply( null, args );
};
// This is based on code from Emscripten's preamble.js.
Module.STDWEB_PRIVATE.utf8_len = function utf8_len( str ) {
var len = 0;
for( var i = 0; i < str.length; ++i ) {
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
// See http://unicode.org/faq/utf_bom.html#utf16-3
var u = str.charCodeAt( i ); // possibly a lead surrogate
if( u >= 0xD800 && u <= 0xDFFF ) {
u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt( ++i ) & 0x3FF);
}
if( u <= 0x7F ) {
++len;
} else if( u <= 0x7FF ) {
len += 2;
} else if( u <= 0xFFFF ) {
len += 3;
} else if( u <= 0x1FFFFF ) {
len += 4;
} else if( u <= 0x3FFFFFF ) {
len += 5;
} else {
len += 6;
}
}
return len;
};
Module.STDWEB_PRIVATE.prepare_any_arg = function( value ) {
var arg = Module.STDWEB_PRIVATE.alloc( 16 );
Module.STDWEB_PRIVATE.from_js( arg, value );
return arg;
};
Module.STDWEB_PRIVATE.acquire_tmp = function( dummy ) {
var value = Module.STDWEB_PRIVATE.tmp;
Module.STDWEB_PRIVATE.tmp = null;
return value;
};