Skip to content

Commit 0231aa2

Browse files
committed
Fixed #2
1 parent 8eca550 commit 0231aa2

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/supported-ref-types.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const SUPPORTED_REF_TYPES = {
1010
return wasmExports.__retain(wasmExports.__allocString(arg));
1111
},
1212
getValueFromRef: (wasmExports, responseRef) => {
13-
return wasmExports.__getString(responseRef);
13+
return wasmExports.__getString(responseRef).slice(0);
1414
}
1515
},
1616
INT8ARRAY: {
@@ -26,7 +26,7 @@ const SUPPORTED_REF_TYPES = {
2626
);
2727
},
2828
getValueFromRef: (wasmExports, responseRef) => {
29-
return Int8Array.from(wasmExports.__getArray(responseRef));
29+
return wasmExports.__getInt8Array(responseRef).slice();
3030
}
3131
},
3232
UINT8ARRAY: {
@@ -42,7 +42,7 @@ const SUPPORTED_REF_TYPES = {
4242
);
4343
},
4444
getValueFromRef: (wasmExports, responseRef) => {
45-
return Uint8Array.from(wasmExports.__getArray(responseRef));
45+
return wasmExports.__getUint8Array(responseRef).slice();
4646
}
4747
},
4848
INT16ARRAY: {
@@ -58,7 +58,7 @@ const SUPPORTED_REF_TYPES = {
5858
);
5959
},
6060
getValueFromRef: (wasmExports, responseRef) => {
61-
return Int16Array.from(wasmExports.__getArray(responseRef));
61+
return wasmExports.__getInt16Array(responseRef).slice();
6262
}
6363
},
6464
UINT16ARRAY: {
@@ -74,7 +74,7 @@ const SUPPORTED_REF_TYPES = {
7474
);
7575
},
7676
getValueFromRef: (wasmExports, responseRef) => {
77-
return Uint16Array.from(wasmExports.__getArray(responseRef));
77+
return wasmExports.__getUint16Array(responseRef).slice();
7878
}
7979
},
8080
INT32ARRAY: {
@@ -90,7 +90,7 @@ const SUPPORTED_REF_TYPES = {
9090
);
9191
},
9292
getValueFromRef: (wasmExports, responseRef) => {
93-
return Int32Array.from(wasmExports.__getArray(responseRef));
93+
return wasmExports.__getInt32Array(responseRef).slice();
9494
}
9595
},
9696
UINT32ARRAY: {
@@ -106,7 +106,7 @@ const SUPPORTED_REF_TYPES = {
106106
);
107107
},
108108
getValueFromRef: (wasmExports, responseRef) => {
109-
return Uint32Array.from(wasmExports.__getArray(responseRef));
109+
return wasmExports.__getUint32Array(responseRef).slice();
110110
}
111111
},
112112
FLOAT32ARRAY: {
@@ -125,7 +125,7 @@ const SUPPORTED_REF_TYPES = {
125125
);
126126
},
127127
getValueFromRef: (wasmExports, responseRef) => {
128-
return Float32Array.from(wasmExports.__getArray(responseRef));
128+
return wasmExports.__getFloat32Array(responseRef).slice();
129129
}
130130
},
131131
FLOAT64ARRAY: {
@@ -144,7 +144,7 @@ const SUPPORTED_REF_TYPES = {
144144
);
145145
},
146146
getValueFromRef: (wasmExports, responseRef) => {
147-
return Float64Array.from(wasmExports.__getArray(responseRef));
147+
return wasmExports.__getFloat64Array(responseRef).slice();
148148
}
149149
}
150150
};

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe("asbind", () => {
150150

151151
before(async () => {
152152
const importObjectFunction = value => {
153-
testImportCalledWith = [value];
153+
testImportCalledWith = [value].slice();
154154
};
155155

156156
const wrappedBaseImportObject = {
@@ -204,7 +204,7 @@ describe("asbind", () => {
204204
"Float64Array"
205205
].forEach(typedArrayKey => {
206206
it(`should handle ${typedArrayKey} being passed to the import object`, () => {
207-
const randomValue = Math.floor(Math.random() * 10);
207+
const randomValue = Math.floor(Math.random() * 10) + 1;
208208
const array = global[typedArrayKey].from([randomValue]);
209209
const arrayMapResponse = asbindInstance.exports[
210210
"callTestImport" + typedArrayKey

0 commit comments

Comments
 (0)