|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import * as wasm from './index_bg.wasm'; |
| 9 | + |
| 10 | +const lTextDecoder = |
| 11 | + typeof TextDecoder === 'undefined' |
| 12 | + ? (0, module.require)('util').TextDecoder |
| 13 | + : TextDecoder; |
| 14 | + |
| 15 | +const cachedTextDecoder = new lTextDecoder('utf-8', { |
| 16 | + fatal: true, |
| 17 | + ignoreBOM: true, |
| 18 | +}); |
| 19 | + |
| 20 | +cachedTextDecoder.decode(); |
| 21 | + |
| 22 | +let cachedUint8Memory0 = new Uint8Array(); |
| 23 | + |
| 24 | +function getUint8Memory0() { |
| 25 | + if (cachedUint8Memory0.byteLength === 0) { |
| 26 | + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); |
| 27 | + } |
| 28 | + return cachedUint8Memory0; |
| 29 | +} |
| 30 | + |
| 31 | +function getStringFromWasm0(ptr, len) { |
| 32 | + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); |
| 33 | +} |
| 34 | + |
| 35 | +function logError(f, args) { |
| 36 | + try { |
| 37 | + return f.apply(this, args); |
| 38 | + } catch (e) { |
| 39 | + const error = (function () { |
| 40 | + try { |
| 41 | + return e instanceof Error |
| 42 | + ? `${e.message}\n\nStack:\n${e.stack}` |
| 43 | + : e.toString(); |
| 44 | + } catch (_) { |
| 45 | + return '<failed to stringify thrown value>'; |
| 46 | + } |
| 47 | + })(); |
| 48 | + console.error( |
| 49 | + 'wasm-bindgen: imported JS function that was not marked as `catch` threw an error:', |
| 50 | + error, |
| 51 | + ); |
| 52 | + throw e; |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +let WASM_VECTOR_LEN = 0; |
| 57 | + |
| 58 | +const lTextEncoder = |
| 59 | + typeof TextEncoder === 'undefined' |
| 60 | + ? (0, module.require)('util').TextEncoder |
| 61 | + : TextEncoder; |
| 62 | + |
| 63 | +const cachedTextEncoder = new lTextEncoder('utf-8'); |
| 64 | + |
| 65 | +const encodeString = |
| 66 | + typeof cachedTextEncoder.encodeInto === 'function' |
| 67 | + ? function (arg, view) { |
| 68 | + return cachedTextEncoder.encodeInto(arg, view); |
| 69 | + } |
| 70 | + : function (arg, view) { |
| 71 | + const buf = cachedTextEncoder.encode(arg); |
| 72 | + view.set(buf); |
| 73 | + return { |
| 74 | + read: arg.length, |
| 75 | + written: buf.length, |
| 76 | + }; |
| 77 | + }; |
| 78 | + |
| 79 | +function passStringToWasm0(arg, malloc, realloc) { |
| 80 | + if (typeof arg !== 'string') throw new Error('expected a string argument'); |
| 81 | + |
| 82 | + if (realloc === undefined) { |
| 83 | + const buf = cachedTextEncoder.encode(arg); |
| 84 | + const ptr = malloc(buf.length); |
| 85 | + getUint8Memory0() |
| 86 | + .subarray(ptr, ptr + buf.length) |
| 87 | + .set(buf); |
| 88 | + WASM_VECTOR_LEN = buf.length; |
| 89 | + return ptr; |
| 90 | + } |
| 91 | + |
| 92 | + let len = arg.length; |
| 93 | + let ptr = malloc(len); |
| 94 | + |
| 95 | + const mem = getUint8Memory0(); |
| 96 | + |
| 97 | + let offset = 0; |
| 98 | + |
| 99 | + for (; offset < len; offset++) { |
| 100 | + const code = arg.charCodeAt(offset); |
| 101 | + if (code > 0x7f) break; |
| 102 | + mem[ptr + offset] = code; |
| 103 | + } |
| 104 | + |
| 105 | + if (offset !== len) { |
| 106 | + if (offset !== 0) { |
| 107 | + arg = arg.slice(offset); |
| 108 | + } |
| 109 | + ptr = realloc(ptr, len, (len = offset + arg.length * 3)); |
| 110 | + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); |
| 111 | + const ret = encodeString(arg, view); |
| 112 | + if (ret.read !== arg.length) throw new Error('failed to pass whole string'); |
| 113 | + offset += ret.written; |
| 114 | + } |
| 115 | + |
| 116 | + WASM_VECTOR_LEN = offset; |
| 117 | + return ptr; |
| 118 | +} |
| 119 | +/** |
| 120 | + * @param {string} name |
| 121 | + */ |
| 122 | +export function greet(name) { |
| 123 | + const ptr0 = passStringToWasm0( |
| 124 | + name, |
| 125 | + wasm.__wbindgen_malloc, |
| 126 | + wasm.__wbindgen_realloc, |
| 127 | + ); |
| 128 | + const len0 = WASM_VECTOR_LEN; |
| 129 | + wasm.greet(ptr0, len0); |
| 130 | +} |
| 131 | + |
| 132 | +export function __wbg_alert_9ea5a791b0d4c7a3() { |
| 133 | + return logError((arg0, arg1) => { |
| 134 | + // eslint-disable-next-line no-undef |
| 135 | + alert(getStringFromWasm0(arg0, arg1)); |
| 136 | + }, arguments); |
| 137 | +} |
| 138 | + |
| 139 | +export function __wbindgen_throw(arg0, arg1) { |
| 140 | + throw new Error(getStringFromWasm0(arg0, arg1)); |
| 141 | +} |
0 commit comments