| 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('js_helper'); | 5 #library('js_helper'); |
| 6 | 6 |
| 7 $throw(String msg) { | |
| 8 var e = JS("Object", @"new Error($0)", msg); | |
| 9 var hasTrace = JS("bool", @"Error.captureStackTrace !== (void 0)"); | |
| 10 if (hasTrace) { | |
| 11 JS("void", @"Error.captureStackTrace($0)", e); | |
| 12 } | |
| 13 throw e; | |
| 14 } | |
| 15 | |
| 16 /** | 7 /** |
| 17 * Returns true if both arguments are numbers. | 8 * Returns true if both arguments are numbers. |
| 18 * If only the first argument is a number, throws the given message as | 9 * If only the first argument is a number, throws the given message as |
| 19 * exception. | 10 * exception. |
| 20 */ | 11 */ |
| 21 bool checkNumbers(var a, var b, var message) { | 12 bool checkNumbers(var a, var b, var message) { |
| 22 if (a is num) { | 13 if (a is num) { |
| 23 if (b is num) { | 14 if (b is num) { |
| 24 return true; | 15 return true; |
| 25 } else { | 16 } else { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return UNINTERCEPTED(~a); | 192 return UNINTERCEPTED(~a); |
| 202 } | 193 } |
| 203 | 194 |
| 204 neg(var a) { | 195 neg(var a) { |
| 205 if (JS("bool", @"typeof $0 === 'number'", a)) return JS("num", @"-$0", a); | 196 if (JS("bool", @"typeof $0 === 'number'", a)) return JS("num", @"-$0", a); |
| 206 return UNINTERCEPTED(-a); | 197 return UNINTERCEPTED(-a); |
| 207 } | 198 } |
| 208 | 199 |
| 209 index(var a, var index) { | 200 index(var a, var index) { |
| 210 if (a is String || isJSArray(a)) { | 201 if (a is String || isJSArray(a)) { |
| 211 if (!(index is int)) $throw('Illegal argument'); | 202 if (!(index is int)) { |
| 212 if (index < 0 || index >= a.length) $throw('Out of bounds'); | 203 throw new IllegalArgumentException(index); |
| 204 } |
| 205 if (index < 0 || index >= a.length) { |
| 206 throw new IndexOutOfRangeException(index); |
| 207 } |
| 213 return JS("Object", @"$0[$1]", a, index); | 208 return JS("Object", @"$0[$1]", a, index); |
| 214 } | 209 } |
| 215 return UNINTERCEPTED(a[index]); | 210 return UNINTERCEPTED(a[index]); |
| 216 } | 211 } |
| 217 | 212 |
| 218 indexSet(var a, var index, var value) { | 213 indexSet(var a, var index, var value) { |
| 219 if (isJSArray(a)) { | 214 if (isJSArray(a)) { |
| 220 if (!(index is int)) $throw('Illegal argument'); | 215 if (!(index is int)) { |
| 221 if (index < 0 || index >= a.length) $throw('Out of bounds'); | 216 throw new IllegalArgumentException(index); |
| 217 } |
| 218 if (index < 0 || index >= a.length) { |
| 219 throw new IndexOutOfRangeException(index); |
| 220 } |
| 222 return JS("Object", @"$0[$1] = $2", a, index, value); | 221 return JS("Object", @"$0[$1] = $2", a, index, value); |
| 223 } | 222 } |
| 224 return UNINTERCEPTED(a[index] = value); | 223 return UNINTERCEPTED(a[index] = value); |
| 225 } | 224 } |
| 226 | 225 |
| 227 builtin$add$1(var receiver, var value) { | 226 builtin$add$1(var receiver, var value) { |
| 228 if (isJSArray(receiver)) { | 227 if (isJSArray(receiver)) { |
| 229 JS("Object", @"$0.push($1)", receiver, value); | 228 JS("Object", @"$0.push($1)", receiver, value); |
| 230 return; | 229 return; |
| 231 } | 230 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return 1; | 393 return 1; |
| 395 } else { | 394 } else { |
| 396 return -1; | 395 return -1; |
| 397 } | 396 } |
| 398 } else if (a is String) { | 397 } else if (a is String) { |
| 399 throw 'String.compareTo is not implemented'; | 398 throw 'String.compareTo is not implemented'; |
| 400 } else { | 399 } else { |
| 401 return UNINTERCEPTED(a.compareTo(b)); | 400 return UNINTERCEPTED(a.compareTo(b)); |
| 402 } | 401 } |
| 403 } | 402 } |
| OLD | NEW |