Skip to content
Alon Zakai edited this page Apr 17, 2014 · 23 revisions

WebIDL Binder

The WebIDL binder is the third tool providing bindings glue between C++ and JS in Emscripten. The first was the "bindings generator", which was a hackish experiment (despite its hackishness, it managed to be good enough for ammo.js and box2d.js). The second was Embind, which is fairly high-level and supports mapping sophisticated C++11 constructs between C++ and JS.

The goals of the WebIDL binder is to be low-level, efficient, and simpler than Embind, while robust and more maintainable than the bindings generator. Like Embind, it requires explicit declarations of what to bind together, but like the bindings generator, it does so at a low-level which is simpler to optimize.

The level at which it works is WebIDL, a language used to describe the interfaces between JS and the browser's native code in C++. WebIDL was designed for the particular purpose of gluing together C++ and JS, so it is a natural choice here; also, there are lots of already-written WebIDL files for browser APIs, which could eventually be reused.

The WebIDL binder is currently focused on wrapping C++ code so it is usable from JS (write a C++ class, use it as a library in JS as if it were a normal JS library), which is what the bindings generator does. Embind also supports wrapping in the other direction, which the WebIDL binder might do some day. In particular, it should be easy to let C++ call web APIs in a natural way by using WebIDL files describing those APIs.

Wrapping a C++ class