Monday, February 9, 2015

Moving PLV8 to ECMAScript6

Taras Mitran has just published a blog post about using some of the advanced features of ECMAScript version 6 to make programming with SQL in JavaScript nicer.

He notes that Template Strings allow for multiline strings, which is in itself a significant advance, and that you can also have Tagged Template Strings which can transform the Template String automagically in many interesting ways. His example turns a Template String with embedded variables into a preparable query with a list of parameters. It's very nifty, quite clever in fact.

The other feature that I would really like is proper lexically scoped variables. Perl got these donkeys years ago, and their absence this long in JavaScript has been reprehensible. They are provided for in ES 6.

My understanding is that to get these features we need to provide for PLV8 to build against the latest version of V8 (and possibly provide some initialization flags too.) Unfortunately, the V8 API seems to have changed significantly since the that's available on my Fedora 20 workstation, so enabling it to build with, say, V8 version, which is what io.js is using, will take quite a bit of work, probably by someone whose C++-fu is greater than mine.


  1. I've prepared a set of changes to compile plv8 against a recent version of V8 (tested with, and committed them to a repo clone ( on google code for further testing and review.
    It's not immediately crashing and my existing js funcs are working fine. But it definitely needs some further testing to check if the whole handles stuff is implemented correctly.
    Next step would be deciding on how to enable the ES6 language features. One option would be the node way (a bunch of harmony flags), another a new dialect with a certain feature set much like io.js is doing.

  2. This comment has been removed by the author.

  3. Kai, nice work! With V8 there is no need to enable any of the ES6 language features. This particular version of V8 already ships with several ES6 features enabled by default without requiring any additional harmony flag - those should be left for experimental / in-progress features only, which plv8 probably doesn't need for now.