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

Detect runtime in code (js, dartvm, dartium) #3357

Closed
sethladd opened this issue Jun 1, 2012 · 15 comments
Closed

Detect runtime in code (js, dartvm, dartium) #3357

sethladd opened this issue Jun 1, 2012 · 15 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue library-core

Comments

@sethladd
Copy link
Contributor

sethladd commented Jun 1, 2012

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.

@lrhn
Copy link
Member

lrhn commented Jun 4, 2012

I'm wary at giving that information.
Currently the different platforms have different shortcomings, and I don't want users to write code that depends on, or codes around, these shortcomings based on the platform. Eventually the platforms should become mature enough that you shouldn't need to know the difference (at least between Dartium and dart2js, which should be indistinguishable).
I can see the need for detecting whether you are running in a browser or in the server VM, because that changes which libraries are available - but then, it might be more interesting to be able to check for the availability of a library.

@sethladd
Copy link
Contributor Author

sethladd commented Jun 4, 2012

I think determining if you are running in a browser or server VM is sufficient. This is indeed about library availability.

@whesse
Copy link
Contributor

whesse commented Jun 4, 2012

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.

@sethladd
Copy link
Contributor Author

sethladd commented Jun 4, 2012

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.

@sethladd
Copy link
Contributor Author

sethladd commented Feb 3, 2013

@DartBot
Copy link

DartBot commented Nov 8, 2013

This comment was originally written by [email protected]


As this method here now broke as well:

bool isDart() => js.scoped(() {
  try {
    // will throw exception if it doesn't exist
    var dartExists = js.context.navigator.webkitStartDart;
    return true;
  }
  on NoSuchMethodError {
    return false;
  }
});

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..

@sethladd
Copy link
Contributor Author

sethladd commented Nov 8, 2013

Try this:

identical(1, 1.0)

false in VM
true in dart2js

Obviously a hack, but it might work for you

@DartBot
Copy link

DartBot commented Nov 14, 2013

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.
It is like running "format c:" in a JVM to see if I am running on windows..

I think there are many interesting aspects that could be covered with a DartVM class that contains those information. For example:

  • intPrecision
  • doublePrecision
  • dartVM version (in case you write 2.0 code but the vm is just 1.0)
  • environmentType (isVM, isJS, isBrowser, isConsole)
  • canSpawnDart
  • canSpawnJavaScript

@DartBot
Copy link

DartBot commented Feb 24, 2014

This comment was originally written by [email protected]


Similar: https://code.google.com/p/dart/issues/detail?id=11642

@lrhn
Copy link
Member

lrhn commented Apr 30, 2014

There are no current plans to add information about the platform.
We should work to remove the differences, or make more specific information available (like canSpawnUri, not isVM). The former isn't future proof. If there end up being ten different implementations of Dart, we won't be able to expect the possible return values, and then we are back to user agent string parsing hell.
Feature detection, not platform detection.


Added Library-Core, NotPlanned labels.

@DartBot
Copy link

DartBot commented Apr 30, 2014

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:

  • There will be different versions of Dart with different level of language support
  • There might be different vendors
  • There will be different platforms
  • Not everyone can or wants to upgrade to the latest version
  • Each version from every vendor contains bugs

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.

@azenla
Copy link
Contributor

azenla commented Feb 4, 2015

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
Dart VM (Browser): -Dplatform=browser_vm
dart2js: -Dplatform=js

That would seriously make things easy.

bool get isServerVM => new String.fromEnvironment("platform") == "vm";
bool get isBrowserVM => new String.fromEnvironment("platform") == "browser_vm";
bool get isDart2JS => new String.fromEnvironment("platform") == "js";

The name 'platform' could be changed if needed.

@DartBot
Copy link

DartBot commented Mar 11, 2015

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:

dart-gde/chrome.dart#215

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.

@DartBot
Copy link

DartBot commented Mar 11, 2015

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.

@sethladd sethladd added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core closed-not-planned Closed as we don't intend to take action on the reported issue labels Mar 11, 2015
@jtmcdole
Copy link
Contributor

Note; path has a neat way of working around this.

copybara-service bot pushed a commit that referenced this issue Mar 29, 2022
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]>
copybara-service bot pushed a commit that referenced this issue Mar 29, 2022
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]>
copybara-service bot pushed a commit that referenced this issue Mar 30, 2022
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]>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue library-core
Projects
None yet
Development

No branches or pull requests

6 participants