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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 459 } |
460 | 460 |
461 @JSExportName('toString') | 461 @JSExportName('toString') |
462 _toString(obj) { | 462 _toString(obj) { |
463 if (obj == null) return "null"; | 463 if (obj == null) return "null"; |
464 | 464 |
465 var extension = getExtensionType(obj); | 465 var extension = getExtensionType(obj); |
466 if (extension != null) { | 466 if (extension != null) { |
467 return JS('', '#[dartx.toString]()', obj); | 467 return JS('', '#[dartx.toString]()', obj); |
468 } | 468 } |
469 return JS('', '#.toString()', obj); | 469 return JS('', '"" + #', obj); |
470 } | 470 } |
471 | 471 |
472 // TODO(jmesserly): is the argument type verified statically? | 472 // TODO(jmesserly): is the argument type verified statically? |
473 noSuchMethod(obj, Invocation invocation) { | 473 noSuchMethod(obj, Invocation invocation) { |
474 if (obj == null) { | 474 if (obj == null) { |
475 throw new NoSuchMethodError( | 475 throw new NoSuchMethodError( |
476 null, | 476 null, |
477 invocation.memberName, | 477 invocation.memberName, |
478 invocation.positionalArguments, | 478 invocation.positionalArguments, |
479 invocation.namedArguments); | 479 invocation.namedArguments); |
(...skipping 12 matching lines...) Expand all Loading... |
492 if (result != null) return wrapType(result); | 492 if (result != null) return wrapType(result); |
493 | 493 |
494 // Delegate to the (possibly user-defined) method on the object. | 494 // Delegate to the (possibly user-defined) method on the object. |
495 var extension = getExtensionType(obj); | 495 var extension = getExtensionType(obj); |
496 if (extension != null) { | 496 if (extension != null) { |
497 return JS('', '#[dartx.runtimeType]', obj); | 497 return JS('', '#[dartx.runtimeType]', obj); |
498 } | 498 } |
499 return JS('', '#.runtimeType', obj); | 499 return JS('', '#.runtimeType', obj); |
500 } | 500 } |
501 | 501 |
| 502 /// Implements Dart's interpolated strings as ES2015 tagged template literals. |
| 503 /// |
| 504 /// For example: dart.str`hello ${name}` |
| 505 String str(strings, @rest values) => JS('', '''(() => { |
| 506 let s = $strings[0]; |
| 507 for (let i = 0, len = $values.length; i < len; ) { |
| 508 s += $notNull($_toString($values[i])) + $strings[++i]; |
| 509 } |
| 510 return s; |
| 511 })()'''); |
| 512 |
| 513 |
502 final JsIterator = JS('', ''' | 514 final JsIterator = JS('', ''' |
503 class JsIterator { | 515 class JsIterator { |
504 constructor(dartIterator) { | 516 constructor(dartIterator) { |
505 this.dartIterator = dartIterator; | 517 this.dartIterator = dartIterator; |
506 } | 518 } |
507 next() { | 519 next() { |
508 let i = this.dartIterator; | 520 let i = this.dartIterator; |
509 let done = !i.moveNext(); | 521 let done = !i.moveNext(); |
510 return { done: done, value: done ? void 0 : i.current }; | 522 return { done: done, value: done ? void 0 : i.current }; |
511 } | 523 } |
512 } | 524 } |
513 '''); | 525 '''); |
OLD | NEW |