Chromium Code Reviews| Index: pkg/path/lib/path.dart |
| diff --git a/pkg/path/lib/path.dart b/pkg/path/lib/path.dart |
| index da4c935f0bafb532b2c3cc0285d2303c18ba9429..276f396f779a3b07abda6a41e4873e2c9b66eb35 100644 |
| --- a/pkg/path/lib/path.dart |
| +++ b/pkg/path/lib/path.dart |
| @@ -46,11 +46,6 @@ |
| /// even when the program is run on a POSIX machine. |
| library path; |
| -@MirrorsUsed(targets: 'dart.dom.html.window, ' |
| - 'dart.io.Directory.current, ' |
| - 'dart.io.Platform.operatingSystem') |
| -import 'dart:mirrors'; |
| - |
| /// An internal builder for the current OS so we can provide a straight |
| /// functional interface and not require users to create one. |
| final _builder = new Builder(); |
| @@ -69,19 +64,6 @@ final url = new Builder(style: Style.url); |
| void _growListFront(List list, int length, fillValue) => |
| list.insertAll(0, new List.filled(length, fillValue)); |
| -/// If we're running in the server-side Dart VM, this will return a |
| -/// [LibraryMirror] that gives access to the `dart:io` library. |
| -/// |
| -/// If `dart:io` is not available, this returns null. |
| -LibraryMirror get _io => currentMirrorSystem().libraries[Uri.parse('dart:io')]; |
| - |
| -// TODO(nweiz): when issue 6490 or 6943 are fixed, make this work under dart2js. |
| -/// If we're running in Dartium, this will return a [LibraryMirror] that gives |
| -/// access to the `dart:html` library. |
| -/// |
| -/// If `dart:html` is not available, this returns null. |
| -LibraryMirror get _html => |
| - currentMirrorSystem().libraries[Uri.parse('dart:html')]; |
| /// Gets the path to the current working directory. |
| /// |
| @@ -89,13 +71,13 @@ LibraryMirror get _html => |
| /// currently returns `.` due to technical constraints. In the future, it will |
| /// return the current URL. |
|
nweiz
2013/11/06 20:43:13
The dart2js comment in this paragraph is no longer
Anders Johnsen
2013/11/07 07:50:32
Done.
|
| String get current { |
| - if (_io != null) { |
| - return (_io.declarations[#Directory] as ClassMirror) |
| - .getField(#current).reflectee.path; |
| - } else if (_html != null) { |
| - return _html.getField(#window).reflectee.location.href; |
| + var uri = Uri.base; |
| + if (Style.platform == Style.url) { |
| + return uri.toString(); |
|
nweiz
2013/11/06 19:37:09
We should be sure to return an actual directory he
Anders Johnsen
2013/11/07 07:50:32
Done.
|
| } else { |
| - return '.'; |
| + var path = uri.toFilePath(); |
| + // Remove trailing '/' or '\'. |
| + return path.substring(0, path.length - 1); |
|
nweiz
2013/11/06 19:37:09
Add an assertion that the last character is '/' or
Anders Johnsen
2013/11/07 07:50:32
Done.
|
| } |
| } |
| @@ -866,14 +848,15 @@ abstract class Style { |
| /// Gets the type of the host platform. |
| static Style _getPlatformStyle() { |
| - if (_io == null) return Style.url; |
| - |
| - if ((_io.declarations[#Platform] as ClassMirror).getField(#operatingSystem) |
| - .reflectee == 'windows') { |
| - return Style.windows; |
| + // The browser can not open a file, pointing to a directory, while also |
| + // be running Dart scripts. |
|
nweiz
2013/11/06 19:37:09
I think this comment could be clearer. How about "
Anders Johnsen
2013/11/07 07:50:32
Done.
|
| + if (Uri.base.path.toString().endsWith('/') && Uri.base.scheme == 'file') { |
|
nweiz
2013/11/06 19:37:09
[Uri.base.path] is already a string; [toString] he
Anders Johnsen
2013/11/07 07:50:32
Ah, yes, good catch!
|
| + if (new Uri.file('a/b').toFilePath() == 'a\\b') { |
|
nweiz
2013/11/06 19:37:09
Nit: the [new Uri.file] constructor here is unnece
Anders Johnsen
2013/11/07 07:50:32
Done.
|
| + return Style.windows; |
| + } |
| + return Style.posix; |
| } |
| - |
| - return Style.posix; |
| + return Style.url; |
|
nweiz
2013/11/06 19:37:09
Style suggestion: reduce the nesting here by re-or
Anders Johnsen
2013/11/07 07:50:32
Done.
|
| } |
| /// The name of this path style. Will be "posix" or "windows". |