1# Maintaining WebAssembly 2 3Support for [WebAssembly](https://webassembly.org/) 4has been identified as one of the 5[top technical priorities](https://github.com/nodejs/node/blob/main/doc/contributing/technical-priorities.md#webassembly) 6for the future success of Node.js. 7 8This document provides an overview of our high-level strategy for 9supporting WebAssembly and information about our current implementation 10as a starting point for contributors. 11 12## High-level approach 13 14The key elements of our WebAssembly strategy include: 15 16* Up-to-date core WebAssembly support 17* Support for high-level APIs 18* Making it easy to load WebAssembly 19* Making sure the core Node.js APIs are compatible with WebAssembly 20 and can be called in an efficient manner from WebAssembly 21 22### Up-to-date core WebAssembly support 23 24Node.js gets its core WebAssembly support through V8. We don't need 25to do anything specific to support this, all we have to do is keep 26the version of V8 as up-to-date as possible. 27 28### Key API support 29 30As a runtime, Node.js must implement a number of APIs in addition 31to the core WebAssembly support in order to be a good choice to run 32WebAssembly. The project has currently identified these additional 33APIs as important: 34 35* WebAssembly System Interface (WASI). This provides the ability for 36 WebAssembly to interact with the outside world. Node.js currently 37 has an implementation (see below for more details). 38* [WebAssembly Web API](https://www.w3.org/TR/wasm-web-api-1/). Node.js 39 currently has an implementation of streaming module compilation and 40 instantiation. As this and other specifications evolve, keeping up with them 41 will be important. 42* [WebAssembly Component Model](https://github.com/WebAssembly/component-model/). 43 This API is still in the definition stage but the project should 44 keep track of its development as a way to simplify native code 45 integration. 46 47### Making it as easy as possible to load WASM 48 49The most important thing we can do on this front is to either find and 50reference resources or provide resources on how to: 51 52* Compile your WebAssembly code (outside of Node.js) and integrate that 53 into an npm workflow. 54* Load and run WebAssembly code in your Node.js application. 55 56It is also important to support and track the ongoing work in ESM to enable 57loading of WebAssembly with ESM. 58 59### Making sure the core Node.js APIs are compatible with WebAssembly 60 61Use cases for which Node.js will be a good runtime will include code 62both in JavaScript and compiled into WebAssembly. It is important 63that Node.js APIs are able to be called from WebAssembly in 64an efficient manner without extra buffer copies. We need to: 65 66* Review APIs and identify those that can be called often from 67 WebAssembly. 68* Where appropriate, make additions to identified APIs to allow 69 a pre-existing buffer to be passed in order to avoid copies. 70 71## Current implementation and assets 72 73### WebAssembly System Interface (WASI) 74 75The Node.js WASI implementation is maintained in the 76[uvwasi](https://github.com/nodejs/uvwasi) repository in the 77Node.js GitHub organization. As needed, an updated copy 78is vendored into the Node.js deps in 79[deps/uvwasi](https://github.com/nodejs/node/tree/main/deps/uvwasi). 80 81In addition to the code from uvwasi, Node.js includes bindings and 82APIs that allow WebAssembly to be run with WASI support from Node.js. 83The documentation for this API is in 84[WebAssembly System Interface (WASI)](https://nodejs.org/api/wasi.html). 85 86The implementation of the bindings and the public API is in: 87 88* [src/node\_wasi.h](https://github.com/nodejs/node/blob/main/src/node_wasi.h) 89* [src/node\_wasi.cc](https://github.com/nodejs/node/blob/main/src/node_wasi.cc) 90* [lib/wasi.js](https://github.com/nodejs/node/blob/main/lib/wasi.js) 91