Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Unified Diff: sdk/lib/_internal/lib/js_helper.dart

Issue 23686021: Add property base to the Uri class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed more review comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/lib/isolate_helper.dart ('k') | sdk/lib/core/uri.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/js_helper.dart
diff --git a/sdk/lib/_internal/lib/js_helper.dart b/sdk/lib/_internal/lib/js_helper.dart
index f31a0b813d18ffb5e1804937a215af995947381d..5d70b9e61c2b53392c2d4c94c3f2be3fab01f12f 100644
--- a/sdk/lib/_internal/lib/js_helper.dart
+++ b/sdk/lib/_internal/lib/js_helper.dart
@@ -470,6 +470,45 @@ class Primitives {
return 1000 * dateNow();
}
+ static bool get isD8 {
+ return JS('bool',
+ 'typeof version == "function"'
+ ' && typeof os == "object" && "system" in os');
+ }
+
+ static bool get isJsshell {
+ return JS('bool',
+ 'typeof version == "function" && typeof system == "function"');
+ }
+
+ static String currentUri() {
+ // In a browser return self.location.href.
+ if (JS('bool', 'typeof self != "undefined"')) {
+ return JS('String', 'self.location.href');
+ }
+
+ // In JavaScript shells try to determine the current working
+ // directory.
+ var workingDirectory;
+ if (isD8) {
+ // TODO(sgjesse): This does not work on Windows.
+ workingDirectory = JS('String', 'os.system("pwd")');
+ var length = workingDirectory.length;
+ if (workingDirectory[length - 1] == '\n') {
+ workingDirectory = workingDirectory.substring(0, length - 1);
+ }
+ }
+
+ if (isJsshell) {
+ // TODO(sgjesse): This does not work on Windows.
+ workingDirectory = JS('String', 'environment["PWD"]');
+ }
+
+ return workingDirectory != null
+ ? "file://" + workingDirectory + "/"
+ : null;
+ }
+
// This is to avoid stack overflows due to very large argument arrays in
// apply(). It fixes http://dartbug.com/6919
static String _fromCharCodeApply(List<int> array) {
« no previous file with comments | « sdk/lib/_internal/lib/isolate_helper.dart ('k') | sdk/lib/core/uri.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698