-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathgetter-setter.js
197 lines (170 loc) · 5.18 KB
/
getter-setter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
function isLikeNone(x) {
return x === undefined || x === null;
}
let WASM_VECTOR_LEN = 0;
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
let cachedTextEncoder = new lTextEncoder('utf-8');
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
const FooFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_foo_free(ptr >>> 0, 1));
export class Foo {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
FooFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_foo_free(ptr, 0);
}
/**
* @returns {number}
*/
get x() {
const ret = wasm.__wbg_get_foo_x(this.__wbg_ptr);
return ret >>> 0;
}
/**
* @param {number} arg0
*/
set x(arg0) {
wasm.__wbg_set_foo_x(this.__wbg_ptr, arg0);
}
/**
* @returns {number | undefined}
*/
get y() {
const ret = wasm.__wbg_get_foo_y(this.__wbg_ptr);
return ret === 0x100000001 ? undefined : ret;
}
/**
* @param {number | undefined} [arg0]
*/
set y(arg0) {
wasm.__wbg_set_foo_y(this.__wbg_ptr, isLikeNone(arg0) ? 0x100000001 : (arg0) >>> 0);
}
/**
* @returns {number | undefined}
*/
get z() {
const ret = wasm.foo_z(this.__wbg_ptr);
return ret === 0x100000001 ? undefined : ret;
}
/**
* @param {number | undefined} [z]
*/
set z(z) {
wasm.foo_set_z(this.__wbg_ptr, isLikeNone(z) ? 0x100000001 : (z) >>> 0);
}
/**
* @returns {number | undefined}
*/
get lone_getter() {
const ret = wasm.foo_lone_getter(this.__wbg_ptr);
return ret === 0x100000001 ? undefined : ret;
}
/**
* @param {number | undefined} [value]
*/
set lone_setter(value) {
wasm.foo_set_lone_setter(this.__wbg_ptr, isLikeNone(value) ? 0x100000001 : (value) >>> 0);
}
/**
* You will only read numbers.
* @returns {number}
*/
get weird() {
const ret = wasm.foo_weird(this.__wbg_ptr);
return ret >>> 0;
}
/**
* But you must write strings.
*
* Yes, this is totally fine in JS.
* @param {string | undefined} [value]
*/
set weird(value) {
var ptr0 = isLikeNone(value) ? 0 : passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
wasm.foo_set_weird(this.__wbg_ptr, ptr0, len0);
}
/**
* There can be static getters and setters too, and they can even have the
* same name as instance getters and setters.
* @returns {boolean | undefined}
*/
static get x() {
const ret = wasm.foo_x();
return ret === 0xFFFFFF ? undefined : ret !== 0;
}
/**
* @param {boolean | undefined} [value]
*/
static set x(value) {
wasm.foo_set_x(isLikeNone(value) ? 0xFFFFFF : value ? 1 : 0);
}
}
export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};