Skip to content

Commit

Permalink
Updated to the latest loader API
Browse files Browse the repository at this point in the history
  • Loading branch information
torch2424 committed Nov 11, 2020
1 parent 4e6ad59 commit 4442d68
Show file tree
Hide file tree
Showing 9 changed files with 537 additions and 374 deletions.
2 changes: 1 addition & 1 deletion lib/asbind-instance/instantiate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Wrapper around the loader instantiate
import * as loader from "assemblyscript/lib/loader";
import loader from "@assemblyscript/loader";

export async function asbindInstantiate(source, importObject) {
let wasmInstance;
Expand Down
57 changes: 53 additions & 4 deletions lib/asbind-instance/reserved-export-keys.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
export const RUNTIME_EXPORT_KEYS = [
// Runtime Export keys we don't want to bind to
export const RESERVED_RUNTIME_EXPORT_KEYS = [
"__newString",
"__newArray",
"__getString",
"__getArrayBuffer",
"__getArray",
"__getArrayView",
"__getInt8ArrayView",
"__getUint8ArrayView",
"__getUint8ClampedArrayView",
"__getInt16ArrayView",
"__getUint16ArrayView",
"__getInt32ArrayView",
"__getUint32ArrayView",
"__getInt64ArrayView",
"__getUint64ArrayView",
"__getFloat32ArrayView",
"__getFloat64ArrayView",
"__new",
"__renew",
"__retain",
"__release",
"__instanceof",
"__collect",
"__rtti_base",
"__alloc",
"__allocString",
"__allocArray",
"__allocString"
];

// Runtime export keys that must exist for the AsBind to work
export const REQUIRED_RUNTIME_EXPORT_KEYS = [
"__new",
"__newString",
"__newArray",
"__retain",
"__release"
"__release",
"__instanceof",
"__getString",
"__getArrayBuffer",
"__getArray",
"__getArrayView",
"__getInt8ArrayView",
"__getUint8ArrayView",
"__getUint8ClampedArrayView",
"__getInt16ArrayView",
"__getUint16ArrayView",
"__getInt32ArrayView",
"__getUint32ArrayView",
"__getInt64ArrayView",
"__getUint64ArrayView",
"__getFloat32ArrayView",
"__getFloat64ArrayView"
];

export function isReservedExportKey(key) {
if (key.startsWith("__asbind")) {
return true;
} else if (RUNTIME_EXPORT_KEYS.includes(key)) {
} else if (RESERVED_RUNTIME_EXPORT_KEYS.includes(key)) {
return true;
}

Expand Down
18 changes: 9 additions & 9 deletions lib/asbind-instance/supported-ref-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SUPPORTED_REF_TYPES = {
return wasmExports.__instanceof(ref, wasmExports.__asbind_String_ID);
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(wasmExports.__allocString(arg));
return wasmExports.__retain(wasmExports.__newString(arg));
},
getValueFromRef: (wasmExports, responseRef) => {
return wasmExports.__getString(responseRef);
Expand All @@ -29,7 +29,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Int8Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Int8Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -51,7 +51,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Uint8Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Uint8Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -73,7 +73,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Int16Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Int16Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -95,7 +95,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Uint16Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Uint16Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -117,7 +117,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Int32Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Int32Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -139,7 +139,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Uint32Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Uint32Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -164,7 +164,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Float32Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Float32Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand All @@ -189,7 +189,7 @@ const SUPPORTED_REF_TYPES = {
},
getRef: (wasmExports, arg) => {
return wasmExports.__retain(
wasmExports.__allocArray(wasmExports.__asbind_Float64Array_ID, arg)
wasmExports.__newArray(wasmExports.__asbind_Float64Array_ID, arg)
);
},
getValueFromRef: (wasmExports, responseRef) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/asbind-instance/validate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Validations to run when binding elements

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

export function validateExportsAndFunction(exports, exportFunction) {
// Do some validation
Expand All @@ -16,7 +16,7 @@ export function validateExportsAndFunction(exports, exportFunction) {
);
}

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

0 comments on commit 4442d68

Please sign in to comment.