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

Side by Side Diff: pkg/polymer/lib/src/loader.dart

Issue 26051002: Updating Polymer to derive from custom elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/test/attr_deserialize_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 polymer; 5 part of polymer;
6 6
7 /** Annotation used to automatically register polymer elements. */ 7 /** Annotation used to automatically register polymer elements. */
8 class CustomTag { 8 class CustomTag {
9 final String tagName; 9 final String tagName;
10 const CustomTag(this.tagName); 10 const CustomTag(this.tagName);
(...skipping 18 matching lines...) Expand all
29 * The urls in [libraries] can be absolute or relative to [srcUrl]. 29 * The urls in [libraries] can be absolute or relative to [srcUrl].
30 */ 30 */
31 void initPolymer(List<String> libraries, [String srcUrl]) { 31 void initPolymer(List<String> libraries, [String srcUrl]) {
32 runMicrotask(() { 32 runMicrotask(() {
33 // DOM events don't yet go through microtasks, so we catch those here. 33 // DOM events don't yet go through microtasks, so we catch those here.
34 new Timer.periodic(new Duration(milliseconds: 125), 34 new Timer.periodic(new Duration(milliseconds: 125),
35 (_) => performMicrotaskCheckpoint()); 35 (_) => performMicrotaskCheckpoint());
36 36
37 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize. 37 // TODO(jmesserly): mdv should use initMdv instead of mdv.initialize.
38 mdv.initialize(); 38 mdv.initialize();
39 registerCustomElement('polymer-element', () => new PolymerDeclaration()); 39 document.register(PolymerDeclaration._TAG, PolymerDeclaration);
40 40
41 for (var lib in libraries) { 41 for (var lib in libraries) {
42 _loadLibrary(lib, srcUrl); 42 _loadLibrary(lib, srcUrl);
43 } 43 }
44 44
45 // TODO(jmesserly): this should be in the custom_element polyfill, not here. 45 // TODO(jmesserly): this should be in the custom_element polyfill, not here.
46 // notify the system that we are bootstrapped 46 // notify the system that we are bootstrapped
47 document.body.dispatchEvent( 47 document.body.dispatchEvent(
48 new CustomEvent('WebComponentsReady', canBubble: true)); 48 new CustomEvent('WebComponentsReady', canBubble: true));
49 }); 49 });
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Search top-level functions marked with @initMethod 83 // Search top-level functions marked with @initMethod
84 for (var f in lib.functions.values) { 84 for (var f in lib.functions.values) {
85 _maybeInvoke(lib, f); 85 _maybeInvoke(lib, f);
86 } 86 }
87 87
88 for (var c in lib.classes.values) { 88 for (var c in lib.classes.values) {
89 // Search for @CustomTag on classes 89 // Search for @CustomTag on classes
90 for (var m in c.metadata) { 90 for (var m in c.metadata) {
91 var meta = m.reflectee; 91 var meta = m.reflectee;
92 if (meta is CustomTag) { 92 if (meta is CustomTag) {
93 Polymer._registerClassMirror(meta.tagName, c); 93 Polymer.register(meta.tagName, _getReflectedTypeWorkaround(c));
94 } 94 }
95 } 95 }
96 96
97 // TODO(sigmund): check also static methods marked with @initMethod. 97 // TODO(sigmund): check also static methods marked with @initMethod.
98 // This is blocked on two bugs: 98 // This is blocked on two bugs:
99 // - dartbug.com/12133 (static methods are incorrectly listed as top-level 99 // - dartbug.com/12133 (static methods are incorrectly listed as top-level
100 // in dart2js, so they end up being called twice) 100 // in dart2js, so they end up being called twice)
101 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception, 101 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception,
102 // we could wrap and hide those exceptions, but it's not ideal). 102 // we could wrap and hide those exceptions, but it's not ideal).
103 } 103 }
104 } 104 }
105 105
106 // Horrible hack to work around: http://dartbug.com/12607
107 Type _getReflectedTypeWorkaround(ClassMirror cls) {
108 // On Dart VM, just return reflectedType.
109 if (1.0 is! int) return cls.reflectedType;
110
111 var mangledName = reflect(cls).getField(_mangledNameField).reflectee;
112 Type type = _jsHelper.invoke(#createRuntimeType, [mangledName]).reflectee;
113 return type;
114 }
115
116 final LibraryMirror _jsHelper =
117 currentMirrorSystem().libraries[Uri.parse('dart:_js_helper')];
118
119 final Symbol _mangledNameField = () {
120 var jsClassMirrorMirror = reflect(reflectClass(ClassMirror)).type;
121 for (var name in jsClassMirrorMirror.variables.keys) {
122 if (MirrorSystem.getName(name) == '_mangledName') return name;
123 }
124 }();
125
106 void _maybeInvoke(ObjectMirror obj, MethodMirror method) { 126 void _maybeInvoke(ObjectMirror obj, MethodMirror method) {
107 var annotationFound = false; 127 var annotationFound = false;
108 for (var meta in method.metadata) { 128 for (var meta in method.metadata) {
109 if (identical(meta.reflectee, initMethod)) { 129 if (identical(meta.reflectee, initMethod)) {
110 annotationFound = true; 130 annotationFound = true;
111 break; 131 break;
112 } 132 }
113 } 133 }
114 if (!annotationFound) return; 134 if (!annotationFound) return;
115 if (!method.isStatic) { 135 if (!method.isStatic) {
116 print("warning: methods marked with @initMethod should be static," 136 print("warning: methods marked with @initMethod should be static,"
117 " ${method.simpleName} is not."); 137 " ${method.simpleName} is not.");
118 return; 138 return;
119 } 139 }
120 if (!method.parameters.where((p) => !p.isOptional).isEmpty) { 140 if (!method.parameters.where((p) => !p.isOptional).isEmpty) {
121 print("warning: methods marked with @initMethod should take no " 141 print("warning: methods marked with @initMethod should take no "
122 "arguments, ${method.simpleName} expects some."); 142 "arguments, ${method.simpleName} expects some.");
123 return; 143 return;
124 } 144 }
125 obj.invoke(method.simpleName, const []); 145 obj.invoke(method.simpleName, const []);
126 } 146 }
127 147
128 class _InitMethodAnnotation { 148 class _InitMethodAnnotation {
129 const _InitMethodAnnotation(); 149 const _InitMethodAnnotation();
130 } 150 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/test/attr_deserialize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698