-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The kernel reader seems to compute the root library by looking for the library that has the 'main' symbol, this may not be the case always (main just needs to exist in the exported namespace or it could also just be a top level getter that returns a function).
When loading from a source the VM uses the script url of the specified application to set as the root library but this scheme fails when a '.dill' file is specified directly on the command line. It would be nice if the kernel format stored the root script url in the file so this can be determined reliably.
The root library should be the library corresponding to the script that is specified for execution.
This causes problems in some of the Dart test cases which test this and also is an issue when we try to execute unit test cases that do not have a 'main' even after we added an option in the front end to not require a 'main'.
per spec -
A script is a library whose exported namespace (18.2) includes a top-level
member named main. It is a static warning if the static type of main is not
assignable to a function type or is a function type with more than two required
parameters.
A script S may be executed as follows:
First, S is compiled as a library as specified above. Then, the top-level
function main that is in the exported namespace of S is invoked. If main has no
positional parameters, it is invoked with no arguments. Otherwise if main has
exactly one positional parameter, it is invoked with a single actual argument
whose runtime type implements List. Otherwise main is invoked with
the following two actual arguments:
- An object whose runtime type implements List.
- The initial message of the current isolate i as determined by the invocation
of Isolate.spawnUri that spawned i.
It is a run time error if S does not declare or export either:
• A top-level function named main, or
• A top-level getter named main that returns a function.
Note that if main requires more than two arguments, a run time error will occur.
The names of scripts are optional, in the interests of interactive, informal
use. However, any script of long term value should be given a name as a matter
of good practice.
A Dart program will typically be executed by executing a script.