(slab, types, allocator, ptr)
| 563 | // ignored. |
| 564 | // @allocator: How to allocate memory, see ALLOC_* |
| 565 | function allocate(slab, types, allocator, ptr) { |
| 566 | var zeroinit, size; |
| 567 | if (typeof slab === 'number') { |
| 568 | zeroinit = true; |
| 569 | size = slab; |
| 570 | } else { |
| 571 | zeroinit = false; |
| 572 | size = slab.length; |
| 573 | } |
| 574 | |
| 575 | var singleType = typeof types === 'string' ? types : null; |
| 576 | |
| 577 | var ret; |
| 578 | if (allocator == ALLOC_NONE) { |
| 579 | ret = ptr; |
| 580 | } else { |
| 581 | ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc, Runtime.dynamicAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length)); |
| 582 | } |
| 583 | |
| 584 | if (zeroinit) { |
| 585 | var ptr = ret, stop; |
| 586 | assert((ret & 3) == 0); |
| 587 | stop = ret + (size & ~3); |
| 588 | for (; ptr < stop; ptr += 4) { |
| 589 | HEAP32[((ptr)>>2)]=0; |
| 590 | } |
| 591 | stop = ret + size; |
| 592 | while (ptr < stop) { |
| 593 | HEAP8[((ptr++)>>0)]=0; |
| 594 | } |
| 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | if (singleType === 'i8') { |
| 599 | if (slab.subarray || slab.slice) { |
| 600 | HEAPU8.set(slab, ret); |
| 601 | } else { |
| 602 | HEAPU8.set(new Uint8Array(slab), ret); |
| 603 | } |
| 604 | return ret; |
| 605 | } |
| 606 | |
| 607 | var i = 0, type, typeSize, previousType; |
| 608 | while (i < size) { |
| 609 | var curr = slab[i]; |
| 610 | |
| 611 | if (typeof curr === 'function') { |
| 612 | curr = Runtime.getFunctionIndex(curr); |
| 613 | } |
| 614 | |
| 615 | type = singleType || types[i]; |
| 616 | if (type === 0) { |
| 617 | i++; |
| 618 | continue; |
| 619 | } |
| 620 | |
| 621 | if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later |
| 622 |
no test coverage detected