Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart2js generates code which handles command line arguments incorrectly #16779

Closed
DartBot opened this issue Feb 12, 2014 · 6 comments
Closed
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@DartBot
Copy link

DartBot commented Feb 12, 2014

This issue was originally filed by markovuksan...@gmail.com


What steps will reproduce the problem?

  1. Use the following code as an example:
    void main(List<String> args) {
      args.forEach((arg) => print('Argument: ${arg}'));
    }
  2. Run as regular dart application. When running pass in some arguments (i.e. dart bin/dartlang_args_test.dart test).
  3. The output should be:
    Argument: test
  4. Use dart2js to get a js version of the code. (dart2js --categories=Server bin/dartlang_args_test.dart)
  5. run the js file using node, and pass parameters. (i.e. node out.js test, where out.js is ouput from previous step)
  6. There is no ouput

What is the expected output?
At step should be same as step three.

What do you see instead?
Nothing

What version of the product are you using? On what operating system?
Dart VM version: 1.2.0-edge.32628 (Thu Feb 13 08:58:25 2014) on "macos_ia32"

Please provide any additional information below.
This also happens with version 1.1.3

@DartBot
Copy link
Author

DartBot commented Feb 12, 2014

This comment was originally written by markovuksan...@gmail.com


Here's link to gist with code used in the example: https://gist.github.com/markovuksanovic/8966280

@kevmoo
Copy link
Member

kevmoo commented Feb 13, 2014

Added Area-Dart2JS, Triaged labels.

@floitschG
Copy link
Contributor

This is a node-specific API and we would rather not include it in dart2js.

However: the main-call can already be intercepted by providing a 'dartMainRunner'. It currently doesn't support arguments, but that can easily be fixed. You could then have a separate file that you prefix to dart2js' output:

===
function dartMainRunner(main) {
  main(process.argv.slice(1));
}
===

Fwiw: we are discussing similar "pre-load" scripts for d8 and jsshell to reduce the size of the js file for web-applications.

@floitschG
Copy link
Contributor

Starting with r32740 we now support the dartMainRunner as described in my previous comment. In fact the dartMainRunner is now invoked with the original arguments (currently always "[]") and should forward them (or provide new ones) to the main function.

===
function dartMainRunner(main, args) {
  if (args.length != 0) throw "Non-zero arguments";
  main(process.argv.slive(1));
}

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
@joshualitt
Copy link
Contributor

Closing, as we are unlikely to do more work on this unless there is great demand.

@rakudrama
Copy link
Member

I would say this issue is fixed by cc3c701

dart2js emits a conversion stub when main takes a single argument with type List<String>.
The conversions stub copies the input JavaScript Array to a Dart List<String>.
The version of main passed to dartMainRunner includes this conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

6 participants