recursal/MDN huggingface dataset:
WebAssembly.Module.exports()
============================

 The **`WebAssembly.Module.exports()`** static method returns an
 array containing descriptions of all the declared exports of the given
 `Module`.

Syntax
------


```js
WebAssembly.Module.exports(module)
```

### Parameters

`module`

A `WebAssembly.Module` object.

### Return value

An array containing objects representing the exported functions of the given module.

### Exceptions

 If module is not a `WebAssembly.Module` object instance, a
 `TypeError` is thrown.

Examples
--------

### Using exports

 The following example (see our index-compile.html
 demo on GitHub, and view it live also)
 compiles the loaded simple.wasm byte code using the
 `WebAssembly.compileStreaming()` method and then sends it to a worker using postMessage().


```js
const worker = new Worker("wasm\_worker.js");

WebAssembly.compileStreaming(fetch("simple.wasm")).then((mod) =>
  worker.postMessage(mod),
);
```


 In the worker (see
 `wasm_worker.js`)
 we define an import object for the module to use, then set up an event handler to
 receive the module from the main thread. When the module is received, we create an
 instance from it using the `WebAssembly.Instantiate()` method, invoke an
 exported function from inside it, then show how we can return information on the
 available exports on a module using `WebAssembly.Module.exports`.


```js
const importObject = {
  imports: {
    imported\_func(arg) {
      console.log(arg);
    },
  },
};

onmessage = (e) => {
  console.log("module received from main thread");
  const mod = e.data;

  WebAssembly.instantiate(mod, importObject).then((instance) => {
    instance.exports.exported\_func();
  });

  const exports = WebAssembly.Module.exports(mod);
  console.log(exports[0]);
};
```


The `exports[0]` output looks like this:


```js
{ name: "exported\_func", kind: "function" }
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-module-exports |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Module() constructor
================================

 A **`WebAssembly.Module()`** constructor creates a new Module
 object containing stateless WebAssembly code that has already been compiled by the
 browser and can be efficiently shared with Workers, and instantiated multiple times.

 The `WebAssembly.Module()` constructor function can be called to
 synchronously compile given WebAssembly binary code. However, the primary way to get a
 `Module` is through an asynchronous compilation function like
 `WebAssembly.compile()`.


**Note:** Webpages that have strict Content Security Policy (CSP) might block WebAssembly from compiling and executing modules.
 For more information on allowing WebAssembly compilation and execution, see the script-src CSP.


Syntax
------

**Warning:** Since compilation for large modules can be expensive,
 developers should only use the `Module()` constructor when synchronous
 compilation is absolutely required; the asynchronous
 `WebAssembly.compileStreaming()` method should be used at all other times.



```js
new WebAssembly.Module(bufferSource)
```

### Parameters

`bufferSource`

 A typed array or ArrayBuffer
 containing the binary code of the Wasm module you want to compile.


#### Exceptions

* If the parameter is not of the correct type or structure, a
 `TypeError` is thrown.
* If compilation fails, the constructor rejects with a
 `WebAssembly.CompileError`.
* Some browsers may throw a `RangeError`, as they prohibit compilation and instantiation of Wasm with large buffers on the UI thread.
Examples
--------

### Synchronously compiling a WebAssembly module


```js
const importObject = {
  imports: {
    imported\_func(arg) {
      console.log(arg);
    },
  },
};

function createWasmModule(bytes) {
  return new WebAssembly.Module(bytes);
}

fetch("simple.wasm")
  .then((response) => response.arrayBuffer())
  .then((bytes) => {
    const mod = createWasmModule(bytes);
    WebAssembly.instantiate(mod, importObject).then((result) =>
      result.exports.exported\_func(),
    );
  });
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-module-module |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Module.imports()
============================

 The **`WebAssembly.Module.imports()`** static method returns an array
 containing descriptions of all the declared imports of the given `Module`.

Syntax
------


```js
WebAssembly.Module.imports(module)
```

### Parameters

`module`

A `WebAssembly.Module` object.

### Return value

An array containing objects representing the imported functions of the given module.

### Exceptions

 If module is not a `WebAssembly.Module` object instance, a
 `TypeError` is thrown.

Examples
--------

### Using imports

The following example compiles a loaded Wasm module and queries the module's imports.

 See imports.html source code and
 live version.


```js
WebAssembly.compileStreaming(fetch("simple.wasm")).then((mod) => {
  const imports = WebAssembly.Module.imports(mod);
  console.log(imports[0]);
});
```


