Skip to content

Commit 33b4b1b

Browse files
committed
Finished the README
1 parent 54a57fe commit 33b4b1b

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,36 @@ An AsBindInstance is vaugley similar to a [WebAssembly instance](https://develop
174174

175175
##### exports
176176

177+
Similar to to [WebAssembly.Instance.prototype.exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports), this is an object containing all of the exported fields from the WebAssembly module. However, **exported functions** are bound / wrapped in which they will handle passing the supported high-level data types to the exported AssemblyScript function.
178+
179+
Each **exported function** has the property: `shouldCacheTypes`. If you would like to disable type caching (speculative execution) for a particular function, you can do: `asBindInstance.exports.myFunction.shouldCacheTypes = false;`. Or set to true, to re-enable type caching.
180+
177181
##### unboundExports
178182

183+
This is essentially the same as the [WebAssembly.Instance.prototype.exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports), this is an object containing all of the exported fields from the WebAssembly module. These are not bound / wrapped, so you can access the original exported functions.
184+
185+
#### importObject
186+
187+
Similar to to [WebAssembly.instantiateStreaming() importObject](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming), This is the original passed importObject on instantiation, after the **importObject functions** are bound / wrapped by as-bind.
188+
189+
Each wrapped **importObject function** has the property: `shouldCacheTypes`. If you would like to disable type caching (speculative execution) for a particular function, you can do: `asBindInstance.importObject.myFunction.shouldCacheTypes = false;`. Or set to true, to re-enable type caching.
190+
179191
##### enableExportFunctionTypeCaching
180192

193+
This will (re-)enable type caching (speculative execution) for ALL exported functions on the AsBindInstance.
194+
181195
##### disableExportFunctionTypeCaching
182196

197+
This will disable type caching (speculative execution) for ALL exported functions on the AsBindInstance.
198+
183199
##### enableImportFunctionTypeCaching
184200

201+
This will (re-)enable type caching (speculative execution) for ALL importObject functions on the AsBindInstance.
202+
185203
##### disableExportFunctionTypeCaching
186204

205+
This will disable type caching (speculative execution) for ALL importObject functions on the AsBindInstance.
206+
187207
## License
188208

189209
[MIT](https://oss.ninja/mit/torch2424).

lib/asbind-instance.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ export default class AsbindInstance {
3232
constructor() {
3333
this.unboundExports = {};
3434
this.exports = {};
35-
this._importObject = {};
35+
this.importObject = {};
3636
}
3737

3838
async _instantiate(source, importObject) {
3939
// Set our import object, as we will need it to store type caching
40-
this._importObject = importObject;
40+
this.importObject = importObject;
4141

4242
// Need to traverse the importObject and bind all import functions
4343
traverseObjectAndRunCallbackForFunctions(
44-
this._importObject,
44+
this.importObject,
4545
[],
4646
(baseObject, keys, baseObjectKey) => {
4747
// Wrap the original key, but then expose a new key for the unbound import
4848
let importFunction = baseObject[baseObjectKey];
4949
baseObject[`__asbind_unbound_${baseObjectKey}`] = importFunction;
5050
baseObject[baseObjectKey] = bindImportFunction(
5151
this,
52-
this._importObject,
52+
this.importObject,
5353
[...keys, baseObjectKey]
5454
);
5555
}
5656
);
5757

5858
// Instantiate the module through the loader
59-
this.unboundExports = await asbindInstantiate(source, this._importObject);
59+
this.unboundExports = await asbindInstantiate(source, this.importObject);
6060

6161
// Wrap appropriate the appropriate export functions
6262
this.exports = {};
@@ -91,7 +91,7 @@ export default class AsbindInstance {
9191
enableImportFunctionTypeCaching() {
9292
// Need to traverse the importObject and bind all import functions
9393
traverseObjectAndRunCallbackForFunctions(
94-
this._importObject,
94+
this.importObject,
9595
[],
9696
(baseObject, keys, baseObjectKey) => {
9797
// Wrap the original key, but then expose a new key for the unbound import
@@ -104,7 +104,7 @@ export default class AsbindInstance {
104104
disableImportFunctionTypeCaching() {
105105
// Need to traverse the importObject and bind all import functions
106106
traverseObjectAndRunCallbackForFunctions(
107-
this._importObject,
107+
this.importObject,
108108
[],
109109
(baseObject, keys, baseObjectKey) => {
110110
// Wrap the original key, but then expose a new key for the unbound import

0 commit comments

Comments
 (0)