| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('dart:uri'); | 5 #library('dart:uri'); |
| 6 | 6 |
| 7 #import('dart:math'); | 7 #import('dart:math'); |
| 8 #import('dart:utf'); | 8 #import('dart:utf'); |
| 9 | 9 |
| 10 #source('encode_decode.dart'); | 10 #source('encode_decode.dart'); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 query: targetQuery, | 174 query: targetQuery, |
| 175 fragment: reference.fragment); | 175 fragment: reference.fragment); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool hasAuthority() { | 178 bool hasAuthority() { |
| 179 return (userInfo != "") || (domain != "") || (port != 0); | 179 return (userInfo != "") || (domain != "") || (port != 0); |
| 180 } | 180 } |
| 181 | 181 |
| 182 /** | 182 /** |
| 183 * For http/https schemes returns URI's [origin][] - scheme://domain:port. | 183 * For http/https schemes returns URI's [origin][] - scheme://domain:port. |
| 184 * For all other schemes throws IllegalArgumentException. | 184 * For all other schemes throws ArgumentError. |
| 185 * [origin]: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin | 185 * [origin]: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin |
| 186 */ | 186 */ |
| 187 String get origin { | 187 String get origin { |
| 188 if (scheme == "") { | 188 if (scheme == "") { |
| 189 // TODO(aprelev@gmail.com): Use StateException instead | 189 // TODO(aprelev@gmail.com): Use StateException instead |
| 190 throw new IllegalArgumentException("Cannot use origin without a scheme"); | 190 throw new ArgumentError("Cannot use origin without a scheme"); |
| 191 } | 191 } |
| 192 if (scheme != "http" && scheme != "https") { | 192 if (scheme != "http" && scheme != "https") { |
| 193 // TODO(aprelev@gmail.com): Use StateException instead | 193 // TODO(aprelev@gmail.com): Use StateException instead |
| 194 throw new IllegalArgumentException( | 194 throw new ArgumentError( |
| 195 "origin is applicable to http/https schemes only. Not \'$scheme\'"); | 195 "origin is applicable to http/https schemes only. Not \'$scheme\'"); |
| 196 } | 196 } |
| 197 StringBuffer sb = new StringBuffer(); | 197 StringBuffer sb = new StringBuffer(); |
| 198 sb.add(scheme); | 198 sb.add(scheme); |
| 199 sb.add(":"); | 199 sb.add(":"); |
| 200 if (domain == null || domain == "") { | 200 if (domain == null || domain == "") { |
| 201 // TODO(aprelev@gmail.com): Use StateException instead | 201 // TODO(aprelev@gmail.com): Use StateException instead |
| 202 throw new IllegalArgumentException("Cannot use origin without a domain"); | 202 throw new ArgumentError("Cannot use origin without a domain"); |
| 203 } | 203 } |
| 204 | 204 |
| 205 sb.add("//"); | 205 sb.add("//"); |
| 206 sb.add(domain); | 206 sb.add(domain); |
| 207 if (port != 0) { | 207 if (port != 0) { |
| 208 sb.add(":"); | 208 sb.add(":"); |
| 209 sb.add(port); | 209 sb.add(port); |
| 210 } | 210 } |
| 211 return sb.toString(); | 211 return sb.toString(); |
| 212 } | 212 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 230 } | 230 } |
| 231 | 231 |
| 232 static void _addIfNonEmpty(StringBuffer sb, String test, | 232 static void _addIfNonEmpty(StringBuffer sb, String test, |
| 233 String first, String second) { | 233 String first, String second) { |
| 234 if ("" != test) { | 234 if ("" != test) { |
| 235 sb.add(first === null ? "null" : first); | 235 sb.add(first === null ? "null" : first); |
| 236 sb.add(second === null ? "null" : second); | 236 sb.add(second === null ? "null" : second); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 } | 239 } |
| OLD | NEW |