The console log displays the following description for the imported module:


```js
{ module: "imports", name: "imported\_func", kind: "function" }
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-module-imports |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Instance.prototype.exports
======================================

 The **`exports`** readonly property of the
 `WebAssembly.Instance` object prototype returns an object containing as its
 members all the functions exported from the WebAssembly module instance, to allow them
 to be accessed and used by JavaScript.

Examples
--------

### Using exports

 After fetching some WebAssembly bytecode using fetch, we compile and instantiate the
 module using the `WebAssembly.instantiateStreaming()` function, importing a
 JavaScript function into the WebAssembly Module in the process. We then call an Exported WebAssembly function
 that is exported by the `Instance`.


```js
const importObject = {
  imports: {
    imported\_func(arg) {
      console.log(arg);
    },
  },
};

WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
  (obj) => obj.instance.exports.exported\_func(),
);
```


**Note:** You can also find this example as instantiate-streaming.html
 on GitHub (view it live also).


Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-instance-exports |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Instance() constructor
==================================

 The **`WebAssembly.Instance()`** constructor creates a new
 `Instance` object which is a stateful, executable instance of a
 `WebAssembly.Module`.

Syntax
------

**Warning:** Since instantiation for large modules can be expensive,
 developers should only use the `Instance()` constructor when synchronous
 instantiation is absolutely required; the asynchronous
 `WebAssembly.instantiateStreaming()` method should be used at all other
 times.



```js
new WebAssembly.Instance(module, importObject);
```

### Parameters

`module`

The `WebAssembly.Module` object to be instantiated.

`importObject` Optional

 An object containing the values to be imported into the newly-created
 `Instance`, such as functions or `WebAssembly.Memory` objects.
 There must be one matching property for each declared import of `module` or
 else a `WebAssembly.LinkError` is thrown.


#### Exceptions

* If either of the parameters are not of the correct type or structure, a
 `TypeError` is thrown.
* If the operation fails, one of
 `WebAssembly.CompileError`, `WebAssembly.LinkError`, or
 `WebAssembly.RuntimeError` are thrown, depending on the cause of the failure.
* Some browsers may throw a `RangeError`, as they prohibit compilation and instantiation of Wasm with large buffers on the UI thread.
Examples
--------

### Synchronously instantiating a WebAssembly module

 The `WebAssembly.Instance()` constructor function can be called to
 synchronously instantiate a given `WebAssembly.Module` object, for example:


```js
const importObject = {
  imports: {
    imported\_func(arg) {
      console.log(arg);
    },
  },
};

fetch("simple.wasm")
  .then((response) => response.arrayBuffer())
  .then((bytes) => {
    const mod = new WebAssembly.Module(bytes);
    const instance = new WebAssembly.Instance(mod, importObject);
    instance.exports.exported\_func();
  });
```


 However, the preferred way to get an `Instance` is through the asynchronous
 `WebAssembly.instantiateStreaming()` function, for example like this:


```js
const importObject = {
  imports: {
    imported\_func(arg) {
      console.log(arg);
    },
  },
};

WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
  (obj) => obj.instance.exports.exported\_func(),
);
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-instance-instance |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.LinkError() constructor
===================================

 The **`WebAssembly.LinkError()`** constructor creates a new
 WebAssembly `LinkError` object, which indicates an error during module
 instantiation (besides traps
 from the start function).

Syntax
------


```js
new WebAssembly.LinkError()
new WebAssembly.LinkError(message)
new WebAssembly.LinkError(message, options)
new WebAssembly.LinkError(message, fileName)
new WebAssembly.LinkError(message, fileName, lineNumber)
```

### Parameters

`message` Optional

Human-readable description of the error.

`options` Optional

An object that has the following properties:

`cause` Optional

 A property indicating the specific cause of the error.
 When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error.



`fileName` Optional 
Non-standard

The name of the file containing the code that caused the exception.

`lineNumber` Optional 
Non-standard

The line number of the code that caused the exception.

Examples
--------

### Creating a new LinkError instance

 The following snippet creates a new `LinkError` instance, and logs its
 details to the console:


