-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Detect runtime in code (js, dartvm, dartium) #3357
Comments
I'm wary at giving that information. |
I think determining if you are running in a browser or server VM is sufficient. This is indeed about library availability. |
But you currently can't use that knowledge at run time to conditionally include libraries, because libraries must be imported at compile time, not at run time. I think it is very important to maintain the property that all the source is known at compile time, rather than allowing code to included dynamically. So we really need ways to write code for the browser and code for the standalone VM, and allow this code to share all of the common code and include the platform-specific code for the right platform, at deployment time. A really simple base case for this problem would be to allow a cross-platform Timer, which would be implemented by Timer on dart:io and setTimeout on dart:html. There are good reasons why it is difficult to create the same timer interface on both platforms, but if someone wants a least-common-denominator shared class, to use in their code, they should be able to create one. So, we need a way to change Dart code based on the configuration, but this need is at deployment time, not at run time. I think the package manager is supposed to help with this. |
Thanks Bill. We'd love to see a Timer interface that works where Dart works. Perhaps John can elaborate on what his use cases are for this issue. |
This comment was originally written by [email protected] As this method here now broke as well: bool isDart() => js.scoped(() { I am really in favor of putting something stable into the API. Another reason for the need to know whether you're running in VM or not is spawnURI. If you run in a VM you can spawnURI a dart script, while when running in JS, you need to spawn a JS script.. |
Try this: identical(1, 1.0) false in VM Obviously a hack, but it might work for you |
This comment was originally written by [email protected] Seth, I switched to that. But exploiting bugs is not a good way to determine whether something is running in dart2js or native on a VM. I think there are many interesting aspects that could be covered with a DartVM class that contains those information. For example:
|
This comment was originally written by [email protected] Similar: https://code.google.com/p/dart/issues/detail?id=11642 |
There are no current plans to add information about the platform. Added Library-Core, NotPlanned labels. |
This comment was originally written by [email protected] All proper languages that I am aware of have a mechanism to detect something about the environment in a clean way. Not including this in Dart is simply ignorant. The facts are:
While a good language combined with a good VM makes it almost unnecessary to detect what platform something is running on, like with Java, it sometimes is even on those platforms necessary to detect it. Be it to work around a specific bug in a specific version or to work around an issue about a certain platform. |
I would like to propose that there be a simple environment flag (-Dx=y) set on each platform. Like this: Dart VM (Server): -Dplatform=vm That would seriously make things easy. bool get isServerVM => new String.fromEnvironment("platform") == "vm"; The name 'platform' could be changed if needed. |
This comment was originally written by [email protected] Bluetooth on Linux is buggy. Right now, I need to disable bt support on Dartium Linux otherwise it crashes hard. Specifically this bug here: Until such time Google can guarantee ALL FEATURES are always 100% stable on all platforms, users will need a way to look at even some basic platform information and gracefully degrade their app. Otherwise, it just freaking crashes, and makes all other app development halt. |
This comment was originally written by [email protected] Also given that different chrome/dart versions may have bugs, being able to blacklist/degrade/workaround features/bugs on a given platform is absolutely needed to guarantee a good user experience. |
Note; path has a neat way of working around this. |
Changes: ``` > git log --format="%C(auto) %h %s" 8f5ab7b..94ae66a https://dart.googlesource.com/pub.git/+/94ae66a6 Refine what a relative uri means in a git path (#3212) https://dart.googlesource.com/pub.git/+/cc4c1292 Only call Package.listFiles once per publish. (#3346) https://dart.googlesource.com/pub.git/+/f4484073 Fix test/global/activate/git_package_test test on windows (#3361) https://dart.googlesource.com/pub.git/+/610ce7f2 Refactor descriptors (#3305) https://dart.googlesource.com/pub.git/+/953b6097 Substitute pub.dartlang.org for of pub.dev (#3358) https://dart.googlesource.com/pub.git/+/7a6ea396 Add support for pubspec overrides file (#3215) https://dart.googlesource.com/pub.git/+/8abfed9d Global activate git path and ref (#3356) https://dart.googlesource.com/pub.git/+/d1c0e3f9 Revert "Add flag controlling creation of `.packages` file. (#2757)" (#3357) https://dart.googlesource.com/pub.git/+/274f5ad9 Fix signals test (#3359) https://dart.googlesource.com/pub.git/+/83437005 Avoid failing in gitignore validator (#3354) https://dart.googlesource.com/pub.git/+/3082796f dependency_services: Don't download archives on apply (#3352) https://dart.googlesource.com/pub.git/+/48d0ffaf dependency_services: Use ^ constraints for widened intervals when possible (#3349) https://dart.googlesource.com/pub.git/+/826e2086 Remove obsolete test (#3347) https://dart.googlesource.com/pub.git/+/35e5140b Bump analyzer from 2.8.0 to 3.3.1 (#3341) https://dart.googlesource.com/pub.git/+/52f2bdc2 Enable dependabot (#3340) https://dart.googlesource.com/pub.git/+/1e70c0c7 Remove `uploader` command (#3335) https://dart.googlesource.com/pub.git/+/3174a264 Warn if git version is not high enough for supporting all features (#3332) https://dart.googlesource.com/pub.git/+/3f7a3cb7 Don't analyze ignored directories in directory-validator (#3331) https://dart.googlesource.com/pub.git/+/e8f36614 Allow use of token for talking to pub.dev (#3330) https://dart.googlesource.com/pub.git/+/b93bf88f Upgrade `package:tar` to version `0.5.4`. (#3313) https://dart.googlesource.com/pub.git/+/fbc9732e Support for different versioning strategies in dependency_services (#3320) https://dart.googlesource.com/pub.git/+/93c7cfcd Update repository-spec-v2.md (#3311) https://dart.googlesource.com/pub.git/+/941191f7 dependency_services (#3304) https://dart.googlesource.com/pub.git/+/61175cb6 fix: relative to the current directory rules (#3297) https://dart.googlesource.com/pub.git/+/f27e90d3 Upgrade other versions conservatively with --major-versions (#3295) https://dart.googlesource.com/pub.git/+/a2461417 Add flag controlling creation of `.packages` file. (#2757) ``` Diff: https://dart.googlesource.com/pub.git/+/8f5ab7b1aba3b9f66b56246d77e167990339d317~..94ae66a660cc187cc46ceaf1ab96bdcf8d48a313/ Change-Id: I121fa281ad77991ef10938a3c228ce1d62e748db Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238901 Reviewed-by: Jonas Jensen <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
This reverts commit 6e00bb1. Reason for revert: https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/flutter-engine-linux/16089/overview Original change's description: > Bump pub to 94ae66a660cc187cc46ceaf1ab96bdcf8d48a313 > > Changes: > ``` > > git log --format="%C(auto) %h %s" 8f5ab7b..94ae66a > https://dart.googlesource.com/pub.git/+/94ae66a6 Refine what a relative uri means in a git path (#3212) > https://dart.googlesource.com/pub.git/+/cc4c1292 Only call Package.listFiles once per publish. (#3346) > https://dart.googlesource.com/pub.git/+/f4484073 Fix test/global/activate/git_package_test test on windows (#3361) > https://dart.googlesource.com/pub.git/+/610ce7f2 Refactor descriptors (#3305) > https://dart.googlesource.com/pub.git/+/953b6097 Substitute pub.dartlang.org for of pub.dev (#3358) > https://dart.googlesource.com/pub.git/+/7a6ea396 Add support for pubspec overrides file (#3215) > https://dart.googlesource.com/pub.git/+/8abfed9d Global activate git path and ref (#3356) > https://dart.googlesource.com/pub.git/+/d1c0e3f9 Revert "Add flag controlling creation of `.packages` file. (#2757)" (#3357) > https://dart.googlesource.com/pub.git/+/274f5ad9 Fix signals test (#3359) > https://dart.googlesource.com/pub.git/+/83437005 Avoid failing in gitignore validator (#3354) > https://dart.googlesource.com/pub.git/+/3082796f dependency_services: Don't download archives on apply (#3352) > https://dart.googlesource.com/pub.git/+/48d0ffaf dependency_services: Use ^ constraints for widened intervals when possible (#3349) > https://dart.googlesource.com/pub.git/+/826e2086 Remove obsolete test (#3347) > https://dart.googlesource.com/pub.git/+/35e5140b Bump analyzer from 2.8.0 to 3.3.1 (#3341) > https://dart.googlesource.com/pub.git/+/52f2bdc2 Enable dependabot (#3340) > https://dart.googlesource.com/pub.git/+/1e70c0c7 Remove `uploader` command (#3335) > https://dart.googlesource.com/pub.git/+/3174a264 Warn if git version is not high enough for supporting all features (#3332) > https://dart.googlesource.com/pub.git/+/3f7a3cb7 Don't analyze ignored directories in directory-validator (#3331) > https://dart.googlesource.com/pub.git/+/e8f36614 Allow use of token for talking to pub.dev (#3330) > https://dart.googlesource.com/pub.git/+/b93bf88f Upgrade `package:tar` to version `0.5.4`. (#3313) > https://dart.googlesource.com/pub.git/+/fbc9732e Support for different versioning strategies in dependency_services (#3320) > https://dart.googlesource.com/pub.git/+/93c7cfcd Update repository-spec-v2.md (#3311) > https://dart.googlesource.com/pub.git/+/941191f7 dependency_services (#3304) > https://dart.googlesource.com/pub.git/+/61175cb6 fix: relative to the current directory rules (#3297) > https://dart.googlesource.com/pub.git/+/f27e90d3 Upgrade other versions conservatively with --major-versions (#3295) > https://dart.googlesource.com/pub.git/+/a2461417 Add flag controlling creation of `.packages` file. (#2757) > > ``` > > Diff: https://dart.googlesource.com/pub.git/+/8f5ab7b1aba3b9f66b56246d77e167990339d317~..94ae66a660cc187cc46ceaf1ab96bdcf8d48a313/ > Change-Id: I121fa281ad77991ef10938a3c228ce1d62e748db > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238901 > Reviewed-by: Jonas Jensen <[email protected]> > Commit-Queue: Sigurd Meldgaard <[email protected]> [email protected],[email protected] Change-Id: I2402e8647ad79a613d8be55a85a7f05f511a4081 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239301 Reviewed-by: Sigurd Meldgaard <[email protected]> Reviewed-by: Jonas Jensen <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
Changes: ``` > git log --format="%C(auto) %h %s" 8f5ab7b..a3a102a https://dart.googlesource.com/pub.git/+/a3a102a5 Fix equality and hashcode for the sdk descriptors (#3367) https://dart.googlesource.com/pub.git/+/94ae66a6 Refine what a relative uri means in a git path (#3212) https://dart.googlesource.com/pub.git/+/cc4c1292 Only call Package.listFiles once per publish. (#3346) https://dart.googlesource.com/pub.git/+/f4484073 Fix test/global/activate/git_package_test test on windows (#3361) https://dart.googlesource.com/pub.git/+/610ce7f2 Refactor descriptors (#3305) https://dart.googlesource.com/pub.git/+/953b6097 Substitute pub.dartlang.org for of pub.dev (#3358) https://dart.googlesource.com/pub.git/+/7a6ea396 Add support for pubspec overrides file (#3215) https://dart.googlesource.com/pub.git/+/8abfed9d Global activate git path and ref (#3356) https://dart.googlesource.com/pub.git/+/d1c0e3f9 Revert "Add flag controlling creation of `.packages` file. (#2757)" (#3357) https://dart.googlesource.com/pub.git/+/274f5ad9 Fix signals test (#3359) https://dart.googlesource.com/pub.git/+/83437005 Avoid failing in gitignore validator (#3354) https://dart.googlesource.com/pub.git/+/3082796f dependency_services: Don't download archives on apply (#3352) https://dart.googlesource.com/pub.git/+/48d0ffaf dependency_services: Use ^ constraints for widened intervals when possible (#3349) https://dart.googlesource.com/pub.git/+/826e2086 Remove obsolete test (#3347) https://dart.googlesource.com/pub.git/+/35e5140b Bump analyzer from 2.8.0 to 3.3.1 (#3341) https://dart.googlesource.com/pub.git/+/52f2bdc2 Enable dependabot (#3340) https://dart.googlesource.com/pub.git/+/1e70c0c7 Remove `uploader` command (#3335) https://dart.googlesource.com/pub.git/+/3174a264 Warn if git version is not high enough for supporting all features (#3332) https://dart.googlesource.com/pub.git/+/3f7a3cb7 Don't analyze ignored directories in directory-validator (#3331) https://dart.googlesource.com/pub.git/+/e8f36614 Allow use of token for talking to pub.dev (#3330) https://dart.googlesource.com/pub.git/+/b93bf88f Upgrade `package:tar` to version `0.5.4`. (#3313) https://dart.googlesource.com/pub.git/+/fbc9732e Support for different versioning strategies in dependency_services (#3320) https://dart.googlesource.com/pub.git/+/93c7cfcd Update repository-spec-v2.md (#3311) https://dart.googlesource.com/pub.git/+/941191f7 dependency_services (#3304) https://dart.googlesource.com/pub.git/+/61175cb6 fix: relative to the current directory rules (#3297) https://dart.googlesource.com/pub.git/+/f27e90d3 Upgrade other versions conservatively with --major-versions (#3295) https://dart.googlesource.com/pub.git/+/a2461417 Add flag controlling creation of `.packages` file. (#2757) ``` Diff: https://dart.googlesource.com/pub.git/+/8f5ab7b1aba3b9f66b56246d77e167990339d317~..a3a102a549388a6dbfecc9252fabb618f9a2f5f7/ Change-Id: I8d0ea375039ea450d397871d9fac35d590ea8869 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239315 Reviewed-by: Jonas Jensen <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
It would help to know which runtime the Dart program is running in. Options might be JavaScript, Dart VM in Dartium, Dart VM on command line.
The text was updated successfully, but these errors were encountered: