forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_legacy.js
40 lines (36 loc) · 1.28 KB
/
library_legacy.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
/**
* @license
* Copyright 2010 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
mergeInto(LibraryManager.library, {
$ALLOC_NORMAL: 0, // Tries to use _malloc()
$ALLOC_STACK: 1, // Lives for the duration of the current function call
/**
* allocate(): This function is no longer used by emscripten but is kept around to avoid
* breaking external users.
* You should normally not use allocate(), and instead allocate
* memory using _malloc()/stackAlloc(), initialize it with
* setValue(), and so forth.
* @param {(Uint8Array|Array<number>)} slab: An array of data.
* @param {number=} allocator : How to allocate memory, see ALLOC_*
*/
$allocate__deps: ['$ALLOC_NORMAL', '$ALLOC_STACK'],
$allocate: function(slab, allocator) {
var ret;
#if ASSERTIONS
assert(typeof allocator == 'number', 'allocate no longer takes a type argument')
assert(typeof slab != 'number', 'allocate no longer takes a number as arg0')
#endif
if (allocator == ALLOC_STACK) {
ret = stackAlloc(slab.length);
} else {
ret = {{{ makeMalloc('allocate', 'slab.length') }}};
}
if (!slab.subarray && !slab.slice) {
slab = new Uint8Array(slab);
}
HEAPU8.set(slab, ret);
return ret;
},
});