(type)
| 1579 | nextTypeIndex() { return this.types.length; } |
| 1580 | |
| 1581 | static defaultFor(type) { |
| 1582 | switch (type) { |
| 1583 | case kWasmI32: |
| 1584 | return wasmI32Const(0); |
| 1585 | case kWasmI64: |
| 1586 | return wasmI64Const(0); |
| 1587 | case kWasmF32: |
| 1588 | return wasmF32Const(0.0); |
| 1589 | case kWasmF64: |
| 1590 | return wasmF64Const(0.0); |
| 1591 | case kWasmS128: |
| 1592 | return [kSimdPrefix, kExprS128Const, ...(new Array(16).fill(0))]; |
| 1593 | case kWasmStringViewIter: |
| 1594 | case kWasmStringViewWtf8: |
| 1595 | case kWasmStringViewWtf16: |
| 1596 | throw new Error("String views are non-defaultable"); |
| 1597 | default: |
| 1598 | if ((typeof type) != 'number' && type.opcode != kWasmRefNull) { |
| 1599 | throw new Error("Non-defaultable type"); |
| 1600 | } |
| 1601 | let heap_type = (typeof type) == 'number' ? type : type.heap_type; |
| 1602 | return [kExprRefNull, ...wasmSignedLeb(heap_type, kMaxVarInt32Size)]; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | addGlobal(type, mutable, shared, init) { |
| 1607 | if (init === undefined) init = WasmModuleBuilder.defaultFor(type); |
no test coverage detected