OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /* This library defines runtime operations on objects used by the code | 5 /* This library defines runtime operations on objects used by the code |
6 * generator. | 6 * generator. |
7 */ | 7 */ |
8 dart_library.library('dart_runtime/_operations', null, /* Imports */[ | 8 dart_library.library('dart_runtime/_operations', null, /* Imports */[ |
9 ], /* Lazy Imports */[ | 9 ], /* Lazy Imports */[ |
10 'dart/async', | 10 'dart/async', |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 let actual = rtti.realRuntimeType(obj); | 225 let actual = rtti.realRuntimeType(obj); |
226 if (types.isGroundType(type)) errors.throwCastError(actual, type); | 226 if (types.isGroundType(type)) errors.throwCastError(actual, type); |
227 | 227 |
228 if (_ignoreTypeFailure(actual, type)) return obj; | 228 if (_ignoreTypeFailure(actual, type)) return obj; |
229 | 229 |
230 dart_utils.throwStrongModeError('Strong mode cast failure from ' + | 230 dart_utils.throwStrongModeError('Strong mode cast failure from ' + |
231 types.typeName(actual) + ' to ' + types.typeName(type)); | 231 types.typeName(actual) + ' to ' + types.typeName(type)); |
232 } | 232 } |
233 exports.cast = cast; | 233 exports.cast = cast; |
234 | 234 |
| 235 function asInt(obj) { |
| 236 if (Math.floor(obj) != obj) { |
| 237 // Note: null will also be caught by this check |
| 238 errors.throwCastError(rtti.realRuntimeType(obj), core.int); |
| 239 } |
| 240 return obj; |
| 241 } |
| 242 exports.asInt = asInt; |
| 243 |
235 function arity(f) { | 244 function arity(f) { |
236 // TODO(jmesserly): need to parse optional params. | 245 // TODO(jmesserly): need to parse optional params. |
237 // In ES6, length is the number of required arguments. | 246 // In ES6, length is the number of required arguments. |
238 return { min: f.length, max: f.length }; | 247 return { min: f.length, max: f.length }; |
239 } | 248 } |
240 exports.arity = arity; | 249 exports.arity = arity; |
241 | 250 |
242 function equals(x, y) { | 251 function equals(x, y) { |
243 if (x == null || y == null) return x == y; | 252 if (x == null || y == null) return x == y; |
244 let eq = x['==']; | 253 let eq = x['==']; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 next() { | 457 next() { |
449 let i = this.dartIterator; | 458 let i = this.dartIterator; |
450 let done = !i.moveNext(); | 459 let done = !i.moveNext(); |
451 return { done: done, value: done ? void 0 : i.current }; | 460 return { done: done, value: done ? void 0 : i.current }; |
452 } | 461 } |
453 } | 462 } |
454 exports.JsIterator = JsIterator; | 463 exports.JsIterator = JsIterator; |
455 | 464 |
456 | 465 |
457 }); | 466 }); |
OLD | NEW |