```js
try {
  throw new WebAssembly.LinkError("Hello", "someFile", 10);
} catch (e) {
  console.log(e instanceof LinkError); // true
  console.log(e.message); // "Hello"
  console.log(e.name); // "LinkError"
  console.log(e.fileName); // "someFile"
  console.log(e.lineNumber); // 10
  console.log(e.columnNumber); // 0
  console.log(e.stack); // returns the location where the code was run
}
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # exceptiondef-linkerror |
| ECMAScript Language Specification # sec-nativeerror-constructors |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Table.prototype.set()
=================================

The **`set()`** prototype method of the `WebAssembly.Table` object mutates a reference stored at a given index to a different value.

Syntax
------


```js
set(index, value)
```

### Parameters

`index`

The index of the function reference you want to mutate.

`value`

The value you want to mutate the reference to. This must be a value of the table's element type. Depending on the type, it may be an exported WebAssembly function, a JavaScript wrapper for an underlying Wasm function, or a host reference.

### Return value

None (`undefined`).

### Exceptions

* If `index` is greater than or equal to `Table.prototype.length`, a `RangeError` is thrown.
* If `value` is not of the element type of the table, a `TypeError` is thrown.
Examples
--------

### Using Table.set

The following example (see table2.html source code and live version) creates a new WebAssembly Table instance with an initial size of two references. We then print out the table length and contents of the two indexes (retrieved via `Table.prototype.get()`) to show that the length is two, and the indexes currently contain no function references (they currently return `null`).


```js
const tbl = new WebAssembly.Table({ initial: 2, element: "anyfunc" });
console.log(tbl.length);
console.log(tbl.get(0));
console.log(tbl.get(1));
```


We then create an import object that contains a reference to the table:


```js
const importObj = {
  js: { tbl },
};
```


Finally, we load and instantiate a Wasm module (table2.wasm) using `WebAssembly.instantiateStreaming()`, print the table length, and invoke the two referenced functions that are now stored in the table. The `table2.wasm` module adds two function references to the table, both of which print out a simple value (see text representation:


```js
WebAssembly.instantiateStreaming(fetch("table2.wasm"), importObject).then(
  (obj) => {
    console.log(tbl.length);
    console.log(tbl.get(0)());
    console.log(tbl.get(1)());
  },
);
```


Note how you've got to include a second function invocation operator at the end of the accessor to actually invoke the referenced function and log the value stored inside it (e.g. `get(0)()` rather than `get(0)`) .

This example shows that we're creating and accessing the table from JavaScript, but the same table is visible and callable inside the Wasm instance, too.

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-table-set |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Table.prototype.length
==================================

The read-only **`length`** prototype property of the `WebAssembly.Table` object returns the length of the table, i.e. the number of elements in the table.

Examples
--------

### Using length

 The following example creates a new WebAssembly Table instance with an initial size of
 2 and a maximum size of 10:


```js
const table = new WebAssembly.Table({
  element: "anyfunc",
  initial: 2,
  maximum: 10,
});
```


Grow the table by 1 using `WebAssembly.grow()`:


```js
console.log(table.length); // 2
table.grow(1);
console.log(table.length); // 3
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-table-length |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Table.prototype.grow()
==================================

The **`grow()`** prototype method of the `WebAssembly.Table` object increases the size of the `Table` instance by a specified number of elements, filled with the provided value.

Syntax
------


```js
grow(delta)
grow(delta, value)
```

### Parameters

`delta`

The number of elements you want to grow the table by.

`value` Optional

The element to fill the newly-allocated space with.

### Return value

The previous length of the table.

### Exceptions

`RangeError`

Thrown in one of the following cases:

* If the current size added with `delta` exceeds the Table instance's maximum size capacity.
* If the client doesn't have enough memory for the allocation.

`TypeError`

Thrown if `value` is not a value of the element type of the table.

Examples
--------

### Using grow

 The following example creates a new WebAssembly Table instance with an initial size of
 2 and a maximum size of 10:


```js
const table = new WebAssembly.Table({
  element: "anyfunc",
  initial: 2,
  maximum: 10,
});
```


Grow the table by 1 element using `Table.grow()`:


```js
console.log(table.length); // 2
table.grow(1);
console.log(table.length); // 3
```

### Using grow with a value

 The following example creates a new WebAssembly `Table` instance with an initial size of
 0 and a maximum size of 4, filling it with an object:


```js
const myObject = { hello: "world" };

const table = new WebAssembly.Table({
  element: "externref",
  initial: 0,
  maximum: 4,
});
```


Grow the table by 4 units and fill it with a value using `WebAssembly.grow()`:


