Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: tool/input_sdk/private/ddc_runtime/operations.dart

Issue 1989663002: fix #470, string interpolation now respects Dart toString (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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('', '#.toString()', obj);
sra1 2016/05/17 23:47:58 It is faster to do: JS('', '"" + #', obj); JS en
Jennifer Messerly 2016/05/18 00:23:42 Done.
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
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 += $_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 ''');
OLDNEW
« lib/src/compiler/code_generator.dart ('K') | « test/codegen/expect/sunflower/sunflower.js.map ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698