(val, max_len = 10)
| 2416 | } |
| 2417 | |
| 2418 | function wasmSignedLeb64(val, max_len = 10) { |
| 2419 | if (val == null) throw new Error("Leb value may not be null/undefined"); |
| 2420 | if (typeof val != "bigint") { |
| 2421 | if (val < Math.pow(2, 31)) { |
| 2422 | return wasmSignedLeb(val, max_len); |
| 2423 | } |
| 2424 | val = BigInt(val); |
| 2425 | } |
| 2426 | let res = []; |
| 2427 | for (let i = 0; i < max_len; ++i) { |
| 2428 | let v = val & 0x7fn; |
| 2429 | // If {v} sign-extended from 7 to 32 bits is equal to val, we are done. |
| 2430 | if (BigInt.asIntN(7, v) == val) { |
| 2431 | res.push(Number(v)); |
| 2432 | return res; |
| 2433 | } |
| 2434 | res.push(Number(v) | 0x80); |
| 2435 | val = val >> 7n; |
| 2436 | } |
| 2437 | throw new Error( |
| 2438 | 'Leb value <' + val + '> exceeds maximum length of ' + max_len); |
| 2439 | } |
| 2440 | |
| 2441 | function wasmUnsignedLeb(val, max_len = 5) { |
| 2442 | if (val == null) throw new Error("Leb value many not be null/undefined"); |
no test coverage detected