```js
table.grow(4, myObject);
console.log(myObject === table.get(2)); // true
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-table-grow |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Table.prototype.get()
=================================

The **`get()`** prototype method of the `WebAssembly.Table()` object retrieves the element stored at a given index.

Syntax
------


```js
get(index)
```

### Parameters

`index`

The index of the element you want to retrieve.

### Return value

Depending the element type of the Table, can be a function reference — this is an exported WebAssembly function, a JavaScript wrapper for an underlying Wasm function, or it can be a host reference.

### Exceptions

If *index* is greater than or equal to `Table.prototype.length`, a `RangeError` is thrown.

Examples
--------

### Using get

The following example (see table.html on GitHub, and view it live also) compiles and instantiates the loaded table.wasm byte code using the `WebAssembly.instantiateStreaming()` method. It then retrieves the references stored in the exported table.


```js
WebAssembly.instantiateStreaming(fetch("table.wasm")).then((obj) => {
  const tbl = obj.instance.exports.tbl;
  console.log(tbl.get(0)()); // 13
  console.log(tbl.get(1)()); // 42
});
```


Note how you've got to include a second function invocation operator at the end of the accessor to actually retrieve the value stored inside the reference (e.g. `get(0)()` rather than `get(0)`) — it is a function rather than a simple value.

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface # dom-table-get |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview page
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Exception.prototype.is()
====================================

The **`is()`** prototype method of the `Exception` object can be used to test if the `Exception` matches a given tag.

 The method might be used to test that a tag is correct before passing it to `Exception.prototype.getArg()` to get the passed values.
 It can be used on tags created in JavaScript or created in WebAssembly code and exported to JavaScript.

**Note:** It is not enough that the tag has an identical sequence of data types — it must have the same *identity* (be the same tag) as was used to create the exception.

Syntax
------


```js
is(tag)
```

### Parameters

`tag`

An `WebAssembly.Tag` that can be checked to verify the type of the exception.

### Return value

A boolean `true` if the specified tag matches the exception, and `false` otherwise.

Examples
--------

The code below shows how to use `is()` to verify that a tag matches an `Exception`.


```js
// Create tag and use it to create an exception
const tag1 = new WebAssembly.Tag({ parameters: ["i32", "f64"] });
const exception1 = new WebAssembly.Exception(tag1, [42, 42.3]);

// Verify that "tag1" matches this exception
console.log(`Tag1: ${exception1.is(tag1)}`);

// Log output:
// Tag1: true
```


We can also demonstrate that this exception will not match another tag even if the tag is created with the same parameters.


```js
// Create a new tag (with same parameters) and verify it does not match the exception
const tag2 = new WebAssembly.Tag({ parameters: ["i32", "f64"] });
console.log(`Tag2: ${exception1.is(tag2)}`);

// Log output:
// Tag2: false
```

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface: Exception Handling # dom-exception-is |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview
* WebAssembly concepts
* Using the WebAssembly JavaScript API
WebAssembly.Exception constructor
=================================

The **`WebAssembly.Exception()`** constructor is used to create a new `WebAssembly.Exception`.

 The constructor accepts a `Tag` argument and a `payload` array of data fields.
 The data types of each of the payload elements must match the corresponding data type specified in the `Tag`.

 The constructor may also take an `options` object.
 The `options.traceStack` property can be set `true` (by default it is `false`) to indicate that a Wasm stack trace may be attached to the exception's `stack` property.

Syntax
------


```js
new Exception(tag, payload)
new Exception(tag, payload, options)
```

### Parameters

`tag`

An `WebAssembly.Tag` defining the data types expected for each of the values in the `payload`.

`payload`

 An array of one or more data fields comprising the payload of the exception.
 The elements must match the data types of the corresponding elements in the `tag`.
 If the number of data fields in the payload and their types don't match, a `TypeError` exception is thrown.


`options` Optional 
Non-standard

An object with the following optional fields:

`traceStack` Optional 
Non-standard

`true` if the `Exception` may have a stack trace attached to its `stack` property, otherwise `false`.
 This is `false` by default (if `options` or `options.traceStack` are not provided).



### Exceptions

`TypeError`

The `payload` and `tag` sequences do not have the same number of elements and/or the elements are not of matching types.

Examples
--------

This example shows the creation of an exception using a simple tag.


```js
// Create tag and use it to create an exception
const tag = new WebAssembly.Tag({ parameters: ["i32", "f32"] });
const exception = new WebAssembly.Exception(tag, [42, 42.3]);
```


The `stack` example shows the creation of an exception that uses the `options` parameter.

Specifications
--------------

| Specification |
| --- |
| WebAssembly JavaScript Interface: Exception Handling # dom-exception-exception |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebAssembly overview
* WebAssembly concepts
* Using the WebAssembly JavaScript API