dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.56k forks source link

Allow spawning an isolate for a library #12611

Open munificent opened 11 years ago

munificent commented 11 years ago

Currently, if you spawn an isolate in the standalone VM given a URL to a Dart library with no main(), you get:

in ShutdownIsolate: Unable to resolve function 'main' in library 'file:///.../plugin.dart'.

And the app terminates.

For plug-ins, the typical pattern is to load code dynamically and then use reflection/mirrors to determine what to invoke instead of relying on a fixed entrypoint. To get around this in the dev server, we currently procedurally create a temporary Dart script that has a no-op main() method and imports the real library. Then we save that to a temp directory and use that URL to spawn the isolate. That's obviously pretty gross.

Instead, I'm thinking something like:

    SendPort spawnIsolate(String url, {bool invokeMain: true});

If invokeMain is false, it just loads the isolate without calling main() (whether or not it's there).

Note that I only need this to work in the standalone VM, so my need isn't gated on dart2js or Dartium support for it.

nex3 commented 11 years ago

This also presupposes a way to invoke functions/create classes in the isolate. [mirrorSystemOf] may accomplish this.

munificent commented 11 years ago

Right, I'm assuming mirrorSystemOf() will cover this and work as advertised. If it doesn't, we'll file more bugs. :)

nex3 commented 11 years ago

Marked this as being blocked by #12614.

anders-sandholm commented 10 years ago

Added Area-Library label.