使用并行数组赋值与therubyracer

时间:2016-07-10 05:48:47

标签: javascript ruby-on-rails-4 v8 therubyracer

在调用V8 :: Context#load时,therubyracer会抱怨

Unexpected token [ at /home/dm/contra/app/assets/javascripts/libfigure/figure.js:120:10

最终在此函数中间为var [ who

function allemande_orbit_view(move,pvs) {
    var who = pvs[0]
    var [ who, dir, inner_angle, outer_angle, beats] = pvs
    var [swho,sdir,sinner_angle,souter_angle,sbeats] = parameter_strings(move, pvs)
...

它抱怨使用解构数组赋值,如下所示:

var [a,b] = [5,6]

我发现V8的更高版本支持此版本(Array destructuring assignment not working in v8 with harmony option in Node.js),但如果我将gem 'libv8', '~> 5.1', '>= 5.1.281.59.1'放入Gemfile,那么捆绑商会告诉我要关闭:

Bundler could not find compatible versions for gem "libv8":
  In Gemfile:
    libv8 (>= 5.1.281.59.1, ~> 5.1)

    therubyracer was resolved to 0.12.2, which depends on
      libv8 (~> 3.16.14.0)

我查看了therubyracer github页面,并查看一年前的最新更新,然后才看到v8 4.5,看起来效果不佳。

Sooo ....我想我已经在升级V8了,对吧?

任何人都知道如何将--harmony_restructuring标志传递给现有的V8?

1 个答案:

答案 0 :(得分:2)

libv8 maintainer here.

Unfortunately therubyracer is incompatible with versions of V8 greater than 3.16 at this point.

If you are using it just as a JS runtime for asset compilation you should consider switching to the brand new mini_racer instead.

As a side note, you should consider asking the maintainers of a project directly first, through their issue tracker for example, before shooting a question in SO. Your question probably would have remained unanswered had I not been by chance looking for recent questions about libv8 here.