Question on compiling dart2js using dart2js

134 views
Skip to first unread message

Thomas

unread,
Jun 22, 2015, 6:23:57 AM6/22/15
to compil...@dartlang.org
Hej,

I have question on using dart2js. When I try to compile dart2js using dart2js
I end up with an exception when running the generated javascript output.

For compilation I am using:

   dart2js --package-root=out/ReleaseX64/packages --categories=Server --library-root=out/ReleaseX64/dart-sdk pkg/compiler/lib/src/dart2js.dart

where out/ReleaseX64 is the built directory for the dart project. This works
well and generates a javascript file, which I atferwards concatenate with the
d8 preamble file:

   cat out/ReleaseX64/dart-sdk/lib/_internal/compiler/js_lib/preambles/d8.js >> main.js
   cat out.js >> main.js

However, when trying to execute the resulting javascript file afterwards
using nodejs, I get the following exception:

    The compiler crashed: Unsupported operation: Platform._operatingSystem 
    Unsupported operation: Platform._operatingSystem
        at dart.wrapException (/home/thomas/Schreibtisch/main.js:3170:15)
        at dart._Platform__operatingSystem (/home/thomas/Schreibtisch/main.js:18786:13)
        at dart._Platform_operatingSystem (/home/thomas/Schreibtisch/main.js:18798:14)
        at t1.fixed$length (/home/thomas/Schreibtisch/main.js:113579:12)
        at Isolate.prototype.(anonymous function) (/home/thomas/Schreibtisch/main.js:114206:40)
        at t1.fixed$length (/home/thomas/Schreibtisch/main.js:113583:5)
        at Isolate.prototype.(anonymous function) (/home/thomas/Schreibtisch/main.js:114206:40)
        at dart.uriPathToNative (/home/thomas/Schreibtisch/main.js:50768:12)
        at dart.internalMain (/home/thomas/Schreibtisch/main.js:28971:16)
        at dart.main (/home/thomas/Schreibtisch/main.js:28965:7)

    /home/thomas/Schreibtisch/main.js:263
              throw e;
                    ^
    Unsupported operation: ProcessUtils._exit
        at dart.wrapException (/home/thomas/Schreibtisch/main.js:3170:15)
        at dart._ProcessUtils__exit (/home/thomas/Schreibtisch/main.js:18810:13)
        at dart.exit (/home/thomas/Schreibtisch/main.js:18813:7)
        at internalMain_onError.dart.internalMain_onError.call$2 (/home/thomas/Schreibtisch/main.js:29401:20)
        at dart.internalMain (/home/thomas/Schreibtisch/main.js:28980:22)
        at dart.main (/home/thomas/Schreibtisch/main.js:28965:7)
        at startRootIsolate_closure.dart.startRootIsolate_closure.call$0 (/home/thomas/Schreibtisch/main.js:2052:30)
        at _IsolateContext.dart._IsolateContext.eval$1 (/home/thomas/Schreibtisch/main.js:2234:23)
        at dart.startRootIsolate (/home/thomas/Schreibtisch/main.js:1911:19)
        at /home/thomas/Schreibtisch/main.js:114294:9

I am surely doing something wrong and would appreciate help in pointing out what.
I am using an Ubuntu with dart (revision 4501) and node js v0.10.25 installed.

Thanks a lot and kind regards
Thomas Heinze

Peter Ahé

unread,
Jun 22, 2015, 6:31:18 AM6/22/15
to t.hein...@gmail.com, compil...@dartlang.org
The way you compile dart2js relies on dart:io. We haven't designed dart:io to run on JavaScript platforms, and D8, for example, doesn't provide enough features to really support running dart2js. Using --categories=Server mostly generates code that doesn't work.

So what I would recommend that you do instead is to use --categories=Client and write your own CompilerInputProvider, CompilerOutputProvider, DiagnosticHandler, and PackagesDiscoveryProvider and use them together with compile in package:compiler/compiler.dart. We do this in a bunch of tests, and also in the old version of try.dartlang.org which ran dart2js in the browser.


Notice, however, that this test doesn't provide a PackagesDiscoveryProvider, but hopefully it shouldn't be too hard implementing one of those.

A challenge you will face is interfacing to native functions. In theory, you can use dart:js for that, but its implementation in dart2js is rather dependent on running in a browser.

On Mon, Jun 22, 2015 at 12:17 PM <t.hein...@gmail.com> wrote:
Hej,

I am trying to run the dart2js compiler with dart2js as input. So far, I succeeded in running the compiler,
which also generates its output, but I am afterwards not able to run the javascript executable.

For running the compiler I am using:

> dart2js --package-root=out/ReleaseX64/packages --categories=Server --library-root=out/ReleaseX64/dart-sdk pkg/compiler/lib/src/dart2js.dart

where out/ReleaseX64 is the built directory for the dart project.

This generates the javascript output, which I then concatenate with a preamble file (d8.js).
However, when I then try to execute the resulting file using a d8 standalone shell:

> cat d8.js >> main.js
> cat out.js >> main.js
> js main.js

I am getting the following error:
I am getting a similar error when using the jsshell preamble file. I am using an Ubuntu system
with dart (revision 4501) and node js v0.10.25. I think I miss something, but I do not know
what.

Anyone can help ? Thanks a lot !

Kind regards
Thomas Heinze

To unsubscribe from this group and stop receiving emails from it, send an email to compiler-dev...@dartlang.org.

Günter Zöchbauer

unread,
Jun 22, 2015, 6:31:37 AM6/22/15
to compil...@dartlang.org
Seems you are transpiling a command line application (which imports dart:io). There is no way to execute such instructions in JS 
Reply all
Reply to author
Forward
0 new messages