| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); | 443 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); |
| 444 } | 444 } |
| 445 return js(r'var inheritFrom = #', [result]); | 445 return js(r'var inheritFrom = #', [result]); |
| 446 } | 446 } |
| 447 | 447 |
| 448 jsAst.Statement buildFinishClass(bool hasNativeClasses) { | 448 jsAst.Statement buildFinishClass(bool hasNativeClasses) { |
| 449 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" | 449 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" |
| 450 | 450 |
| 451 jsAst.Expression finishedClassesAccess = | 451 jsAst.Expression finishedClassesAccess = |
| 452 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); | 452 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); |
| 453 |
| 454 jsAst.Expression nativeInfoAccess = js('prototype[$specProperty]', []); |
| 455 jsAst.Expression constructorAccess = js('constructor', []); |
| 456 Function subclassReadGenerator = |
| 457 (jsAst.Expression subclass) => js('allClasses[#]', subclass); |
| 453 jsAst.Expression interceptorsByTagAccess = | 458 jsAst.Expression interceptorsByTagAccess = |
| 454 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); | 459 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); |
| 455 jsAst.Expression leafTagsAccess = | 460 jsAst.Expression leafTagsAccess = |
| 456 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); | 461 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); |
| 462 jsAst.Statement nativeInfoHandler = nativeEmitter.buildNativeInfoHandler( |
| 463 nativeInfoAccess, |
| 464 constructorAccess, |
| 465 subclassReadGenerator, |
| 466 interceptorsByTagAccess, |
| 467 leafTagsAccess); |
| 457 | 468 |
| 458 return js.statement(''' | 469 return js.statement(''' |
| 459 { | 470 { |
| 460 var finishedClasses = #finishedClassesAccess; | 471 var finishedClasses = #finishedClassesAccess; |
| 461 | 472 |
| 462 function finishClass(cls) { | 473 function finishClass(cls) { |
| 463 | 474 |
| 464 if (finishedClasses[cls]) return; | 475 if (finishedClasses[cls]) return; |
| 465 finishedClasses[cls] = true; | 476 finishedClasses[cls] = true; |
| 466 | 477 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 493 } | 504 } |
| 494 finishClass(superclass); | 505 finishClass(superclass); |
| 495 var superConstructor = allClasses[superclass]; | 506 var superConstructor = allClasses[superclass]; |
| 496 | 507 |
| 497 if (!superConstructor) | 508 if (!superConstructor) |
| 498 superConstructor = existingIsolateProperties[superclass]; | 509 superConstructor = existingIsolateProperties[superclass]; |
| 499 | 510 |
| 500 var constructor = allClasses[cls]; | 511 var constructor = allClasses[cls]; |
| 501 var prototype = inheritFrom(constructor, superConstructor); | 512 var prototype = inheritFrom(constructor, superConstructor); |
| 502 | 513 |
| 503 if (#hasNativeClasses) { | 514 if (#hasNativeClasses) |
| 504 // The property looks like this: | 515 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) |
| 505 // | 516 #nativeInfoHandler |
| 506 // HtmlElement: { | |
| 507 // "%": "HTMLDivElement|HTMLAnchorElement;HTMLElement;FancyButton" | |
| 508 // | |
| 509 // The first two semicolon-separated parts contain dispatch tags, the | |
| 510 // third contains the JavaScript names for classes. | |
| 511 // | |
| 512 // The tags indicate that JavaScript objects with the dispatch tags | |
| 513 // (usually constructor names) HTMLDivElement, HTMLAnchorElement and | |
| 514 // HTMLElement all map to the Dart native class named HtmlElement. | |
| 515 // The first set is for effective leaf nodes in the hierarchy, the | |
| 516 // second set is non-leaf nodes. | |
| 517 // | |
| 518 // The third part contains the JavaScript names of Dart classes that | |
| 519 // extend the native class. Here, FancyButton extends HtmlElement, so | |
| 520 // the runtime needs to know that window.HTMLElement.prototype is the | |
| 521 // prototype that needs to be extended in creating the custom element. | |
| 522 // | |
| 523 // The information is used to build tables referenced by | |
| 524 // getNativeInterceptor and custom element support. | |
| 525 if (Object.prototype.hasOwnProperty.call(prototype, $specProperty)) { | |
| 526 var nativeSpec = prototype[$specProperty].split(";"); | |
| 527 if (nativeSpec[0]) { | |
| 528 var tags = nativeSpec[0].split("|"); | |
| 529 for (var i = 0; i < tags.length; i++) { | |
| 530 #interceptorsByTagAccess[tags[i]] = constructor; | |
| 531 #leafTagsAccess[tags[i]] = true; | |
| 532 } | |
| 533 } | |
| 534 if (nativeSpec[1]) { | |
| 535 tags = nativeSpec[1].split("|"); | |
| 536 if (#allowNativesSubclassing) { | |
| 537 if (nativeSpec[2]) { | |
| 538 var subclasses = nativeSpec[2].split("|"); | |
| 539 for (var i = 0; i < subclasses.length; i++) { | |
| 540 var subclass = allClasses[subclasses[i]]; | |
| 541 subclass.#nativeSuperclassTagName = tags[0]; | |
| 542 } | |
| 543 } | |
| 544 for (i = 0; i < tags.length; i++) { | |
| 545 #interceptorsByTagAccess[tags[i]] = constructor; | |
| 546 #leafTagsAccess[tags[i]] = false; | |
| 547 } | |
| 548 } | |
| 549 } | |
| 550 } | |
| 551 } | |
| 552 } | 517 } |
| 553 }''', {'finishedClassesAccess': finishedClassesAccess, | 518 }''', {'finishedClassesAccess': finishedClassesAccess, |
| 554 'needsMixinSupport': needsMixinSupport, | 519 'needsMixinSupport': needsMixinSupport, |
| 555 'hasNativeClasses': hasNativeClasses, | 520 'hasNativeClasses': hasNativeClasses, |
| 556 'nativeSuperclassTagName': embeddedNames.NATIVE_SUPERCLASS_TAG_NAME, | 521 'nativeInfoHandler': nativeInfoHandler}); |
| 557 'interceptorsByTagAccess': interceptorsByTagAccess, | |
| 558 'leafTagsAccess': leafTagsAccess, | |
| 559 'allowNativesSubclassing': true}); | |
| 560 } | 522 } |
| 561 | 523 |
| 562 void emitFinishIsolateConstructorInvocation(CodeOutput output) { | 524 void emitFinishIsolateConstructorInvocation(CodeOutput output) { |
| 563 String isolate = namer.isolateName; | 525 String isolate = namer.isolateName; |
| 564 output.add("$isolate = $finishIsolateConstructorName($isolate)$N"); | 526 output.add("$isolate = $finishIsolateConstructorName($isolate)$N"); |
| 565 } | 527 } |
| 566 | 528 |
| 567 /// In minified mode we want to keep the name for the most common core types. | 529 /// In minified mode we want to keep the name for the most common core types. |
| 568 bool _isNativeTypeNeedingReflectionName(Element element) { | 530 bool _isNativeTypeNeedingReflectionName(Element element) { |
| 569 if (!element.isClass) return false; | 531 if (!element.isClass) return false; |
| (...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2027 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2066 if (element.isInstanceMember) { | 2028 if (element.isInstanceMember) { |
| 2067 cachedClassBuilders.remove(element.enclosingClass); | 2029 cachedClassBuilders.remove(element.enclosingClass); |
| 2068 | 2030 |
| 2069 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2031 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2070 | 2032 |
| 2071 } | 2033 } |
| 2072 } | 2034 } |
| 2073 } | 2035 } |
| 2074 } | 2036 } |
| OLD | NEW |