Last active
May 17, 2018 13:15
-
-
Save alexcrichton/3d85c505e785fb8ff32e2c1cf9618367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* tslint:disable */ | |
import * as wasm from './js_hello_world_wasm'; // imports from wasm file | |
import { | |
bar_on_reset | |
} from './index'; | |
import { | |
Awesome | |
} from './index'; | |
let cachedEncoder = null; | |
function textEncoder() { | |
if (cachedEncoder) | |
return cachedEncoder; | |
cachedEncoder = new TextEncoder('utf-8'); | |
return cachedEncoder; | |
} | |
let cachedUint8Memory = null; | |
function getUint8Memory() { | |
if (cachedUint8Memory === null || | |
cachedUint8Memory.buffer !== wasm.memory.buffer) | |
cachedUint8Memory = new Uint8Array(wasm.memory.buffer); | |
return cachedUint8Memory; | |
} | |
function passStringToWasm(arg) { | |
if (typeof(arg) !== 'string') | |
throw new Error('expected a string argument'); | |
const buf = textEncoder().encode(arg); | |
const len = buf.length; | |
const ptr = wasm.__wbindgen_malloc(len); | |
getUint8Memory().set(buf, ptr); | |
return [ptr, len]; | |
} | |
let slab = []; | |
let slab_next = 0; | |
function addHeapObject(obj) { | |
if (slab_next == slab.length) | |
slab.push(slab.length + 1); | |
const idx = slab_next; | |
const next = slab[idx]; | |
slab_next = next; | |
slab[idx] = { | |
obj, | |
cnt: 1 | |
}; | |
return idx << 1; | |
} | |
let cachedDecoder = null; | |
function textDecoder() { | |
if (cachedDecoder) | |
return cachedDecoder; | |
cachedDecoder = new TextDecoder('utf-8'); | |
return cachedDecoder; | |
} | |
function getStringFromWasm(ptr, len) { | |
const mem = getUint8Memory(); | |
const slice = mem.slice(ptr, ptr + len); | |
const ret = textDecoder().decode(slice); | |
return ret; | |
} | |
let stack = []; | |
function getObject(idx) { | |
if ((idx & 1) === 1) { | |
return stack[idx >> 1]; | |
} else { | |
const val = slab[idx >> 1]; | |
return val.obj; | |
} | |
} | |
export function __wbg_f_bar_on_reset(ptr0, len0, arg1) { | |
bar_on_reset(getStringFromWasm(ptr0, len0), getObject(arg1)) | |
} | |
export function __wbg_s_Awesome_new() { | |
return addHeapObject(new Awesome()); | |
} | |
export function __wbg_s_Awesome_get_internal(arg0) { | |
return Awesome.prototype.get_internal.call(getObject(arg0)); | |
} | |
export function concat(arg0, arg1) { | |
const [ptr0, len0] = passStringToWasm(arg0); | |
const [ptr1, len1] = passStringToWasm(arg1); | |
try { | |
const ret = wasm.concat(ptr0, len0, ptr1, len1); | |
const ptr = wasm.__wbindgen_boxed_str_ptr(ret); | |
const len = wasm.__wbindgen_boxed_str_len(ret); | |
const realRet = getStringFromWasm(ptr, len); | |
wasm.__wbindgen_boxed_str_free(ret); | |
return realRet; | |
} finally { | |
wasm.__wbindgen_free(ptr0, len0); | |
wasm.__wbindgen_free(ptr1, len1); | |
} | |
} | |
export class Foo { | |
constructor(ptr) { | |
this.ptr = ptr; | |
} | |
free() { | |
const ptr = this.ptr; | |
this.ptr = 0; | |
wasm.__wbg_foo_free(ptr); | |
} | |
static new() { | |
const ret = wasm.foo_new(); | |
return new Foo(ret); | |
} | |
add(arg0) { | |
const ret = wasm.foo_add(this.ptr, arg0); | |
return ret; | |
} | |
add_other(arg0) { | |
const ret = wasm.foo_add_other(this.ptr, arg0.ptr); | |
return ret; | |
} | |
consume_other(arg0) { | |
const ptr0 = arg0.ptr; | |
arg0.ptr = 0; | |
const ret = wasm.foo_consume_other(this.ptr, ptr0); | |
return ret; | |
} | |
} | |
export class Bar { | |
constructor(ptr) { | |
this.ptr = ptr; | |
} | |
free() { | |
const ptr = this.ptr; | |
this.ptr = 0; | |
wasm.__wbg_bar_free(ptr); | |
} | |
static from_str(arg0, arg1) { | |
const [ptr0, len0] = passStringToWasm(arg0); | |
const idx1 = addHeapObject(arg1); | |
try { | |
const ret = wasm.bar_from_str(ptr0, len0, idx1); | |
return new Bar(ret); | |
} finally { | |
wasm.__wbindgen_free(ptr0, len0); | |
} | |
} | |
reset(arg0) { | |
const [ptr0, len0] = passStringToWasm(arg0); | |
try { | |
const ret = wasm.bar_reset(this.ptr, ptr0, len0); | |
return ret; | |
} finally { | |
wasm.__wbindgen_free(ptr0, len0); | |
} | |
} | |
} | |
function dropRef(idx) { | |
let obj = slab[idx >> 1]; | |
obj.cnt -= 1; | |
if (obj.cnt > 0) | |
return; | |
// If we hit 0 then free up our space in the slab | |
slab[idx >> 1] = slab_next; | |
slab_next = idx >> 1; | |
} | |
export const __wbindgen_object_drop_ref = dropRef; | |
export const __wbindgen_throw = | |
function(ptr, len) { | |
throw new Error(getStringFromWasm(ptr, len)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment