Skip to content

Commit 107707e

Browse files
authored
Merge pull request #55 from torch2424/update-as-loader
Updated to AssemblyScript Loader API 0.17.x
2 parents c22d4b2 + 04f52fc commit 107707e

File tree

10 files changed

+523
-361
lines changed

10 files changed

+523
-361
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
notifications:
22
email: false
33
language: node_js
4-
sudo: false
54
node_js:
65
- "node"
76
install:

lib/asbind-instance/instantiate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Wrapper around the loader instantiate
2-
import * as loader from "assemblyscript/lib/loader";
2+
import loader from "@assemblyscript/loader";
33

44
export async function asbindInstantiate(source, importObject) {
55
let wasmInstance;

lib/asbind-instance/reserved-export-keys.js

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,63 @@
1-
export const RUNTIME_EXPORT_KEYS = [
1+
// Runtime Export keys we don't want to bind to
2+
export const RESERVED_RUNTIME_EXPORT_KEYS = [
3+
"__newString",
4+
"__newArray",
5+
"__getString",
6+
"__getArrayBuffer",
7+
"__getArray",
8+
"__getArrayView",
9+
"__getInt8ArrayView",
10+
"__getUint8ArrayView",
11+
"__getUint8ClampedArrayView",
12+
"__getInt16ArrayView",
13+
"__getUint16ArrayView",
14+
"__getInt32ArrayView",
15+
"__getUint32ArrayView",
16+
"__getInt64ArrayView",
17+
"__getUint64ArrayView",
18+
"__getFloat32ArrayView",
19+
"__getFloat64ArrayView",
20+
"__new",
21+
"__renew",
22+
"__retain",
23+
"__release",
24+
"__instanceof",
25+
"__collect",
26+
"__rtti_base",
227
"__alloc",
3-
"__allocString",
28+
"__allocArray",
29+
"__allocString"
30+
];
31+
32+
// Runtime export keys that must exist for the AsBind to work
33+
export const REQUIRED_RUNTIME_EXPORT_KEYS = [
34+
"__new",
35+
"__newString",
36+
"__newArray",
437
"__retain",
5-
"__release"
38+
"__release",
39+
"__instanceof",
40+
"__getString",
41+
"__getArrayBuffer",
42+
"__getArray",
43+
"__getArrayView",
44+
"__getInt8ArrayView",
45+
"__getUint8ArrayView",
46+
"__getUint8ClampedArrayView",
47+
"__getInt16ArrayView",
48+
"__getUint16ArrayView",
49+
"__getInt32ArrayView",
50+
"__getUint32ArrayView",
51+
"__getInt64ArrayView",
52+
"__getUint64ArrayView",
53+
"__getFloat32ArrayView",
54+
"__getFloat64ArrayView"
655
];
756

857
export function isReservedExportKey(key) {
958
if (key.startsWith("__asbind")) {
1059
return true;
11-
} else if (RUNTIME_EXPORT_KEYS.includes(key)) {
60+
} else if (RESERVED_RUNTIME_EXPORT_KEYS.includes(key)) {
1261
return true;
1362
}
1463

lib/asbind-instance/supported-ref-types.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const SUPPORTED_REF_TYPES = {
1414
return wasmExports.__instanceof(ref, wasmExports.__asbind_String_ID);
1515
},
1616
getRef: (wasmExports, arg) => {
17-
return wasmExports.__retain(wasmExports.__allocString(arg));
17+
return wasmExports.__retain(wasmExports.__newString(arg));
1818
},
1919
getValueFromRef: (wasmExports, responseRef) => {
2020
return wasmExports.__getString(responseRef);
@@ -29,7 +29,7 @@ export const SUPPORTED_REF_TYPES = {
2929
},
3030
getRef: (wasmExports, arg) => {
3131
return wasmExports.__retain(
32-
wasmExports.__allocArray(wasmExports.__asbind_Int8Array_ID, arg)
32+
wasmExports.__newArray(wasmExports.__asbind_Int8Array_ID, arg)
3333
);
3434
},
3535
getValueFromRef: (wasmExports, responseRef) => {
@@ -51,7 +51,7 @@ export const SUPPORTED_REF_TYPES = {
5151
},
5252
getRef: (wasmExports, arg) => {
5353
return wasmExports.__retain(
54-
wasmExports.__allocArray(wasmExports.__asbind_Uint8Array_ID, arg)
54+
wasmExports.__newArray(wasmExports.__asbind_Uint8Array_ID, arg)
5555
);
5656
},
5757
getValueFromRef: (wasmExports, responseRef) => {
@@ -73,7 +73,7 @@ export const SUPPORTED_REF_TYPES = {
7373
},
7474
getRef: (wasmExports, arg) => {
7575
return wasmExports.__retain(
76-
wasmExports.__allocArray(wasmExports.__asbind_Int16Array_ID, arg)
76+
wasmExports.__newArray(wasmExports.__asbind_Int16Array_ID, arg)
7777
);
7878
},
7979
getValueFromRef: (wasmExports, responseRef) => {
@@ -95,7 +95,7 @@ export const SUPPORTED_REF_TYPES = {
9595
},
9696
getRef: (wasmExports, arg) => {
9797
return wasmExports.__retain(
98-
wasmExports.__allocArray(wasmExports.__asbind_Uint16Array_ID, arg)
98+
wasmExports.__newArray(wasmExports.__asbind_Uint16Array_ID, arg)
9999
);
100100
},
101101
getValueFromRef: (wasmExports, responseRef) => {
@@ -117,7 +117,7 @@ export const SUPPORTED_REF_TYPES = {
117117
},
118118
getRef: (wasmExports, arg) => {
119119
return wasmExports.__retain(
120-
wasmExports.__allocArray(wasmExports.__asbind_Int32Array_ID, arg)
120+
wasmExports.__newArray(wasmExports.__asbind_Int32Array_ID, arg)
121121
);
122122
},
123123
getValueFromRef: (wasmExports, responseRef) => {
@@ -139,7 +139,7 @@ export const SUPPORTED_REF_TYPES = {
139139
},
140140
getRef: (wasmExports, arg) => {
141141
return wasmExports.__retain(
142-
wasmExports.__allocArray(wasmExports.__asbind_Uint32Array_ID, arg)
142+
wasmExports.__newArray(wasmExports.__asbind_Uint32Array_ID, arg)
143143
);
144144
},
145145
getValueFromRef: (wasmExports, responseRef) => {
@@ -164,7 +164,7 @@ export const SUPPORTED_REF_TYPES = {
164164
},
165165
getRef: (wasmExports, arg) => {
166166
return wasmExports.__retain(
167-
wasmExports.__allocArray(wasmExports.__asbind_Float32Array_ID, arg)
167+
wasmExports.__newArray(wasmExports.__asbind_Float32Array_ID, arg)
168168
);
169169
},
170170
getValueFromRef: (wasmExports, responseRef) => {
@@ -189,7 +189,7 @@ export const SUPPORTED_REF_TYPES = {
189189
},
190190
getRef: (wasmExports, arg) => {
191191
return wasmExports.__retain(
192-
wasmExports.__allocArray(wasmExports.__asbind_Float64Array_ID, arg)
192+
wasmExports.__newArray(wasmExports.__asbind_Float64Array_ID, arg)
193193
);
194194
},
195195
getValueFromRef: (wasmExports, responseRef) => {

lib/asbind-instance/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Validations to run when binding elements
22

3-
import { RUNTIME_EXPORT_KEYS } from "./reserved-export-keys";
3+
import { REQUIRED_RUNTIME_EXPORT_KEYS } from "./reserved-export-keys";
44

55
export function validateExportsAndFunction(exports, exportFunction) {
66
// Do some validation
@@ -16,7 +16,7 @@ export function validateExportsAndFunction(exports, exportFunction) {
1616
);
1717
}
1818

19-
RUNTIME_EXPORT_KEYS.forEach(key => {
19+
REQUIRED_RUNTIME_EXPORT_KEYS.forEach(key => {
2020
if (!exports[key]) {
2121
throw new Error(
2222
'Required Exported AssemblyScript Runtime functions are not present. Runtime must be set to "full" or "stub"'

0 commit comments

Comments
 (0)