PINF JavaScript Loader support for v8cgi

9 views
Skip to first unread message

Christoph Dorn

unread,
Sep 28, 2011, 7:50:58 PM9/28/11
to v8...@googlegroups.com
I am pleased to say I was able to add initial support [2] for v8cgi to the PINF JavaScript Loader [1] in a matter of 15 minutes!

There is the beginnings of a demo project containing various programs that can run cross-platform here:

  https://github.com/pinf/test-programs-js

NOTE: The `commonjs --platform <PlatformAlias>` platform selection does not work yet. See: https://github.com/pinf/loader-js/blob/master/pinf-loader.sh **Help with the sh script would be appreciated!**

To run the two demo programs that work on v8cgi use the following commands.
Get the PINF JavaScript Loader:

  cd ~/
  wget -O pinf-loader-js.tar.gz https://github.com/pinf/loader-js/tarball/master
  tar -zxf pinf-loader-js.tar.gz
  mv pinf-loader-js-* pinf-loader-js
  cd pinf-loader-js 
Download the dependencies for the demo programs using NodeJS (this will work with
v8cgi natively once the adapter is complete):

    node ./pinf-loader.js -v https://github.com/pinf/test-programs-js/zipball/master HelloWorld
    node ./pinf-loader.js -v https://github.com/pinf/test-programs-js/zipball/master AdditionalLoad

You can now run the demos:

   
v8cgi ./pinf-loader.js -v https://github.com/pinf/test-programs-js/zipball/master HelloWorld
   
v8cgi ./pinf-loader.js -v https://github.com/pinf/test-programs-js/zipball/master AdditionalLoad

Drop the "-v" to only get the script output.

It would be great if someone could try this out and let me know if it works for them.

To be able to download dependencies when running on `v8cgi` (instead of using `node`) the v8cgi adapter [3] must be completed to the level of the node adapter [4].

Thanks!

Christoph

[1] - https://github.com/pinf/loader-js/commit/37f855ad30dbdbdfb352d3728f90218f8b7bce90
[2] - https://github.com/pinf/loader-js
[3] - https://github.com/pinf/loader-js/blob/master/lib/pinf-loader-js/adapter/v8cgi.js
[4] - https://github.com/pinf/loader-js/blob/master/lib/pinf-loader-js/adapter/node.js

Ondřej Žára

unread,
Sep 29, 2011, 1:55:29 AM9/29/11
to v8...@googlegroups.com
Hi Christoph,

this is great news! I will try your samples soon; I may also look into the v8cgi adapter to improve its functionality. Let me ask some questions regarding this adapter:

1) what API must be implemented in order to offer complete functionality?
2) are there any unit tests for the adapter?
3) what do you mean by "global require" (https://github.com/pinf/loader-js/blob/master/lib/pinf-loader-js/adapter/v8cgi.js#L17) and what is its purpose in the adapter?



Thanks,
Ondrej



2011/9/29 Christoph Dorn <chri...@christophdorn.com>

--
You received this message because you are subscribed to the Google Groups "v8cgi" group.
To post to this group, send email to v8...@googlegroups.com.
To unsubscribe from this group, send email to v8cgi+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/v8cgi?hl=en.

Christoph Dorn

unread,
Sep 29, 2011, 3:26:57 AM9/29/11
to v8...@googlegroups.com
Ondřej Žára
28 September, 2011 10:55 PM

1) what API must be implemented in order to offer complete functionality?
See link [4].
2) are there any unit tests for the adapter?
No unit tests yet for adapters but there are use-case tests for the loader you can use. You can run the HelloWorld program until it succeeds without downloading dependencies via node first. Just delete the ./.pinf_packages folder. You should get NYI errors from the adapter until it runs through.

Once that HelloWorld program works you can run a bunch of different tests from ./demos/ in the github.com/pinf/loader-js repo. See "Portable" at https://github.com/pinf/loader-js/blob/master/docs/Demos.md

To get commonjs --platform c8cgi working the sh script needs to be fixed. See https://github.com/pinf/loader-js/blob/master/pinf-loader.sh
I don't know bash well enough to wrestle with that. It should locate the binary on the OS and use that instead of node.

3) what do you mean by "global require" (https://github.com/pinf/loader-js/blob/master/lib/pinf-loader-js/adapter/v8cgi.js#L17) and what is its purpose in the adapter?
The platform require is used by the loader to load platform-native modules. This allows you to map platform-native modules to a require-prefix in a package (CommonJS/Mappings/C).

The global require is something that GPSEE has but is not necessarily required. I think the only difference is the context. Rather than having the context of the module it is called from it has a global context without an attachment to a file/module (Wes can confirm). I am using it because I load modules on behalf of other modules using the platformRequire function so the calling context does not matter anyway (or rather I don't have a means to pass it on to the global require - this may help with debugging and stack traces if working though, not sure yet).

If you get the adapter completed, v8cgi will be the second (after node) to have support for asynchronously downloading package dependencies meaning you can boot entire JavaScript programs from a URL.

We can then try and get the CanvasGraphics demo working on v8cgi by wiring up a JSGI interface for node and v8cgi which I have working for jetpack already (and get rid of node connect which the demo is currently using). This is very interesting because you could then run the PINF Program Server in the v8cgi apache module and dynamically serve programs from disk resolving all dependencies as needed without the need to run a development server outside of apache. This would be a great way for newcomers to play with CommonJS packages, dependencies and modules without needing to understand a lot of pieces.

Very exiting!

Christoph




Christoph Dorn
28 September, 2011 4:50 PM

Christoph Dorn

unread,
Sep 29, 2011, 6:39:05 PM9/29/11
to v8...@googlegroups.com
Christoph Dorn wrote:
>
> To get commonjs --platform c8cgi working the sh script needs to be
> fixed. See https://github.com/pinf/loader-js/blob/master/pinf-loader.sh
> I don't know bash well enough to wrestle with that. It should locate
> the binary on the OS and use that instead of node.
This is now fixed (pinf/loader-js/v0.2.11) so you can select the v8cgi
platform via `commonjs --platform v8cgi ...`.

Christoph

Reply all
Reply to author
Forward
0 new messages