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

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

Issue 184033007: Prototype of Dart proxies for JS objects. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More tests. Created 6 years, 9 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 _callConstructor(constructor, interceptor) { 7 _callConstructor(constructor, interceptor) {
8 return (receiver) { 8 return (receiver) {
9 setNativeSubclassDispatchRecord(receiver, interceptor); 9 setNativeSubclassDispatchRecord(receiver, interceptor);
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 getNativeInterceptor(new Element.tag('article')); 80 getNativeInterceptor(new Element.tag('article'));
81 81
82 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); 82 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
83 if (baseClassName == null) { 83 if (baseClassName == null) {
84 throw new ArgumentError(type); 84 throw new ArgumentError(type);
85 } 85 }
86 86
87 if (extendsTagName == null) { 87 if (extendsTagName == null) {
88 if (baseClassName != 'HTMLElement') { 88 if (baseClassName != 'HTMLElement') {
89 throw new UnsupportedError('Class must provide extendsTag if base ' 89 throw new UnsupportedError('Class must provide extendsTag if base '
90 'native class is not HTMLElement'); 90 'native class is not HtmlElement');
91 } 91 }
92 } else { 92 } else {
93 if (!JS('bool', '(#.createElement(#) instanceof window[#])', 93 if (!JS('bool', '(#.createElement(#) instanceof window[#])',
94 document, extendsTagName, baseClassName)) { 94 document, extendsTagName, baseClassName)) {
95 throw new UnsupportedError('extendsTag does not match base native class'); 95 throw new UnsupportedError('extendsTag does not match base native class');
96 } 96 }
97 } 97 }
98 98
99 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); 99 var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
100 100
(...skipping 20 matching lines...) Expand all
121 JS('=Object', '#.extends = #', options, extendsTagName); 121 JS('=Object', '#.extends = #', options, extendsTagName);
122 } 122 }
123 123
124 JS('void', '#.registerElement(#, #)', document, tag, options); 124 JS('void', '#.registerElement(#, #)', document, tag, options);
125 } 125 }
126 126
127 //// Called by Element.created to do validation & initialization. 127 //// Called by Element.created to do validation & initialization.
128 void _initializeCustomElement(Element e) { 128 void _initializeCustomElement(Element e) {
129 // TODO(blois): Add validation that this is only in response to an upgrade. 129 // TODO(blois): Add validation that this is only in response to an upgrade.
130 } 130 }
131
132 class _JSElementUpgrader implements ElementUpgrader {
133 var _interceptor;
134 var _baseClassName;
135 var _constructor;
136
137 _JSElementUpgrader(Document document, Type type, String extendsTag) {
138 var interceptorClass = findInterceptorConstructorForType(type);
139 if (interceptorClass == null) {
140 throw new ArgumentError(type);
141 }
142
143 _constructor = findConstructorForNativeSubclassType(type, 'created');
144 if (_constructor == null) {
145 throw new ArgumentError("$type has no constructor called 'created'");
146 }
147
148 // Workaround for 13190- use an article element to ensure that HTMLElement's
149 // interceptor is resolved correctly.
150 getNativeInterceptor(new Element.tag('article'));
151
152 _baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
153 if (_baseClassName == null) {
154 throw new ArgumentError(type);
155 }
156
157 if (extendsTag == null) {
158 if (_baseClassName != 'HTMLElement') {
159 throw new UnsupportedError('Class must provide extendsTag if base '
160 'native class is not HtmlElement');
161 }
162 } else {
163 if (!JS('bool', '(#.createElement(#) instanceof window[#])',
164 document, extendsTag, _baseClassName)) {
165 throw new UnsupportedError(
166 'extendsTag does not match base native class');
167 }
168 }
169
170 _interceptor = JS('=Object', '#.prototype', interceptorClass);
171 }
172
173 Element upgrade(Element element) {
174 if (!JS('bool', '(# instanceof window[#])', element, _baseClassName)) {
175 throw new ArgumentError('element is not subclass of $_baseClassName');
176 }
177
178 setNativeSubclassDispatchRecord(element, _interceptor);
179 JS('', '#(#)', _constructor, element);
180 return element;
181 }
182 }
OLDNEW
« no previous file with comments | « tests/html/custom/element_upgrade_test.html ('k') | tools/dom/src/dartium_CustomElementSupport.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698