| 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 part of dart._runtime; | 7 part of dart._runtime; |
| 8 | 8 |
| 9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { | 9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { |
| 10 $name = $canonicalMember($obj, $name); | 10 $name = $canonicalMember($obj, $name); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 @JSExportName('as') | 254 @JSExportName('as') |
| 255 cast(obj, type) { | 255 cast(obj, type) { |
| 256 if (obj == null) return obj; | 256 if (obj == null) return obj; |
| 257 | 257 |
| 258 bool result = strongInstanceOf(obj, type, true); | 258 bool result = strongInstanceOf(obj, type, true); |
| 259 if (JS('bool', '#', result)) return obj; | 259 if (JS('bool', '#', result)) return obj; |
| 260 _throwCastError(obj, type, result); | 260 _throwCastError(obj, type, result); |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool test(obj) { | 263 bool test(obj) { |
| 264 if (JS('bool', 'typeof # == "boolean"', obj)) return JS('bool', '#', obj); | 264 if (obj is bool) return obj; |
| 265 throwCastError(getReifiedType(obj), JS('', '#', bool)); | 265 return booleanConversionFailed(obj); |
| 266 } |
| 267 |
| 268 bool booleanConversionFailed(obj) { |
| 269 if (obj == null) { |
| 270 throw new BooleanConversionAssertionError(); |
| 271 } |
| 272 var actual = getReifiedType(obj); |
| 273 var expected = JS('', '#', bool); |
| 274 throw new TypeErrorImplementation.fromMessage( |
| 275 "type '${typeName(actual)}' is not a subtype of " |
| 276 "type '${typeName(expected)}' in boolean expression"); |
| 266 } | 277 } |
| 267 | 278 |
| 268 void _throwCastError(obj, type, bool result) { | 279 void _throwCastError(obj, type, bool result) { |
| 269 var actual = getReifiedType(obj); | 280 var actual = getReifiedType(obj); |
| 270 if (result == false) throwCastError(actual, type); | 281 if (result == false) throwCastError(actual, type); |
| 271 | 282 |
| 272 throwStrongModeError('Strong mode cast failure from ' + | 283 throwStrongModeError('Strong mode cast failure from ' + |
| 273 typeName(actual) + ' to ' + typeName(type)); | 284 typeName(actual) + ' to ' + typeName(type)); |
| 274 } | 285 } |
| 275 | 286 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 constructor(dartIterator) { | 527 constructor(dartIterator) { |
| 517 this.dartIterator = dartIterator; | 528 this.dartIterator = dartIterator; |
| 518 } | 529 } |
| 519 next() { | 530 next() { |
| 520 let i = this.dartIterator; | 531 let i = this.dartIterator; |
| 521 let done = !i.moveNext(); | 532 let done = !i.moveNext(); |
| 522 return { done: done, value: done ? void 0 : i.current }; | 533 return { done: done, value: done ? void 0 : i.current }; |
| 523 } | 534 } |
| 524 } | 535 } |
| 525 '''); | 536 '''); |
| OLD | NEW |