| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 # = Object.create(null); // embedded interceptorsByTag. | 351 # = Object.create(null); // embedded interceptorsByTag. |
| 352 # = Object.create(null); // embedded leafTags. | 352 # = Object.create(null); // embedded leafTags. |
| 353 # = Object.create(null); // embedded finishedClasses | 353 # = Object.create(null); // embedded finishedClasses |
| 354 })() | 354 })() |
| 355 ''', [allClassesAccess, | 355 ''', [allClassesAccess, |
| 356 interceptorsByTagAccess, | 356 interceptorsByTagAccess, |
| 357 leafTagsAccess, | 357 leafTagsAccess, |
| 358 finishedClassesAccess]); | 358 finishedClassesAccess]); |
| 359 } | 359 } |
| 360 | 360 |
| 361 List buildSplitOffAliases() { |
| 362 if (backend.aliasedSuperMembers.isEmpty) return []; |
| 363 return [js(r''' |
| 364 var splitOffAliases = function(constructor) { |
| 365 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 366 var properties = constructor.prototype; |
| 367 for (var member in properties) { |
| 368 if (hasOwnProperty.call(properties, member)) { |
| 369 var s = member.split(':'); |
| 370 if (s.length > 1) { |
| 371 properties[s[0]] = properties[s[1]] = properties[member]; |
| 372 delete properties[member]; |
| 373 } |
| 374 } |
| 375 } |
| 376 } |
| 377 ''')]; |
| 378 } |
| 379 |
| 361 jsAst.Fun get finishClassesFunction { | 380 jsAst.Fun get finishClassesFunction { |
| 362 // Class descriptions are collected in a JS object. | 381 // Class descriptions are collected in a JS object. |
| 363 // 'finishClasses' takes all collected descriptions and sets up | 382 // 'finishClasses' takes all collected descriptions and sets up |
| 364 // the prototype. | 383 // the prototype. |
| 365 // Once set up, the constructors prototype field satisfy: | 384 // Once set up, the constructors prototype field satisfy: |
| 366 // - it contains all (local) members. | 385 // - it contains all (local) members. |
| 367 // - its internal prototype (__proto__) points to the superclass' | 386 // - its internal prototype (__proto__) points to the superclass' |
| 368 // prototype field. | 387 // prototype field. |
| 369 // - the prototype's constructor field points to the JavaScript | 388 // - the prototype's constructor field points to the JavaScript |
| 370 // constructor. | 389 // constructor. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 return js.statement(''' | 526 return js.statement(''' |
| 508 { | 527 { |
| 509 var finishedClasses = #; // finishedClassesAccess. | 528 var finishedClasses = #; // finishedClassesAccess. |
| 510 | 529 |
| 511 function finishClass(cls) { | 530 function finishClass(cls) { |
| 512 | 531 |
| 513 if (finishedClasses[cls]) return; | 532 if (finishedClasses[cls]) return; |
| 514 finishedClasses[cls] = true; | 533 finishedClasses[cls] = true; |
| 515 | 534 |
| 516 var superclass = pendingClasses[cls]; | 535 var superclass = pendingClasses[cls]; |
| 536 var constructor = allClasses[cls]; |
| 537 |
| 538 // Process aliased members due to super calls. We have to do this early |
| 539 // to ensure that we also hit the object class. |
| 540 if (#) splitOffAliases(constructor); |
| 517 | 541 |
| 518 // The superclass is only false (empty string) for the Dart Object | 542 // The superclass is only false (empty string) for the Dart Object |
| 519 // class. The minifier together with noSuchMethod can put methods on | 543 // class. The minifier together with noSuchMethod can put methods on |
| 520 // the Object.prototype object, and they show through here, so we check | 544 // the Object.prototype object, and they show through here, so we check |
| 521 // that we have a string. | 545 // that we have a string. |
| 522 if (!superclass || typeof superclass != "string") return; | 546 if (!superclass || typeof superclass != "string") return; |
| 523 finishClass(superclass); | 547 finishClass(superclass); |
| 524 var constructor = allClasses[cls]; | |
| 525 var superConstructor = allClasses[superclass]; | 548 var superConstructor = allClasses[superclass]; |
| 526 | 549 |
| 527 if (!superConstructor) | 550 if (!superConstructor) |
| 528 superConstructor = existingIsolateProperties[superclass]; | 551 superConstructor = existingIsolateProperties[superclass]; |
| 529 | 552 |
| 530 var prototype = inheritFrom(constructor, superConstructor); | 553 var prototype = inheritFrom(constructor, superConstructor); |
| 531 | 554 |
| 532 if (#) { // !nativeClasses.isEmpty, | 555 if (#) { // !nativeClasses.isEmpty, |
| 533 // The property looks like this: | 556 // The property looks like this: |
| 534 // | 557 // |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 for (i = 0; i < tags.length; i++) { | 596 for (i = 0; i < tags.length; i++) { |
| 574 #[tags[i]] = constructor; // embedded interceptorsByTag. | 597 #[tags[i]] = constructor; // embedded interceptorsByTag. |
| 575 #[tags[i]] = false; // embedded leafTags. | 598 #[tags[i]] = false; // embedded leafTags. |
| 576 } | 599 } |
| 577 } | 600 } |
| 578 } | 601 } |
| 579 } | 602 } |
| 580 } | 603 } |
| 581 } | 604 } |
| 582 }''', [finishedClassesAccess, | 605 }''', [finishedClassesAccess, |
| 606 backend.aliasedSuperMembers.isNotEmpty, |
| 583 !nativeClasses.isEmpty, | 607 !nativeClasses.isEmpty, |
| 584 interceptorsByTagAccess, | 608 interceptorsByTagAccess, |
| 585 leafTagsAccess, | 609 leafTagsAccess, |
| 586 true, | 610 true, |
| 587 interceptorsByTagAccess, | 611 interceptorsByTagAccess, |
| 588 leafTagsAccess]); | 612 leafTagsAccess]); |
| 589 } | 613 } |
| 590 | 614 |
| 591 jsAst.Fun get finishIsolateConstructorFunction { | 615 jsAst.Fun get finishIsolateConstructorFunction { |
| 592 // We replace the old Isolate function with a new one that initializes | 616 // 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... |
| 684 } | 708 } |
| 685 ''', [laziesAccess, laziesAccess, | 709 ''', [laziesAccess, laziesAccess, |
| 686 laziesAccess, | 710 laziesAccess, |
| 687 cyclicThrow]); | 711 cyclicThrow]); |
| 688 } | 712 } |
| 689 | 713 |
| 690 List buildDefineClassAndFinishClassFunctionsIfNecessary() { | 714 List buildDefineClassAndFinishClassFunctionsIfNecessary() { |
| 691 if (!needsDefineClass) return []; | 715 if (!needsDefineClass) return []; |
| 692 return defineClassFunction | 716 return defineClassFunction |
| 693 ..add(buildInheritFrom()) | 717 ..add(buildInheritFrom()) |
| 718 ..addAll(buildSplitOffAliases()) |
| 694 ..add(js('$finishClassesName = #', finishClassesFunction)) | 719 ..add(js('$finishClassesName = #', finishClassesFunction)) |
| 695 ..add(initFinishClasses); | 720 ..add(initFinishClasses); |
| 696 } | 721 } |
| 697 | 722 |
| 698 List buildLazyInitializerFunctionIfNecessary() { | 723 List buildLazyInitializerFunctionIfNecessary() { |
| 699 if (!needsLazyInitializer) return []; | 724 if (!needsLazyInitializer) return []; |
| 700 | 725 |
| 701 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; | 726 return [js('# = #', [js(lazyInitializerName), lazyInitializerFunction])]; |
| 702 } | 727 } |
| 703 | 728 |
| (...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2004 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 1980 if (element.isInstanceMember) { | 2005 if (element.isInstanceMember) { |
| 1981 cachedClassBuilders.remove(element.enclosingClass); | 2006 cachedClassBuilders.remove(element.enclosingClass); |
| 1982 | 2007 |
| 1983 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2008 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 1984 | 2009 |
| 1985 } | 2010 } |
| 1986 } | 2011 } |
| 1987 } | 2012 } |
| 1988 } | 2013 } |
| OLD | NEW |