Filtered by Tag: embedding

Code-generating Away the Boilerplate in Our Migration Back to Spidermonkey

| | c++ metaprogramming embedding javascript

If creativity emerges from constraint, then embedding a JavaScript engine into your database server is a recipe for creativity.

We’ve worked with the internals of a lot of different JavaScript engines, and one thing stands out: JavaScript is hard to embed for anything but the most trivial uses. To do it well, without writing a ton of mind-numbing and maintenance-hostile duplicode, we had to use a wide slice of the code-generating capabilities of C++ in concert. In our most recent migration from the V8 engine back to SpiderMonkey, we eliminated boilerplate by:

  • Generating callbacks with unique template instantiations
  • Implementing type integrations through policy based class design
  • Generating callbacks with constrained method invocation with compile time type lists
  • Utilizing a Lippincott function to provide C++ and Javascript exception interchangeability

I’ve put together a compiling walkthrough of these techniques in use, but before we get there, an examination of the prevailing context is in order...