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

Side by Side Diff: tools/dom/src/dart2js_CustomElementSupport.dart

Issue 26089002: Call .created constructor on dart2js 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
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 dart.dom.html; 5 part of dart.dom.html;
6 6
7 _callCreated(receiver) { 7 _callConstructor(constructor) {
8 return receiver.createdCallback(); 8 return (receiver) {
9 return JS('', '#(#)', constructor, receiver);
10 };
9 } 11 }
10 12
11 _callEnteredView(receiver) { 13 _callEnteredView(receiver) {
12 return receiver.enteredView(); 14 return receiver.enteredView();
13 } 15 }
14 16
15 _callLeftView(receiver) { 17 _callLeftView(receiver) {
16 return receiver.leftView(); 18 return receiver.leftView();
17 } 19 }
18 _callAttributeChanged(receiver, name, oldValue, newValue) { 20 _callAttributeChanged(receiver, name, oldValue, newValue) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // }); 79 // });
78 // document.register('x-foo', { prototype: proto }); 80 // document.register('x-foo', { prototype: proto });
79 // ... 81 // ...
80 // var e = document.createElement('x-foo'); 82 // var e = document.createElement('x-foo');
81 83
82 var interceptorClass = findInterceptorConstructorForType(type); 84 var interceptorClass = findInterceptorConstructorForType(type);
83 if (interceptorClass == null) { 85 if (interceptorClass == null) {
84 throw new ArgumentError(type); 86 throw new ArgumentError(type);
85 } 87 }
86 88
89 var constructor = findConstructorForWebComponentType(type, 'created');
90 if (constructor == null) {
91 throw new ArgumentError("$type has no constructor called 'created'");
92 }
93
87 // Workaround for 13190- use an article element to ensure that HTMLElement's 94 // Workaround for 13190- use an article element to ensure that HTMLElement's
88 // interceptor is resolved correctly. 95 // interceptor is resolved correctly.
89 getNativeInterceptor(new Element.tag('article')); 96 getNativeInterceptor(new Element.tag('article'));
90 97
91 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); 98 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
92 if (baseClassName == null) { 99 if (baseClassName == null) {
93 throw new ArgumentError(type); 100 throw new ArgumentError(type);
94 } 101 }
95 if (baseClassName == 'Element') baseClassName = 'HTMLElement'; 102 if (baseClassName == 'Element') baseClassName = 'HTMLElement';
96 103
97 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); 104 var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
98 105
99 var properties = JS('=Object', '{}'); 106 var properties = JS('=Object', '{}');
100 107
101 JS('void', '#.createdCallback = #', properties, 108 JS('void', '#.createdCallback = #', properties,
102 JS('=Object', '{value: #}', _makeCallbackMethod(_callCreated))); 109 JS('=Object', '{value: #}',
110 _makeCallbackMethod(_callConstructor(constructor))));
103 JS('void', '#.enteredViewCallback = #', properties, 111 JS('void', '#.enteredViewCallback = #', properties,
104 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView))); 112 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView)));
105 JS('void', '#.leftViewCallback = #', properties, 113 JS('void', '#.leftViewCallback = #', properties,
106 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView))); 114 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView)));
107 JS('void', '#.attributeChangedCallback = #', properties, 115 JS('void', '#.attributeChangedCallback = #', properties,
108 JS('=Object', '{value: #}', _makeCallbackMethod3(_callAttributeChanged))); 116 JS('=Object', '{value: #}', _makeCallbackMethod3(_callAttributeChanged)));
109 117
110 // TODO(blois): Bug 13220- remove once transition is complete 118 // TODO(blois): Bug 13220- remove once transition is complete
111 JS('void', '#.enteredDocumentCallback = #', properties, 119 JS('void', '#.enteredDocumentCallback = #', properties,
112 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView))); 120 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView)));
(...skipping 17 matching lines...) Expand all
130 } 138 }
131 } 139 }
132 140
133 JS('void', '#.register(#, #)', document, tag, options); 141 JS('void', '#.register(#, #)', document, tag, options);
134 } 142 }
135 143
136 //// Called by Element.created to do validation & initialization. 144 //// Called by Element.created to do validation & initialization.
137 void _initializeCustomElement(Element e) { 145 void _initializeCustomElement(Element e) {
138 // TODO(blois): Add validation that this is only in response to an upgrade. 146 // TODO(blois): Add validation that this is only in response to an upgrade.
139 } 147 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698