Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 # = Object.create(null); // embedded interceptorsByTag. | 353 # = Object.create(null); // embedded interceptorsByTag. |
| 354 # = Object.create(null); // embedded leafTags. | 354 # = Object.create(null); // embedded leafTags. |
| 355 # = Object.create(null); // embedded finishedClasses | 355 # = Object.create(null); // embedded finishedClasses |
| 356 })() | 356 })() |
| 357 ''', [allClassesAccess, | 357 ''', [allClassesAccess, |
| 358 interceptorsByTagAccess, | 358 interceptorsByTagAccess, |
| 359 leafTagsAccess, | 359 leafTagsAccess, |
| 360 finishedClassesAccess]); | 360 finishedClassesAccess]); |
| 361 } | 361 } |
| 362 | 362 |
| 363 List buildSplitOffAliases() { | |
|
ahe
2014/11/25 09:33:03
If you follow my suggestion in container_builder.d
herhut
2014/11/25 14:03:19
Done.
| |
| 364 if (backend.aliasedSuperMembers.isEmpty) return []; | |
| 365 return [js(r''' | |
| 366 var splitOffAliases = function(constructor) { | |
| 367 var hasOwnProperty = Object.prototype.hasOwnProperty; | |
| 368 var properties = constructor.prototype; | |
| 369 for (var member in properties) { | |
| 370 if (hasOwnProperty.call(properties, member)) { | |
| 371 var s = member.split(':'); | |
| 372 if (s.length > 1) { | |
| 373 properties[s[0]] = properties[s[1]] = properties[member]; | |
| 374 properties[s[1]].$aliasName = s[1]; | |
| 375 delete properties[member]; | |
| 376 } | |
| 377 } | |
| 378 } | |
| 379 } | |
| 380 ''')]; | |
| 381 } | |
| 382 | |
| 363 jsAst.Fun get finishClassesFunction { | 383 jsAst.Fun get finishClassesFunction { |
| 364 // Class descriptions are collected in a JS object. | 384 // Class descriptions are collected in a JS object. |
| 365 // 'finishClasses' takes all collected descriptions and sets up | 385 // 'finishClasses' takes all collected descriptions and sets up |
| 366 // the prototype. | 386 // the prototype. |
| 367 // Once set up, the constructors prototype field satisfy: | 387 // Once set up, the constructors prototype field satisfy: |
| 368 // - it contains all (local) members. | 388 // - it contains all (local) members. |
| 369 // - its internal prototype (__proto__) points to the superclass' | 389 // - its internal prototype (__proto__) points to the superclass' |
| 370 // prototype field. | 390 // prototype field. |
| 371 // - the prototype's constructor field points to the JavaScript | 391 // - the prototype's constructor field points to the JavaScript |
| 372 // constructor. | 392 // constructor. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 return js.statement(''' | 529 return js.statement(''' |
| 510 { | 530 { |
| 511 var finishedClasses = #; // finishedClassesAccess. | 531 var finishedClasses = #; // finishedClassesAccess. |
| 512 | 532 |
| 513 function finishClass(cls) { | 533 function finishClass(cls) { |
| 514 | 534 |
| 515 if (finishedClasses[cls]) return; | 535 if (finishedClasses[cls]) return; |
| 516 finishedClasses[cls] = true; | 536 finishedClasses[cls] = true; |
| 517 | 537 |
| 518 var superclass = pendingClasses[cls]; | 538 var superclass = pendingClasses[cls]; |
| 539 var constructor = allClasses[cls]; | |
| 540 | |
| 541 // Process aliased members due to super calls. We have to do this early | |
| 542 // to ensure that we also hit the object class. | |
| 543 if (#) splitOffAliases(constructor); | |
|
floitsch
2014/11/24 10:47:52
Please change this to named js-holes. (you will ne
ahe
2014/11/25 09:33:03
Awesome. I needed that :-)
herhut
2014/11/25 14:03:19
Done.
herhut
2014/11/25 14:03:19
Acknowledged.
| |
| 519 | 544 |
| 520 // The superclass is only false (empty string) for the Dart Object | 545 // The superclass is only false (empty string) for the Dart Object |
| 521 // class. The minifier together with noSuchMethod can put methods on | 546 // class. The minifier together with noSuchMethod can put methods on |
| 522 // the Object.prototype object, and they show through here, so we check | 547 // the Object.prototype object, and they show through here, so we check |
| 523 // that we have a string. | 548 // that we have a string. |
| 524 if (!superclass || typeof superclass != "string") return; | 549 if (!superclass || typeof superclass != "string") return; |
| 525 finishClass(superclass); | 550 finishClass(superclass); |
| 526 var constructor = allClasses[cls]; | |
| 527 var superConstructor = allClasses[superclass]; | 551 var superConstructor = allClasses[superclass]; |
| 528 | 552 |
| 529 if (!superConstructor) | 553 if (!superConstructor) |
| 530 superConstructor = existingIsolateProperties[superclass]; | 554 superConstructor = existingIsolateProperties[superclass]; |
| 531 | 555 |
| 532 var prototype = inheritFrom(constructor, superConstructor); | 556 var prototype = inheritFrom(constructor, superConstructor); |
| 533 | 557 |
| 534 if (#) { // !nativeClasses.isEmpty, | 558 if (#) { // !nativeClasses.isEmpty, |
| 535 // The property looks like this: | 559 // The property looks like this: |
| 536 // | 560 // |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 for (i = 0; i < tags.length; i++) { | 599 for (i = 0; i < tags.length; i++) { |
| 576 #[tags[i]] = constructor; // embedded interceptorsByTag. | 600 #[tags[i]] = constructor; // embedded interceptorsByTag. |
| 577 #[tags[i]] = false; // embedded leafTags. | 601 #[tags[i]] = false; // embedded leafTags. |
| 578 } | 602 } |
| 579 } | 603 } |
| 580 } | 604 } |
| 581 } | 605 } |
| 582 } | 606 } |
| 583 } | 607 } |
| 584 }''', [finishedClassesAccess, | 608 }''', [finishedClassesAccess, |
| 609 backend.aliasedSuperMembers.isNotEmpty, | |
| 585 !nativeClasses.isEmpty, | 610 !nativeClasses.isEmpty, |
| 586 interceptorsByTagAccess, | 611 interceptorsByTagAccess, |
| 587 leafTagsAccess, | 612 leafTagsAccess, |
| 588 true, | 613 true, |
| 589 interceptorsByTagAccess, | 614 interceptorsByTagAccess, |
| 590 leafTagsAccess]); | 615 leafTagsAccess]); |
| 591 } | 616 } |
| 592 | 617 |
| 593 jsAst.Fun get finishIsolateConstructorFunction { | 618 jsAst.Fun get finishIsolateConstructorFunction { |
| 594 // We replace the old Isolate function with a new one that initializes | 619 // We replace the old Isolate function with a new one that initializes |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 } | 711 } |
| 687 ''', [laziesAccess, laziesAccess, | 712 ''', [laziesAccess, laziesAccess, |
| 688 laziesAccess, | 713 laziesAccess, |
| 689 cyclicThrow]); | 714 cyclicThrow]); |
| 690 } | 715 } |
| 691 | 716 |
| 692 List buildDefineClassAndFinishClassFunctionsIfNecessary() { | 717 List buildDefineClassAndFinishClassFunctionsIfNecessary() { |
| 693 if (!needsDefineClass) return []; | 718 if (!needsDefineClass) return []; |
| 694 return defineClassFunction | 719 return defineClassFunction |
| 695 ..add(buildInheritFrom()) | 720 ..add(buildInheritFrom()) |
| 721 ..addAll(buildSplitOffAliases()) | |
| 696 ..add(js('$finishClassesName = #', finishClassesFunction)) | 722 ..add(js('$finishClassesName = #', finishClassesFunction)) |
| 697 ..add(initFinishClasses); | 723 ..add(initFinishClasses); |
| 698 } | 724 } |
| 699 | 725 |
| 700 List buildLazyInitializerFunctionIfNecessary() { | 726 List buildLazyInitializerFunctionIfNecessary() { |
| 701 if (!needsLazyInitializer) return []; | 727 if (!needsLazyInitializer) return []; |
| 702 | 728 |
| 703 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; | 729 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; |
| 704 } | 730 } |
| 705 | 731 |
| (...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2013 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2039 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2014 if (element.isInstanceMember) { | 2040 if (element.isInstanceMember) { |
| 2015 cachedClassBuilders.remove(element.enclosingClass); | 2041 cachedClassBuilders.remove(element.enclosingClass); |
| 2016 | 2042 |
| 2017 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2043 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2018 | 2044 |
| 2019 } | 2045 } |
| 2020 } | 2046 } |
| 2021 } | 2047 } |
| 2022 } | 2048 } |
| OLD | NEW |