Alternative to v8 for exposing C++ objects to JavaScript (on PowerPC)

怎甘沉沦 提交于 2019-12-13 03:58:53

问题


I need to expose C++ classes (packed as shared libraries) to the magic world of JavaScript.

The most obvious solution is to use Node.js/v8. Problem is that it has to run on PowerPC (please no comments on this...) and - alas! - v8 doesn't run on PowerPC (the v8-powerpc project seems to be dead).

I'm trying to understand if there's any other viable solution, at the moment some possibilities are:

  1. emscripten, which converts LLVM bitcode into JavaScript;
  2. WebKit's JavaScriptCore, although I'm not sure it will work (I'll have WebKit on the PowerPC anyway)

I'm not a JavaScript expert and I actually feel quite lost, so these are my questions:

  1. Is emscripten a valid solution? (have you ever used it?)
  2. Can anyone point me to any documentation on how to expose C++ to JavaScript using JavaScriptCore?
  3. Is there any other option, and/or which one would you adopt?

Many thanks,

Rippel


回答1:


Qt has a port of webkit that runs on powerpc and it has a javascript engine that allows you to call C++ code.

Qt: Making Applications Scriptable




回答2:


You can use Emscripten. And I have used it and am using it. Problems are:

  • The JS/C community is IMO kind of suspicious/vary about Emscripten so you might not get much support there (usually the #emscripten IRC channel is pretty helpful).
  • Emscripten compiles code fairly easy/well but you need to have a decend understanding of C to get a working solution. You will probably have to rewrite certain parts of your code to get it working as expected by your JavaScript engine (stuff like using main_loop, callbacks, etc.).
  • Using Node.js you could also try to use the synchronous file api (see http://nodejs.org/api/fs.html) - but I fear you would have to change the Emscripten file access emulation, as it is mostly coded for Browser usage, right now.



回答3:


JavaScriptCore has JSObjectMakeFunctionWithCallback(). It looks like this potentially involves a lot of boilerplate code to convert arguments in and exceptions out, though.




回答4:


Now Node.js DOES run on PowerPC. See this github link (I think it runs on any system with a powerpc processor that runs linux.



来源:https://stackoverflow.com/questions/11157743/alternative-to-v8-for-exposing-c-objects-to-javascript-on-powerpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!